* {
  box-sizing: border-box;
}

:root {
  --bg: #f5efe3;
  --paper: #fffdf7;
  --ink: #3d3429;
  --sub: #766957;
  --line: #d7c8b4;
  --green: #557a5c;
  --green-dark: #35543c;
  --gold: #c5913f;
  --red: #a9534c;
  --shadow: 0 12px 28px rgba(72, 54, 35, .12);
}

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(255,255,255,.8), transparent 34%),
    linear-gradient(145deg, #f8f3e8, #e9dec9);
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

#app {
  width: min(1100px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: grid;
}

.screen {
  display: none;
  width: 100%;
  min-height: calc(100dvh - 32px);
  animation: fadeIn .22s ease;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

#title-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.studio-brand {
  border: 0;
  background: transparent;
  color: var(--green-dark);
  font-weight: 800;
  letter-spacing: .08em;
  padding: 8px 18px;
  cursor: pointer;
}

h1 {
  margin: 4px 0 0;
  font-size: clamp(2.7rem, 8vw, 5rem);
  letter-spacing: .06em;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
}

h2 {
  margin: 2px 0;
  font-size: clamp(1.7rem, 4vw, 2.4rem);
}

.subtitle {
  margin: 8px 0 28px;
  color: var(--sub);
  font-weight: 700;
}

.menu-grid {
  width: min(820px, 100%);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.mode-card {
  min-height: 126px;
  border: 2px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 253, 247, .94);
  box-shadow: var(--shadow);
  padding: 20px;
  text-align: left;
  cursor: pointer;
  transition: transform .13s ease, border-color .13s ease, box-shadow .13s ease;
}

.mode-card:active {
  transform: scale(.98);
}

.mode-card:hover, .mode-card:focus-visible {
  border-color: var(--green);
  box-shadow: 0 14px 32px rgba(53, 84, 60, .17);
}

.mode-title {
  display: block;
  font-size: clamp(1.3rem, 3vw, 1.8rem);
  font-weight: 900;
  color: var(--green-dark);
}

.mode-desc {
  display: block;
  margin-top: 8px;
  color: var(--sub);
  line-height: 1.5;
}

.collection-card {
  border-color: #d8bd83;
}

.text-button {
  margin-top: 22px;
  border: 0;
  background: transparent;
  color: var(--sub);
  text-decoration: underline;
  padding: 10px;
  cursor: pointer;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.topbar.compact {
  margin-bottom: 12px;
}

.back-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  padding: 10px 18px;
  font-weight: 800;
  cursor: pointer;
}

.eyebrow {
  margin: 0;
  color: var(--green);
  font-weight: 900;
  letter-spacing: .08em;
}

.grade-grid {
  margin: auto;
  width: min(780px, 100%);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.grade-grid button {
  min-height: 100px;
  border: 0;
  border-radius: 22px;
  background: var(--paper);
  box-shadow: var(--shadow);
  font-size: clamp(1.2rem, 3vw, 1.7rem);
  font-weight: 900;
  cursor: pointer;
}

.grade-grid button:nth-child(1) { border-bottom: 8px solid #e56b6f; }
.grade-grid button:nth-child(2) { border-bottom: 8px solid #e9a23b; }
.grade-grid button:nth-child(3) { border-bottom: 8px solid #e0c34c; }
.grade-grid button:nth-child(4) { border-bottom: 8px solid #69a96b; }
.grade-grid button:nth-child(5) { border-bottom: 8px solid #5e91c5; }
.grade-grid button:nth-child(6) { border-bottom: 8px solid #8b71b7; }
.grade-grid .all-grade {
  grid-column: 1 / -1;
  border-bottom: 8px solid var(--green-dark);
}

.quiz-status {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-weight: 800;
}

#progress-label {
  color: var(--sub);
  font-size: .92rem;
}

.life-display {
  min-width: 74px;
  text-align: right;
  font-weight: 900;
  color: var(--red);
  letter-spacing: .1em;
}

.question-card {
  width: min(920px, 100%);
  margin: auto;
  padding: clamp(20px, 4vw, 40px);
  border: 2px solid var(--line);
  border-radius: 28px;
  background: rgba(255, 253, 247, .96);
  box-shadow: var(--shadow);
  text-align: center;
}

.instruction {
  margin: 0 0 12px;
  color: var(--green-dark);
  font-size: 1.1rem;
  font-weight: 900;
}

.word-display {
  min-height: 1.2em;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(3.2rem, 10vw, 6.6rem);
  font-weight: 800;
  letter-spacing: .12em;
}

.word-display .target {
  color: var(--green-dark);
  text-decoration: underline;
  text-decoration-thickness: .08em;
  text-underline-offset: .12em;
}

.hidden-kanji {
  margin: 8px auto 12px;
  width: fit-content;
  min-width: 220px;
  padding: 12px 24px;
  border: 2px dashed var(--line);
  border-radius: 18px;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(2.2rem, 7vw, 4.4rem);
  font-weight: 900;
}

.hidden-radical {
  display: inline-grid;
  place-items: center;
  min-width: .95em;
  margin-right: .06em;
  color: var(--sub);
  border: 3px dashed #b9aa96;
  border-radius: 8px;
  line-height: .9;
}

.question-text {
  margin: 14px 0 18px;
  font-size: clamp(1.15rem, 3vw, 1.65rem);
  font-weight: 900;
}

.choice-area {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.choice-button {
  min-height: 72px;
  border: 2px solid var(--line);
  border-radius: 18px;
  background: #fff;
  padding: 12px;
  font-weight: 900;
  cursor: pointer;
}

.choice-button .radical-glyph {
  display: block;
  font-size: 1.8rem;
  font-family: "Yu Mincho", serif;
}

.choice-button .radical-name {
  display: block;
  margin-top: 2px;
  color: var(--sub);
  font-size: .95rem;
}

.choice-button.selected {
  border-color: var(--green);
  background: #edf5ee;
}

.choice-button.correct {
  border-color: var(--green);
  background: #e6f2e8;
}

.choice-button.wrong {
  border-color: var(--red);
  background: #f8e8e6;
}

.primary-button, .secondary-button {
  border-radius: 999px;
  padding: 13px 26px;
  font-weight: 900;
  cursor: pointer;
}

.primary-button {
  margin-top: 18px;
  border: 0;
  background: var(--green-dark);
  color: white;
}

.secondary-button {
  border: 2px solid var(--green);
  background: white;
  color: var(--green-dark);
}

.feedback {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  padding: 24px;
  background: rgba(245, 239, 227, .94);
  backdrop-filter: blur(4px);
}

.feedback-mark {
  font-size: 4rem;
  font-weight: 900;
  color: var(--green);
}

.feedback h3 {
  margin: 6px 0;
  font-size: clamp(1.7rem, 5vw, 3rem);
}

.feedback p {
  max-width: 560px;
  margin: 4px 0 18px;
  line-height: 1.7;
}

.result-card {
  margin: auto;
  width: min(620px, 100%);
  padding: 34px;
  border-radius: 28px;
  background: var(--paper);
  box-shadow: var(--shadow);
  text-align: center;
}

.result-score {
  margin: 22px auto;
  font-size: clamp(2.8rem, 10vw, 5.5rem);
  font-weight: 900;
  color: var(--green-dark);
}

.result-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}

.collection-summary {
  width: min(900px, 100%);
  margin: 0 auto 16px;
  padding: 14px 18px;
  border-radius: 16px;
  background: rgba(255,255,255,.65);
  color: var(--sub);
  font-weight: 800;
}

.collection-grid {
  width: min(900px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.collection-item {
  min-height: 150px;
  padding: 18px;
  border: 2px solid var(--line);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.collection-item.locked {
  opacity: .58;
  filter: grayscale(.4);
}

.collection-glyph {
  font-size: 2.6rem;
  font-family: "Yu Mincho", serif;
  color: var(--green-dark);
}

.collection-name {
  font-weight: 900;
}

.collection-count {
  margin-top: 8px;
  color: var(--sub);
  font-size: .92rem;
}

.hidden {
  display: none !important;
}

#particle-layer {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  overflow: hidden;
}

.particle {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
  animation: burst .8s ease-out forwards;
}

@keyframes burst {
  from { transform: translate(0, 0) scale(1); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) scale(.15); opacity: 0; }
}

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

@media (max-width: 680px) {
  .menu-grid, .choice-area {
    grid-template-columns: 1fr;
  }

  .grade-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grade-grid .all-grade {
    grid-column: 1 / -1;
  }

  .collection-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mode-card {
    min-height: 96px;
  }

  .word-display {
    letter-spacing: .05em;
  }
}

@media (orientation: landscape) and (max-height: 620px) {
  #title-screen {
    justify-content: flex-start;
  }

  h1 {
    font-size: 2.8rem;
  }

  .subtitle {
    margin-bottom: 14px;
  }

  .mode-card {
    min-height: 88px;
    padding: 14px 18px;
  }

  .question-card {
    padding: 16px 28px;
  }

  .word-display {
    font-size: 3.5rem;
  }

  .choice-button {
    min-height: 58px;
  }
}


.multi-select-note {
  width: fit-content;
  margin: 0 auto 16px;
  padding: 12px 22px;
  border: 3px solid var(--gold);
  border-radius: 999px;
  background: #fff7df;
  color: #6c4a16;
  font-size: clamp(1.25rem, 3.4vw, 2rem);
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(197, 145, 63, .18);
}
.multi-select-note strong {
  font-size: 1.16em;
  text-decoration: underline;
  text-decoration-thickness: .12em;
  text-underline-offset: .14em;
}
#submit-friends {
  min-width: min(360px, 92%);
  min-height: 64px;
  font-size: clamp(1.2rem, 3vw, 1.6rem);
}


/* Ver0.3: トレーニング・仲間探しの縦幅を圧縮 */
#quiz-screen .topbar {
  margin-bottom: 6px;
}

#quiz-screen .question-card {
  padding-top: 14px;
  padding-bottom: 14px;
}

#quiz-screen .instruction {
  margin-bottom: 6px;
}

#quiz-screen .word-display {
  font-size: clamp(2.8rem, 8vw, 5.2rem);
  line-height: 1.05;
}

#quiz-screen .hidden-kanji {
  margin-top: 4px;
  margin-bottom: 6px;
  padding-top: 7px;
  padding-bottom: 7px;
  font-size: clamp(2rem, 6vw, 3.6rem);
}

#quiz-screen .question-text {
  margin-top: 7px;
  margin-bottom: 10px;
}

#quiz-screen .choice-area {
  gap: 8px;
}

#quiz-screen .choice-button {
  min-height: 58px;
  padding-top: 8px;
  padding-bottom: 8px;
}

#quiz-screen .choice-button .radical-glyph {
  font-size: 1.55rem;
}

#quiz-screen .multi-select-note {
  margin-bottom: 8px;
  padding: 7px 16px;
  font-size: clamp(1.05rem, 2.7vw, 1.45rem);
}

#quiz-screen #submit-friends {
  min-height: 54px;
  margin-top: 10px;
}

@media (orientation: landscape) and (max-height: 700px) {
  #quiz-screen {
    min-height: calc(100dvh - 20px);
  }

  #quiz-screen .question-card {
    padding: 10px 22px;
  }

  #quiz-screen .word-display {
    font-size: 3rem;
  }

  #quiz-screen .hidden-kanji {
    font-size: 2.4rem;
  }

  #quiz-screen .choice-button {
    min-height: 50px;
  }
}


.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #f5efe3;
}

.loading-screen.hidden { display: none; }
.loading-card {
  width: min(460px, 100%);
  padding: 30px;
  border: 2px solid var(--line);
  border-radius: 24px;
  background: var(--paper);
  box-shadow: var(--shadow);
  text-align: center;
}
.loading-card strong { display:block; font-size:1.25rem; }
.loading-card span { display:block; margin-top:10px; color:var(--sub); }

.hidden-kanji-svg {
  width: clamp(120px, 22vw, 190px);
  height: clamp(120px, 22vw, 190px);
  display: block;
  margin: 0 auto;
}
.hidden-kanji-svg path {
  fill: none;
  stroke: #3d3429;
  stroke-width: 5.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.hidden-kanji-svg .radical-placeholder {
  fill: rgba(197,145,63,.08);
  stroke: #c5913f;
  stroke-width: 2;
  stroke-dasharray: 5 5;
}

.db-error {
  color: #8c3f38;
  font-weight: 800;
  line-height: 1.6;
}
