:root {
  --ivory: #f7f0df;
  --paper: #fffaf0;
  --ink: #4b4033;
  --muted: #7e7162;
  --line: #e3d6be;
  --green: #8aa58a;
  --rose: #d5968c;
  --ochre: #d9b56d;
  --blue: #8aa2ad;
  --shadow: 0 14px 36px rgba(87, 68, 39, 0.16);
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", "YuGothic", "Meiryo", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 8%, rgba(217, 181, 109, 0.24), transparent 26%),
    linear-gradient(135deg, #efe3ca, #f8f0de 46%, #e7dcc6);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.phone-shell {
  width: min(100vw, 430px);
  height: 100svh;
  min-height: 100svh;
  margin: 0 auto;
  background:
    radial-gradient(circle at 12px 12px, rgba(122, 103, 74, 0.055) 1.2px, transparent 1.4px) 0 0 / 24px 24px,
    linear-gradient(90deg, rgba(122, 103, 74, 0.032) 1px, transparent 1px) 0 0 / 42px 42px,
    linear-gradient(0deg, rgba(122, 103, 74, 0.026) 1px, transparent 1px) 0 0 / 42px 42px,
    linear-gradient(rgba(255, 250, 240, 0.84), rgba(255, 250, 240, 0.94)),
    repeating-linear-gradient(45deg, rgba(216, 188, 139, 0.09), rgba(216, 188, 139, 0.09) 8px, transparent 8px, transparent 18px);
  box-shadow: 0 0 0 1px rgba(117, 92, 55, 0.08), var(--shadow);
  overflow: hidden;
}

@supports (height: 100dvh) {
  .phone-shell {
    height: 100dvh;
    min-height: 100dvh;
  }
}

.screen {
  height: 100%;
  min-height: 0;
  padding:
    max(clamp(10px, 2.2svh, 18px), env(safe-area-inset-top))
    clamp(12px, 4.6vw, 18px)
    max(clamp(10px, 2.2svh, 18px), env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.9svh, 16px);
  overflow: hidden;
}

.scroll-screen {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.quiz-screen {
  position: relative;
  overflow: hidden;
  gap: clamp(6px, 1.4svh, 12px);
  padding-bottom: max(clamp(10px, 2.2svh, 18px), env(safe-area-inset-bottom));
}

.quiz-screen > :not(.quiz-character) {
  position: relative;
  z-index: 1;
}

.quiz-screen .button-row {
  z-index: 2;
  margin-top: auto;
  padding-top: 0;
}

.quiz-screen .soft-button {
  background-color: var(--paper);
}

.quiz-screen .soft-button.primary {
  background-color: #e3edd8;
}

.result-screen {
  position: relative;
  justify-content: flex-end;
  overflow: hidden;
  padding-bottom: max(clamp(10px, 2.2svh, 18px), env(safe-area-inset-bottom));
}

.result-screen > :not(.result-art) {
  position: relative;
  z-index: 1;
}

.result-screen .section-title {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: 18px;
}

.home {
  position: relative;
  justify-content: space-between;
  overflow: hidden;
  padding-top: max(clamp(12px, 2.6svh, 22px), env(safe-area-inset-top));
}

.brand {
  position: relative;
  z-index: 2;
  padding-top: 2px;
  text-align: center;
}

.logo-slot {
  display: none;
  width: min(88%, 340px);
  max-height: 132px;
  object-fit: contain;
  margin: 0 auto 4px;
  filter: drop-shadow(0 8px 10px rgba(87, 68, 39, 0.14));
}

.logo-slot.is-visible {
  display: block;
}

.title {
  margin: 0;
  font-size: 38px;
  line-height: 1.08;
  letter-spacing: 0;
  color: #5a4a38;
}

.brand:has(.logo-slot.is-visible) .title {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.subtitle {
  display: inline-block;
  margin: 2px 0 0;
  padding: 5px 12px;
  border: 1px solid rgba(227, 214, 190, 0.88);
  border-radius: 999px;
  background: rgba(255, 250, 240, 0.78);
  color: var(--muted);
  font-weight: 700;
}

.hero-character {
  position: absolute;
  z-index: 0;
  left: 57%;
  bottom: 0;
  width: auto;
  max-width: 126%;
  height: min(78svh, 690px);
  transform: translateX(-50%);
  object-fit: contain;
  filter: drop-shadow(0 16px 20px rgba(87, 68, 39, 0.18));
}

.hero-face-hotspot {
  position: absolute;
  z-index: 3;
  left: 55%;
  top: clamp(148px, 36svh, 330px);
  width: clamp(94px, 28vw, 138px);
  height: clamp(100px, 18svh, 150px);
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  transform: translate(-50%, -50%);
}

.menu-stack,
.button-row,
.home-action-row,
.choice-grid,
.stats-grid,
.mistake-list,
.range-grid,
.ndc-drum-grid {
  display: grid;
  gap: 10px;
}

.menu-stack {
  position: relative;
  z-index: 2;
  padding-bottom: clamp(0px, 1svh, 8px);
}

.home-menu .soft-button {
  background: rgba(255, 250, 240, 0.82);
}

.home-credit {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 8px;
  justify-self: center;
  width: min(100%, 340px);
  margin: 2px 0 0;
  padding: 6px 10px;
  border: 1px solid rgba(111, 95, 73, 0.28);
  border-radius: 12px;
  background: rgba(255, 250, 240, 0.86);
  color: #67553d;
  box-shadow: 0 5px 12px rgba(87, 68, 39, 0.08);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
}

.button-row {
  grid-template-columns: 1fr 1fr;
}

.home-action-row {
  grid-template-columns: 1fr 1fr;
}

.home-action-row .soft-button {
  min-width: 0;
  padding-inline: 8px;
  font-size: clamp(13px, 3.5vw, 16px);
}

.soft-button,
.option-button,
.answer-button,
.class-toggle {
  border: 1px solid rgba(111, 95, 73, 0.34);
  border-radius: 18px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 5px 0 #c7b58f;
  min-height: clamp(42px, 6svh, 48px);
  padding: clamp(8px, 1.6svh, 12px) 16px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
  touch-action: manipulation;
}

.soft-button:active,
.option-button:active,
.answer-button:active,
.class-toggle:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #c7b58f;
}

.soft-button.primary,
.option-button.is-selected,
.class-toggle.is-selected {
  background: #e3edd8;
  border-color: #667b5e;
}

.soft-button.accent {
  background: #f5dfd8;
  border-color: #9b6b64;
}

.soft-button.small {
  min-height: clamp(38px, 5.4svh, 42px);
  padding: clamp(7px, 1.3svh, 9px) 12px;
  font-size: 14px;
  border-radius: 14px;
}

.soft-button.ghost {
  background: rgba(255, 250, 240, 0.58);
}

.section-title {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
}

.panel {
  background: rgba(255, 250, 240, 0.72);
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: clamp(10px, 1.8svh, 14px);
}

.panel h2,
.panel h3 {
  margin: 0 0 clamp(6px, 1.3svh, 10px);
  font-size: 18px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.check-option {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(111, 95, 73, 0.26);
  border-radius: 12px;
  background: rgba(255, 250, 240, 0.58);
  font-size: 14px;
  font-weight: 900;
}

.check-option input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: #667b5e;
}

.check-option-text {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  outline: none;
}

.option-tooltip {
  position: absolute;
  z-index: 10;
  left: 0;
  bottom: calc(100% + 8px);
  width: min(260px, calc(100vw - 54px));
  padding: 8px 10px;
  border: 1px solid rgba(111, 95, 73, 0.28);
  border-radius: 10px;
  background: rgba(255, 250, 240, 0.98);
  box-shadow: 0 8px 18px rgba(87, 68, 39, 0.14);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.check-option-text:hover .option-tooltip,
.check-option-text:focus-visible .option-tooltip,
.check-option-text:active .option-tooltip {
  opacity: 1;
  transform: translateY(0);
}

.option-button {
  min-height: clamp(44px, 6.4svh, 54px);
  border-radius: 16px;
  box-shadow: 0 2px 0 rgba(199, 181, 143, 0.72);
}

.range-grid {
  grid-template-columns: repeat(5, 1fr);
}

.class-toggle {
  min-width: 0;
  min-height: clamp(36px, 5.4svh, 46px);
  padding: clamp(5px, 1.2svh, 8px) 4px;
  border-radius: 14px;
  box-shadow: 0 3px 0 #c7b58f;
  font-size: 14px;
}

.top-bar,
.quiz-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.quiz-meta {
  font-weight: 900;
}

.timer-track {
  height: clamp(8px, 1.5svh, 12px);
  border-radius: 999px;
  overflow: hidden;
  background: #eadcc1;
  border: 1px solid #cfbd9d;
}

.timer-fill {
  height: 100%;
  width: 100%;
  background: #b9cba8;
  transition: width 200ms linear;
}

.question-card {
  background: #fffaf0;
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: clamp(10px, 2svh, 18px);
  min-height: 0;
  block-size: clamp(92px, 17svh, 150px);
  display: grid;
  align-content: center;
  text-align: center;
  box-shadow: 0 8px 18px rgba(87, 68, 39, 0.1);
}

.question-kicker {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.question-text {
  margin: clamp(4px, 1svh, 8px) 0 0;
  font-size: 24px;
  line-height: 1.3;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.question-text.code-question {
  font-size: 34px;
  line-height: 1.08;
}

.question-text.subject-question {
  font-size: 20px;
  line-height: 1.22;
}

.answer-grid {
  display: grid;
  gap: clamp(6px, 1.1svh, 10px);
}

.answer-button {
  min-height: clamp(44px, 7svh, 58px);
  padding: clamp(6px, 1.3svh, 12px) 10px;
  text-align: center;
  font-size: 14px;
  line-height: 1.24;
  box-shadow: 0 4px 0 #c7b58f;
  overflow-wrap: anywhere;
}

.answer-button.correct {
  background: #dfead2;
  border-color: #667b5e;
}

.answer-button.wrong {
  background: #f3d6cf;
  border-color: #9b6b64;
}

.answer-button:disabled {
  cursor: default;
}

.answer-float {
  position: fixed;
  z-index: 20;
  transform: translate(-50%, -50%);
  pointer-events: none;
  padding: 0;
  font-size: 34px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
  text-shadow:
    0 2px 0 rgba(255, 250, 240, 0.88),
    0 6px 12px rgba(87, 68, 39, 0.18);
  animation: answer-float 1100ms ease-out forwards;
}

.quiz-screen > .answer-float {
  position: fixed;
  z-index: 20;
}

.answer-float.ok {
  color: #637c59;
}

.answer-float.ng {
  color: #9b6b64;
}

@keyframes answer-float {
  0% {
    opacity: 0;
    transform: translate(-50%, -35%) scale(0.72);
  }

  18% {
    opacity: 1;
    transform: translate(-50%, -58%) scale(1.04);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -130%) scale(0.94);
  }
}

.quiz-character {
  position: absolute;
  z-index: 0;
  left: 53%;
  bottom: clamp(-210px, -22svh, -150px);
  width: auto;
  max-width: min(96%, 390px);
  height: clamp(360px, 56svh, 500px);
  transform: translateX(-50%);
  object-fit: contain;
  opacity: 0.96;
  filter: drop-shadow(0 12px 16px rgba(87, 68, 39, 0.16));
}

.quiz-character.is-positioned {
  top: var(--quiz-character-top);
  bottom: auto;
}

.result-art {
  position: absolute;
  z-index: 0;
  left: 50%;
  top: auto;
  bottom: clamp(-220px, -23svh, -150px);
  width: min(174%, 740px);
  max-height: min(112svh, 1080px);
  transform: translateX(-50%);
  object-fit: contain;
  opacity: 0.92;
  filter: drop-shadow(0 12px 18px rgba(87, 68, 39, 0.16));
}

.result-screen .soft-button,
.result-screen .speech,
.result-screen .score {
  background-color: rgba(255, 250, 240, 0.94);
}

.result-screen .soft-button.primary {
  background-color: rgba(227, 237, 216, 0.94);
}

.score {
  align-self: center;
  min-width: 180px;
  padding: clamp(8px, 1.4svh, 10px) 18px;
  border: 2px solid rgba(227, 214, 190, 0.86);
  border-radius: 18px;
  background: rgba(255, 250, 240, 0.86);
  text-align: center;
  font-size: 42px;
  font-weight: 900;
  line-height: 1;
}

.speech {
  margin: 0;
  padding: clamp(10px, 1.8svh, 14px) 16px;
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 18px;
  font-weight: 800;
  line-height: 1.55;
}

.stat-card {
  min-height: 92px;
  padding: 14px;
  border-radius: 16px;
  border: 2px solid var(--line);
  background: var(--paper);
}

.stat-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.stat-value {
  margin-top: 6px;
  font-size: 26px;
  font-weight: 900;
}

.mistake-item {
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  line-height: 1.45;
}

.mistake-code {
  font-weight: 900;
}

.gallery-panel {
  display: grid;
  gap: 10px;
}

.gallery-heading {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.gallery-thumb {
  aspect-ratio: 3 / 4;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border: 2px solid #6f5f49;
  border-radius: 14px;
  background:
    linear-gradient(rgba(255, 250, 240, 0.82), rgba(255, 250, 240, 0.92)),
    linear-gradient(45deg, rgba(111, 95, 73, 0.09) 25%, transparent 25%, transparent 75%, rgba(111, 95, 73, 0.09) 75%),
    linear-gradient(45deg, rgba(111, 95, 73, 0.09) 25%, transparent 25%, transparent 75%, rgba(111, 95, 73, 0.09) 75%);
  background-position: 0 0, 0 0, 8px 8px;
  background-size: auto, 16px 16px, 16px 16px;
  box-shadow: 0 4px 0 #c7b58f;
  cursor: pointer;
}

.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center top;
  display: block;
}

.gallery-thumb.is-locked {
  display: grid;
  place-items: center;
  color: rgba(75, 64, 51, 0.48);
  background: rgba(255, 250, 240, 0.54);
  box-shadow: none;
  cursor: default;
}

.gallery-thumb.is-locked span {
  font-size: 34px;
  font-weight: 900;
  line-height: 1;
}

.gallery-preview {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(75, 64, 51, 0.42);
}

.gallery-preview-card {
  display: grid;
  gap: 8px;
  width: min(86vw, 360px);
  max-height: min(82vh, 720px);
  padding: 12px;
  border-radius: 18px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.gallery-preview-image {
  width: 100%;
  max-height: min(68vh, 620px);
  object-fit: contain;
}

.gallery-preview-caption {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  text-align: center;
}

.ndc-filter-panel {
  display: grid;
  gap: 10px;
}

.ndc-drum-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.ndc-drum-control {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.ndc-drum {
  --drum-row: 38px;
  position: relative;
  height: calc(var(--drum-row) * 3);
  overflow: hidden;
  border: 2px solid rgba(111, 95, 73, 0.42);
  border-radius: 16px;
  background:
    linear-gradient(rgba(255, 250, 240, 0.92), rgba(255, 250, 240, 0) 32%, rgba(255, 250, 240, 0) 68%, rgba(255, 250, 240, 0.92)),
    var(--paper);
}

.ndc-drum::before,
.ndc-drum::after {
  content: "";
  position: absolute;
  z-index: 2;
  left: 10px;
  right: 10px;
  height: 1px;
  background: rgba(111, 95, 73, 0.24);
  pointer-events: none;
}

.ndc-drum::before {
  top: var(--drum-row);
}

.ndc-drum::after {
  bottom: var(--drum-row);
}

.ndc-drum-highlight {
  position: absolute;
  z-index: 1;
  left: 6px;
  right: 6px;
  top: 50%;
  height: var(--drum-row);
  border-radius: 12px;
  background: rgba(227, 237, 216, 0.72);
  transform: translateY(-50%);
  pointer-events: none;
}

.ndc-drum-options {
  position: relative;
  z-index: 3;
  height: 100%;
  overflow-y: auto;
  padding-block: var(--drum-row);
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.ndc-drum-options::-webkit-scrollbar {
  display: none;
}

.ndc-drum-option {
  display: grid;
  place-items: center;
  width: 100%;
  height: var(--drum-row);
  min-height: var(--drum-row);
  padding: 0;
  border: 0;
  background: transparent;
  color: rgba(75, 64, 51, 0.58);
  box-shadow: none;
  scroll-snap-align: center;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.ndc-drum-option.is-selected {
  color: var(--ink);
  font-size: 22px;
}

.ndc-result-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 900;
}

.ndc-result-count {
  color: var(--muted);
  font-size: 13px;
}

.ndc-table {
  display: grid;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
}

.ndc-table-row {
  display: grid;
  grid-template-columns: 74px 1fr;
  min-width: 0;
}

.ndc-table-row + .ndc-table-row {
  border-top: 1px solid var(--line);
}

.ndc-table-row > div {
  min-width: 0;
  padding: 9px 10px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.ndc-table-row > div + div {
  border-left: 1px solid var(--line);
}

.ndc-table-head {
  background: #eadfc8;
  color: #5a4a38;
  font-size: 13px;
  font-weight: 900;
}

.ndc-code-cell {
  font-weight: 900;
  text-align: center;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 18px 8px;
  font-weight: 800;
}

@media (min-width: 431px) {
  body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
  }

  .phone-shell {
    height: min(844px, calc(100vh - 48px));
    min-height: min(844px, calc(100vh - 48px));
    border-radius: 32px;
  }

  .screen {
    height: 100%;
    min-height: 100%;
  }
}

@media (max-height: 700px) {
  .logo-slot {
    max-height: 104px;
  }

  .title {
    font-size: 32px;
  }

  .home-credit {
    padding: 5px 8px;
    font-size: 9px;
  }

  .section-title {
    font-size: 21px;
  }

  .panel h2,
  .panel h3 {
    font-size: 16px;
  }

  .quiz-meta {
    font-size: 14px;
  }

  .question-card {
    block-size: 96px;
  }

  .question-kicker {
    font-size: 12px;
  }

  .question-text.code-question {
    font-size: 30px;
  }

  .question-text.subject-question {
    font-size: 18px;
  }

  .answer-button {
    min-height: 42px;
    font-size: 12px;
    line-height: 1.16;
  }

  .quiz-character {
    bottom: -150px;
    height: 360px;
  }

  .score {
    font-size: 34px;
  }

  .speech {
    font-size: 14px;
    line-height: 1.42;
  }
}
