/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f13;
  --bg2: #17171f;
  --bg3: #1e1e2a;
  --border: #2a2a3a;
  --accent: #7c6df0;
  --accent-light: #9d91f5;
  --accent-dim: rgba(124, 109, 240, 0.15);
  --text: #e8e8f0;
  --text-muted: #888899;
  --text-dim: #555566;
  --yes: #4ade80;
  --no: #f87171;
  --unrel: #fbbf24;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

html, body {
  height: 100%;
  font-family: 'Noto Sans JP', 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

/* ===== Screen System ===== */
.screen {
  display: none;
  min-height: 100vh;
}
.screen.active {
  display: flex;
  flex-direction: column;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 22px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-light);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(124, 109, 240, 0.35);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  background: var(--bg3);
  color: var(--text);
  border-color: var(--accent);
}

.btn-lg {
  padding: 14px 36px;
  font-size: 16px;
  border-radius: var(--radius);
}

.btn-icon {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.18s;
  flex-shrink: 0;
}
.btn-icon:hover {
  background: var(--bg3);
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== Page Container ===== */
.page-container {
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  padding: 40px 24px 60px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  align-items: flex-start;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

/* ===== Title Screen ===== */
#screen-title {
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(124,109,240,0.12) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(124,109,240,0.07) 0%, transparent 50%),
    var(--bg);
}

.title-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  padding: 40px 24px;
}

.title-turtle {
  font-size: 64px;
  line-height: 1;
  filter: drop-shadow(0 0 24px rgba(124, 109, 240, 0.5));
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.title-main {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #fff 30%, var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.title-sub {
  font-size: 13px;
  font-weight: 300;
  color: var(--text-muted);
  letter-spacing: 3px;
  text-transform: uppercase;
}

.title-desc {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.8;
  max-width: 280px;
  margin-bottom: 8px;
}

/* ===== How to Play ===== */
.how-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}

.how-item {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.how-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.how-text {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.7;
}
.how-text strong {
  color: var(--text);
  display: block;
  margin-bottom: 2px;
}

/* ===== Level Tabs ===== */
.level-tabs {
  display: flex;
  gap: 8px;
  width: 100%;
}

.level-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.18s;
  font-family: inherit;
}
.level-tab:hover {
  border-color: var(--accent);
  background: var(--bg2);
}
.level-tab.active {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.level-tab-icon {
  font-size: 20px;
  line-height: 1;
}

.level-tab-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}
.level-tab.active .level-tab-label {
  color: var(--accent-light);
}

.level-tab-count {
  font-size: 11px;
  color: var(--text-dim);
}
.level-tab.active .level-tab-count {
  color: var(--accent);
}

/* 難易度バッジ（ゲームヘッダー） */
.level-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
}
.level-badge.beginner     { background: rgba(74,222,128,0.12); color: #4ade80; }
.level-badge.intermediate { background: rgba(251,191,36,0.12);  color: #fbbf24; }
.level-badge.advanced     { background: rgba(248,113,113,0.12); color: #f87171; }

/* ===== Puzzle Select ===== */
.puzzle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}

.puzzle-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: all 0.18s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.puzzle-card:hover {
  border-color: var(--accent);
  background: var(--bg2);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.puzzle-card-num {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.puzzle-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* ===== Game Screen ===== */
#screen-game {
  background: var(--bg);
}

.game-container {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 0 0 120px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Game Header */
.game-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.game-title-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.game-label {
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.game-puzzle-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Question Card */
.question-card {
  margin: 20px 20px 0;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px 22px;
}

.question-text {
  font-size: 15px;
  line-height: 1.9;
  color: var(--text);
  font-weight: 400;
}

/* Hint Area */
.hint-area {
  margin: 16px 20px 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.hint-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.hint-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.btn-hint {
  background: var(--accent-dim);
  color: var(--accent-light);
  border: 1px solid rgba(124, 109, 240, 0.3);
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 6px;
}
.btn-hint:hover {
  background: rgba(124,109,240,0.25);
}
.btn-hint:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.hint-list {
  padding: 0 16px;
}

.hint-item {
  display: flex;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  animation: slideIn 0.3s ease;
}
.hint-item:last-child {
  border-bottom: none;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hint-item-num {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  background: var(--accent-dim);
  color: var(--accent-light);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.hint-item-text {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.7;
}

.hint-exhausted {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: 12px 16px;
}

/* Chat Area */
.chat-area {
  flex: 1;
  margin: 16px 20px 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.chat-messages {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 320px;
  overflow-y: auto;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Chat Bubbles */
.chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.6;
  animation: bubbleIn 0.25s ease;
}

@keyframes bubbleIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

.chat-bubble.system {
  background: var(--bg3);
  color: var(--text-dim);
  border: 1px solid var(--border);
  font-size: 12px;
  align-self: center;
  max-width: 100%;
  text-align: center;
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-radius: 10px 10px 3px 10px;
}

.chat-bubble.answer {
  align-self: flex-start;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px 10px 10px 3px;
  color: var(--text);
}

.chat-bubble.answer .answer-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 4px;
}
.chat-bubble.answer .answer-tag.yes  { background: rgba(74,222,128,0.15); color: var(--yes); }
.chat-bubble.answer .answer-tag.no   { background: rgba(248,113,113,0.15); color: var(--no); }
.chat-bubble.answer .answer-tag.unrel{ background: rgba(251,191,36,0.15);  color: var(--unrel); }
.chat-bubble.answer .answer-tag.unknown { background: var(--bg); color: var(--text-muted); }

.chat-bubble.answer .answer-body {
  display: block;
  color: var(--text);
  font-size: 13px;
}

/* Input Area */
.input-area {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 720px;
  display: flex;
  gap: 10px;
  padding: 12px 20px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  z-index: 20;
}

.question-input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.18s;
}
.question-input:focus {
  border-color: var(--accent);
}
.question-input::placeholder {
  color: var(--text-dim);
}

.btn-send {
  background: var(--accent);
  color: #fff;
  padding: 10px 20px;
  font-size: 14px;
  border-radius: var(--radius-sm);
}
.btn-send:hover {
  background: var(--accent-light);
}

/* Answer Button */
.answer-btn-area {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 720px;
  padding: 8px 20px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 20;
}

.btn-answer {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  padding: 10px;
  border-radius: var(--radius-sm);
  transition: all 0.18s;
}
.btn-answer:hover {
  border-color: var(--no);
  color: var(--no);
  background: rgba(248,113,113,0.05);
}

/* ===== Answer Screen ===== */
#screen-answer {
  background: var(--bg);
}

.answer-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.answer-icon {
  font-size: 28px;
}

.answer-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
}

.answer-card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 14px;
}

.answer-text {
  font-size: 15px;
  line-height: 1.9;
  color: var(--text);
}

.answer-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

/* ===== Self Judge ===== */
.self-judge-area {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.self-judge-question {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}

.self-judge-buttons {
  display: flex;
  gap: 12px;
  width: 100%;
}

.btn-correct {
  flex: 1;
  background: rgba(74, 222, 128, 0.12);
  color: var(--yes);
  border: 1px solid rgba(74, 222, 128, 0.35);
  font-size: 15px;
  padding: 14px;
  border-radius: var(--radius-sm);
  transition: all 0.18s;
}
.btn-correct:hover {
  background: rgba(74, 222, 128, 0.22);
  transform: translateY(-1px);
}

.btn-wrong {
  flex: 1;
  background: rgba(248, 113, 113, 0.12);
  color: var(--no);
  border: 1px solid rgba(248, 113, 113, 0.35);
  font-size: 15px;
  padding: 14px;
  border-radius: var(--radius-sm);
  transition: all 0.18s;
}
.btn-wrong:hover {
  background: rgba(248, 113, 113, 0.22);
  transform: translateY(-1px);
}

/* 結果バナー */
.result-banner {
  width: 100%;
  border-radius: var(--radius);
  padding: 20px 24px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  animation: bannerIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes bannerIn {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

.result-banner.correct {
  background: rgba(74, 222, 128, 0.1);
  border: 1px solid rgba(74, 222, 128, 0.4);
  color: var(--yes);
}

.result-banner.wrong {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: var(--no);
}

.result-banner .result-sub {
  display: block;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  max-width: 360px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow);
  animation: modalIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.9) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
}

.modal-desc {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.8;
}

.modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ===== Responsive ===== */
@media (max-width: 520px) {
  .puzzle-grid {
    grid-template-columns: 1fr;
  }
  .title-main {
    font-size: 28px;
  }
  .chat-messages {
    max-height: 240px;
  }
}
