:root {
  --bg: #fff7eb;
  --card: #ffffff;
  --ink: #253044;
  --muted: #64748b;
  --line: #dfe7f2;
  --panel: #f8fbff;
  --panel-2: #eef8f4;
  --accent: #ff7a1a;
  --accent-dark: #d95b00;
  --blue: #2563eb;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #fff2d9;
  --shadow: 0 16px 28px rgba(41, 51, 74, 0.12);
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

button, input { font: inherit; }

.app {
  width: min(1120px, calc(100vw - 16px));
  margin: 8px auto 18px;
  min-height: calc(100vh - 16px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 34px 36px 36px;
}

.app.home-screen {
  min-height: auto;
}

.mobile-nav {
  display: none;
  position: relative;
}

.nav-menu-button {
  list-style: none;
  border: 1px solid var(--line);
  cursor: pointer;
  background: #fff0df;
  color: #c34a08;
  border-radius: 999px;
  min-height: 36px;
  padding: 7px 13px;
  font-weight: 900;
  font-size: 14px;
  box-shadow: 0 6px 12px rgba(41, 51, 74, 0.08);
}

.nav-menu-button::-webkit-details-marker {
  display: none;
}

.mobile-nav-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 20;
  width: min(260px, calc(100vw - 32px));
  display: grid;
  gap: 8px;
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.mobile-nav-panel .nav-button {
  width: 100%;
  justify-content: center;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  margin-bottom: 10px;
}

.chips {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 8px 13px;
  border-radius: 999px;
  background: #eef3fb;
  color: var(--ink);
  font-weight: 800;
  font-size: 14px;
}

.chip.orange { background: #fff0df; color: #c34a08; }
.chip.blue { background: #dbeafe; color: #1d4ed8; }
.chip.green { background: #dcfce7; color: #087c3a; }

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.global-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.nav-button {
  border: 1px solid var(--line);
  cursor: pointer;
  background: #ffffff;
  color: var(--ink);
  border-radius: 999px;
  min-height: 36px;
  padding: 7px 13px;
  font-weight: 900;
  font-size: 14px;
  box-shadow: 0 6px 12px rgba(41, 51, 74, 0.08);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}

.nav-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(41, 51, 74, 0.12);
}

.nav-button.home {
  background: #fff0df;
  color: #c34a08;
  border-color: #fed7aa;
}

.nav-button.section {
  background: #dbeafe;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.progress-wrap {
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: #e6edf6;
  margin: 8px 0 18px;
}

.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #fb923c, #22c55e);
  transition: width .25s ease;
}

.screen-grid {
  display: grid;
  grid-template-columns: 1.12fr .95fr;
  gap: 20px;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #fff;
  padding: 24px;
}

.card.soft {
  background: #fbfdff;
}

.hero {
  display: grid;
  grid-template-columns: 1fr 150px;
  gap: 18px;
  align-items: center;
}

.hero h1, .card h1 {
  margin: 0 0 12px;
  font-size: clamp(31px, 4.8vw, 52px);
  line-height: 1.02;
  letter-spacing: -0.03em;
}

h2 {
  margin: 0 0 12px;
  font-size: clamp(22px, 3vw, 32px);
  line-height: 1.12;
  letter-spacing: -0.02em;
}

h3 {
  margin: 0 0 12px;
  font-size: 21px;
}

p { line-height: 1.45; }

.lead {
  color: var(--muted);
  font-size: 18px;
  margin: 0 0 14px;
}

.hero-mascot {
  width: 100%;
  max-width: 150px;
  justify-self: center;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.menu-button, .option-button, .small-button, .primary-button, .ghost-button {
  border: 0;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease, border-color .12s ease;
}

.menu-button {
  display: flex;
  flex-direction: column;
  text-align: left;
  min-height: 118px;
  padding: 18px;
  border-radius: 20px;
  background: #f8fbff;
  border: 1px solid var(--line);
  color: var(--ink);
}

.menu-button strong {
  font-size: 20px;
  margin-bottom: 8px;
}

.menu-button span {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.35;
}

.menu-button:hover, .option-button:hover, .small-button:hover, .primary-button:hover, .ghost-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(41, 51, 74, 0.12);
}

.footer-row {
  margin-top: 20px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

.primary-button {
  background: linear-gradient(180deg, #ff7a1a, #ff6811);
  color: #fff;
  border-radius: 999px;
  min-height: 50px;
  padding: 0 26px;
  font-weight: 900;
  box-shadow: 0 10px 20px rgba(255, 122, 26, 0.22);
}

.ghost-button, .small-button {
  background: #f8fbff;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 999px;
  min-height: 42px;
  padding: 0 18px;
  font-weight: 800;
}

.small-button.selected, .ghost-button.selected {
  background: #dbeafe;
  border-color: #bfdbfe;
  color: #1d4ed8;
}

.question-title {
  font-size: clamp(28px, 4vw, 36px);
  line-height: 1.12;
  margin: 0 0 12px;
  letter-spacing: -0.03em;
}

.question-hint {
  color: var(--muted);
  font-size: 16px;
  margin: 0 0 18px;
}

.scene-panel {
  min-height: 210px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #f8fbff, #f3f8ff);
  border-radius: 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px;
  margin-top: 14px;
  overflow: hidden;
}

.bag-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 10px 14px;
  width: 100%;
}

.bag-img {
  width: clamp(70px, 9.5vw, 108px);
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 8px 10px rgba(15, 23, 42, .10));
}

.bag-row.many .bag-img { width: clamp(58px, 7.4vw, 88px); }

.equation-card {
  width: 100%;
  text-align: center;
}

.big-equation {
  font-size: clamp(58px, 9vw, 92px);
  line-height: 1;
  font-weight: 900;
  color: #111827;
  letter-spacing: -0.04em;
}

.big-equation.medium { font-size: clamp(44px, 7vw, 78px); }
.big-equation.small { font-size: clamp(34px, 5vw, 56px); }

.visual-note {
  margin: 18px auto 0;
  max-width: 520px;
  color: var(--ink);
  font-size: 16px;
}

.options-panel h3 { margin-bottom: 10px; }

.options-list {
  display: grid;
  gap: 12px;
}

.option-button {
  min-height: 58px;
  border-radius: 18px;
  background: #fff;
  border: 2px solid var(--line);
  color: var(--ink);
  font-size: 20px;
  font-weight: 900;
  padding: 12px 18px;
}

.option-button.correct {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

.option-button.wrong {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}

.option-button:disabled {
  cursor: default;
  transform: none;
  box-shadow: none;
}

.input-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.answer-input {
  min-height: 58px;
  flex: 1;
  border: 2px solid #111;
  border-radius: 18px;
  padding: 0 18px;
  font-weight: 900;
  font-size: 22px;
  text-align: center;
}

.answer-input:focus {
  outline: 3px solid rgba(37, 99, 235, .18);
}

.feedback {
  margin-top: 16px;
  border-radius: 18px;
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 66px 1fr;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  background: #f8fbff;
}

.feedback.good { background: #f0fdf4; border-color: #bbf7d0; }
.feedback.bad { background: #fff7ed; border-color: #fed7aa; }
.feedback img { width: 64px; height: auto; }
.feedback strong { display: block; font-size: 18px; margin-bottom: 4px; }
.feedback p { margin: 0; color: var(--ink); }

.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.setup-block {
  border: 1px solid var(--line);
  background: #fbfdff;
  border-radius: 20px;
  padding: 18px;
}

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.table-check {
  min-height: 44px;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  font-weight: 900;
}

.table-check input { margin-right: 6px; }

.pit-table-wrap {
  overflow-x: auto;
  padding-bottom: 4px;
}

.pit-table {
  border-collapse: separate;
  border-spacing: 8px;
  margin: 4px auto 12px;
}

.pit-table th, .pit-table td {
  min-width: 64px;
  height: 54px;
  border-radius: 14px;
  text-align: center;
  font-size: 18px;
  font-weight: 900;
  border: 1px solid var(--line);
  background: #fff;
}

.pit-table th {
  background: #fff0df;
  color: #a93b07;
}

.pit-table .known-cell {
  background: #f8fbff;
}

.blank-cell {
  background: #eef8f4 !important;
  border: 2px dashed #86efac !important;
  color: #087c3a;
  cursor: pointer;
}

.blank-cell.selected {
  outline: 4px solid rgba(37, 99, 235, .22);
  background: #dbeafe !important;
  color: #1d4ed8;
}

.blank-cell.filled {
  border-style: solid !important;
  background: #dcfce7 !important;
  color: #166534;
  cursor: default;
}

.fragment-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.notice-card {
  border-radius: 24px;
  background: linear-gradient(135deg, #fff7ed, #eef8f4);
  border: 1px solid var(--line);
  padding: 28px;
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 20px;
  align-items: center;
}

.notice-card img { width: 130px; justify-self: center; }

.hidden { display: none !important; }

@media (max-width: 850px) {
  .app { padding: 22px 18px; border-radius: 22px; }
  .screen-grid, .setup-grid, .hero, .notice-card { grid-template-columns: 1fr; }
  .menu-grid { grid-template-columns: 1fr; }
  .hero-mascot, .notice-card img { max-width: 118px; }
  .scene-panel { min-height: 180px; padding: 18px; }
  .input-row { flex-direction: column; align-items: stretch; }
  .checkbox-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 520px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .chip { font-size: 13px; min-height: 32px; }
  .bag-img { width: 65px; }
  .bag-row.many .bag-img { width: 56px; }
  .pit-table th, .pit-table td { min-width: 48px; height: 46px; font-size: 16px; }
  .fragment-options { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions, .global-nav {
    justify-content: flex-start;
  }
}


@media (max-width: 720px) {
  body {
    background: #ffffff;
  }

  .app {
    width: 100%;
    margin: 0 auto;
    min-height: 100dvh;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    padding: 14px 12px 22px;
  }

  .app.home-screen {
    min-height: auto;
  }

  .topbar {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
  }

  .chips {
    gap: 6px;
    min-width: 0;
    flex: 1;
  }

  .chip {
    min-height: 28px;
    padding: 5px 9px;
    font-size: 12px;
    white-space: nowrap;
  }

  .top-actions {
    margin-left: auto;
    flex-wrap: nowrap;
    gap: 6px;
  }

  .desktop-nav {
    display: none;
  }

  .mobile-nav {
    display: block;
  }

  .nav-menu-button {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 13px;
  }

  .progress-wrap {
    height: 9px;
    margin: 6px 0 10px;
  }

  .screen-grid,
  .setup-grid {
    gap: 10px;
  }

  .card {
    padding: 16px;
    border-radius: 20px;
  }

  .card.soft {
    padding: 15px;
  }

  .question-title {
    font-size: clamp(24px, 7vw, 31px);
    margin-bottom: 8px;
    line-height: 1.08;
  }

  .question-hint {
    font-size: 16px;
    margin-bottom: 10px;
  }

  .scene-panel {
    min-height: 122px;
    padding: 12px;
    margin-top: 10px;
    border-radius: 18px;
  }

  .visual-note {
    margin-top: 8px;
    font-size: 14px;
    line-height: 1.25;
  }

  .big-equation {
    font-size: clamp(42px, 14vw, 64px);
  }

  .big-equation.medium {
    font-size: clamp(32px, 10vw, 48px);
  }

  .big-equation.small {
    font-size: clamp(27px, 8vw, 38px);
  }

  .options-panel h3 {
    font-size: 18px;
    margin-bottom: 8px;
  }

  .options-list {
    gap: 9px;
  }

  .option-button {
    min-height: 48px;
    border-radius: 16px;
    padding: 9px 12px;
    font-size: 18px;
  }

  .true-false-screen .scene-panel {
    display: none;
  }

  .true-false-screen .options-list {
    grid-template-columns: 1fr 1fr;
  }

  .true-false-screen .option-button {
    min-height: 52px;
  }

  .feedback {
    margin-top: 10px;
    padding: 10px 12px;
    grid-template-columns: 48px 1fr;
    gap: 10px;
    border-radius: 16px;
  }

  .feedback img {
    width: 46px;
  }

  .feedback strong {
    font-size: 16px;
  }

  .feedback p {
    font-size: 15px;
    line-height: 1.32;
  }

  .footer-row {
    margin-top: 12px;
  }

  .primary-button {
    min-height: 44px;
    padding: 0 20px;
  }

  .ghost-button,
  .small-button {
    min-height: 38px;
    padding: 0 14px;
  }

  .answer-input {
    min-height: 48px;
    border-radius: 16px;
    font-size: 20px;
  }

  .hero h1,
  .card h1 {
    font-size: clamp(31px, 10vw, 42px);
  }

  h2 {
    font-size: clamp(24px, 7vw, 31px);
  }

  .lead {
    font-size: 16px;
  }

  .menu-grid {
    gap: 10px;
  }

  .menu-button {
    min-height: 92px;
    padding: 14px;
    border-radius: 18px;
  }

  .menu-button strong {
    font-size: 18px;
  }

  .menu-button span {
    font-size: 14px;
  }
}

@media (max-width: 520px) {
  .bag-img {
    width: 58px;
  }

  .bag-row.many .bag-img {
    width: 49px;
  }

  .pit-table {
    border-spacing: 5px;
  }

  .pit-table th,
  .pit-table td {
    min-width: 42px;
    height: 40px;
    border-radius: 11px;
    font-size: 15px;
  }

  .fragment-options {
    grid-template-columns: 1fr 1fr;
  }

  .mobile-nav-panel {
    right: -2px;
  }
}
