:root {
  color-scheme: light dark;
  --bg: #f7f3ec;
  --bg-soft: #fffaf2;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-strong: #ffffff;
  --ink: #241f1a;
  --muted: #756f66;
  --subtle: #a49b8d;
  --line: rgba(65, 48, 28, 0.12);
  --brand: #b85b4d;
  --brand-strong: #913f36;
  --indigo: #3d4b74;
  --green: #5f8d72;
  --amber: #c58a30;
  --pink: #d96f8f;
  --shadow: 0 22px 70px rgba(50, 38, 24, 0.13);
  --shadow-soft: 0 12px 38px rgba(50, 38, 24, 0.09);
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --max: 1180px;
  --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Hiragino Sans GB", "Hiragino Kaku Gothic ProN", "Noto Sans CJK SC", "Noto Sans JP", "Microsoft YaHei", sans-serif;
  --font-jp: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15120f;
    --bg-soft: #201a15;
    --surface: rgba(35, 30, 25, 0.93);
    --surface-strong: #29231d;
    --ink: #f4ede2;
    --muted: #c8bbac;
    --subtle: #9e9182;
    --line: rgba(255, 238, 210, 0.14);
    --brand: #e08776;
    --brand-strong: #ffb4a5;
    --indigo: #9aa8d6;
    --green: #95c3a9;
    --amber: #e5b864;
    --pink: #ee9cb4;
    --shadow: 0 24px 90px rgba(0, 0, 0, 0.42);
    --shadow-soft: 0 14px 48px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

html {
  width: 100%;
  scroll-behavior: smooth;
}

body {
  width: 100%;
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% -8%, rgba(184, 91, 77, 0.22), transparent 34rem),
    radial-gradient(circle at 92% 0%, rgba(95, 141, 114, 0.18), transparent 30rem),
    linear-gradient(135deg, var(--bg), var(--bg-soft));
  font-family: var(--font-sans);
}

body,
#app,
.page,
.shell,
main,
section,
article,
aside,
header,
nav,
div {
  min-width: 0;
}

#app,
.page {
  width: 100%;
  max-width: 100%;
}

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 58%, transparent);
  outline-offset: 3px;
}

.page {
  min-height: 100vh;
  padding: 26px clamp(16px, 4vw, 48px) 80px;
}

.shell {
  width: min(100%, var(--max));
  max-width: var(--max);
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 14px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.brandMark {
  display: grid;
  flex: 0 0 36px;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 14px;
  color: #fffaf6;
  background: linear-gradient(135deg, var(--brand), var(--indigo));
}

.nav {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.94rem;
}

.nav a {
  min-width: 0;
  padding: 9px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.nav a:hover,
.nav a.active {
  color: var(--ink);
  background: rgba(184, 91, 77, 0.11);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(300px, 0.92fr);
  gap: clamp(24px, 5vw, 54px);
  align-items: center;
  margin: 34px 0 48px;
}

.hero > *,
.lessonLayout > * {
  min-width: 0;
  max-width: 100%;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 7px 12px;
  border: 1px solid rgba(184, 91, 77, 0.22);
  border-radius: 999px;
  color: var(--brand-strong);
  background: rgba(184, 91, 77, 0.08);
  font-size: 0.88rem;
  font-weight: 700;
}

h1 {
  max-width: 18ch;
  margin: 18px 0 16px;
  font-size: clamp(2.1rem, 4.3vw, 3.8rem);
  line-height: 1.08;
  letter-spacing: -0.045em;
  overflow-wrap: break-word;
  word-break: normal;
  line-break: auto;
}

h2 {
  margin: 0 0 14px;
  font-size: clamp(1.55rem, 3vw, 2.4rem);
  line-height: 1.12;
  letter-spacing: -0.03em;
}

h3 {
  margin: 0;
  font-size: 1.08rem;
}

p {
  color: var(--muted);
  line-height: 1.78;
}

.lead {
  max-width: 680px;
  font-size: clamp(1rem, 2vw, 1.18rem);
}

.kicker {
  color: var(--brand-strong);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.meta,
.progressMeta,
.levelMeta {
  color: var(--muted);
  font-size: 0.88rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 26px;
}

.compactActions { margin-top: 18px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft);
}

.btn.primary {
  border-color: transparent;
  color: #fffaf6;
  background: linear-gradient(135deg, var(--brand), var(--indigo));
}

.btn.ghost { background: transparent; }

.btn.disabled {
  color: var(--subtle);
  background: rgba(117, 111, 102, 0.06);
  cursor: not-allowed;
}

.btn.disabled:hover {
  transform: none;
  box-shadow: none;
}

.panel,
.card {
  border: 1px solid var(--line);
  background: var(--surface);
}

.panel {
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.heroPanel {
  position: relative;
  padding: clamp(22px, 4vw, 34px);
}

.heroPanel::before {
  position: absolute;
  z-index: -1;
  right: 0;
  bottom: 0;
  width: 62%;
  height: 72%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(184, 91, 77, 0.2), transparent 68%);
  content: "";
}

.jpLine,
.heroJapanese {
  font-family: var(--font-jp);
}

.heroJapanese {
  font-size: clamp(1.55rem, 3.4vw, 2.8rem);
  line-height: 1.28;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.miniStats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 26px;
}

.miniStat {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface-strong) 60%, transparent);
}

.miniStat strong {
  display: block;
  font-size: 1.35rem;
  overflow-wrap: break-word;
}

.miniStat span {
  color: var(--muted);
  font-size: 0.84rem;
}

.grid {
  display: grid;
  gap: 18px;
}

.languageGrid,
.levelGrid,
.topicGrid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.card {
  position: relative;
  min-width: 0;
  padding: 22px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  animation: rise 0.48s var(--delay, 0ms) ease both;
}

.card:hover {
  transform: translateY(-4px);
  border-color: color-mix(in srgb, var(--brand) 42%, var(--line));
  box-shadow: var(--shadow);
}

.languageCard {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 178px;
}

.languageCard.available {
  grid-column: span 2;
  min-height: 220px;
  border-color: color-mix(in srgb, var(--brand) 36%, var(--line));
  background: linear-gradient(135deg, color-mix(in srgb, var(--surface) 92%, var(--brand) 8%), var(--surface));
}

.languageCard.planned { box-shadow: none; }

.languageSymbol {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 20px;
  color: #fffaf6;
  background: linear-gradient(135deg, var(--brand), var(--indigo));
  font-size: 1.35rem;
  font-weight: 900;
}

.languageStatus {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--muted);
  background: rgba(117, 111, 102, 0.1);
  font-size: 0.78rem;
  font-weight: 800;
}

.languageCard.available .languageStatus {
  color: var(--green);
  background: rgba(95, 141, 114, 0.14);
}

.sectionHead {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin: 0 0 18px;
}

.sectionHead h2,
.sectionHead p { margin-bottom: 0; }
.sectionHead p { max-width: 520px; }

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

.levelCardTop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.levelBadge {
  display: grid;
  flex: 0 0 48px;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 17px;
  color: #fffaf6;
  background: linear-gradient(135deg, var(--brand), var(--indigo));
  font-weight: 900;
}

.levelCard h3 { font-size: 1.35rem; }
.levelCard p { margin: 0; }

.levelMeta {
  display: grid;
  gap: 4px;
  min-height: 42px;
}

.progress {
  height: 9px;
  border-radius: 999px;
  background: rgba(117, 111, 102, 0.16);
  overflow: hidden;
}

.progress > span {
  display: block;
  width: var(--value, 0%);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), var(--green));
  transition: width 0.35s ease;
}

.progressMeta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.progressMeta strong {
  color: var(--ink);
  font-size: 0.84rem;
}

.pageHero {
  max-width: 920px;
  margin: 34px 0 48px;
}

.pageHero h1 { max-width: 20ch; }

.topicExplorer { margin-top: 18px; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 26px 0 18px;
}

.search {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.search input {
  width: 100%;
  min-width: 0;
  height: 48px;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

.chipRow {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 38px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  cursor: pointer;
}

.chip.active {
  border-color: transparent;
  color: #fffaf6;
  background: var(--brand);
}

.topicCard {
  display: grid;
  gap: 14px;
}

.topicCard[hidden] { display: none; }

.topicTop {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  color: var(--muted);
  background: rgba(117, 111, 102, 0.11);
  font-size: 0.78rem;
  white-space: nowrap;
}

.badge.done { color: var(--green); background: rgba(95, 141, 114, 0.13); }
.badge.learning { color: var(--amber); background: rgba(197, 138, 48, 0.13); }

.lessonLayout {
  display: grid;
  grid-template-columns: minmax(0, 780px) minmax(280px, 340px);
  justify-content: center;
  align-items: start;
  gap: 22px;
}

.lessonCard {
  width: 100%;
  max-width: 780px;
  padding: clamp(22px, 4vw, 36px);
}

.lessonHeader {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.lessonHeader > div {
  flex: 1;
  min-width: 0;
}

.lessonHeader h1 {
  max-width: 21ch;
  margin-bottom: 0;
  font-size: clamp(1.65rem, 2.8vw, 2.65rem);
  line-height: 1.18;
  letter-spacing: -0.025em;
}

.audioButton {
  display: grid;
  flex: 0 0 62px;
  place-items: center;
  width: 62px;
  height: 62px;
  border: 0;
  border-radius: 22px;
  color: #fffaf6;
  background: linear-gradient(135deg, var(--brand), var(--indigo));
  box-shadow: var(--shadow-soft);
  cursor: pointer;
}

.audioButton.playing,
.bottomBar button.playing {
  background: linear-gradient(135deg, var(--green), var(--brand));
}

.audioButton.loading { animation: pulse 1s ease infinite; }

.audioStatus {
  margin-bottom: 22px;
  color: var(--muted);
  font-size: 0.86rem;
}

[data-audio-element] { display: none; }

.japaneseText {
  width: 100%;
  max-width: 44rem;
  font-family: var(--font-jp);
  font-size: clamp(1.28rem, 2vw, 1.8rem);
  line-height: 1.82;
  letter-spacing: 0.03em;
  overflow-wrap: break-word;
  word-break: normal;
  line-break: strict;
}

.japaneseText p {
  max-width: 100%;
  margin: 0 0 1.05em;
  color: var(--ink);
}

.speaker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 34px;
  margin-right: 8px;
  padding: 0 8px;
  border-radius: 12px;
  color: #fffaf6;
  background: var(--indigo);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 800;
}

.toggleBlock {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface-strong) 70%, transparent);
}

.toggleHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 16px 18px;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}

.toggleHead::-webkit-details-marker { display: none; }
.toggleHead::after { color: var(--muted); content: "＋"; }
.toggleBlock[open] > .toggleHead::after { content: "－"; }

.toggleHead span {
  flex: 0 0 auto;
  margin-left: auto;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
}

.toggleBody { padding: 0 18px 18px; }
.translationText { display: grid; gap: 8px; }
.translationText p { margin: 0; }

.originalTranslation {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.originalTranslation summary {
  color: var(--brand-strong);
  cursor: pointer;
  font-weight: 800;
}

.vocabList {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.vocabItem {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) minmax(96px, auto);
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 12px;
  border-radius: var(--radius-md);
  background: rgba(117, 111, 102, 0.08);
}

.vocabNo { color: var(--brand-strong); }
.kana { color: var(--muted); font-size: 0.85rem; }
.pos {
  min-width: 0;
  color: var(--brand-strong);
  font-size: 0.82rem;
  font-weight: 800;
  overflow-wrap: break-word;
  text-align: right;
}

.lessonNavigation {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.lessonNavigation .btn { padding-inline: 12px; }

.sideStack {
  display: grid;
  gap: 16px;
}

.sideCard { padding: 20px; }

.bottomBar {
  display: none;
  position: fixed;
  z-index: 30;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  left: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.bottomBar button,
.bottomBar a {
  display: grid;
  min-width: 0;
  min-height: 42px;
  place-items: center;
  padding: 4px;
  border: 0;
  border-radius: 16px;
  color: var(--ink);
  background: rgba(117, 111, 102, 0.1);
  font-size: 0.86rem;
}

.bottomBar button.active {
  color: #fffaf6;
  background: var(--brand);
}

.loadingState,
.errorState,
.planningState,
.emptyState {
  display: grid;
  justify-items: center;
  gap: 12px;
  min-height: 260px;
  padding: 42px;
  place-content: center;
  text-align: center;
}

.loadingDot {
  width: 34px;
  height: 34px;
  border: 4px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.errorState h1,
.planningState h1 { max-width: 18ch; }
.mutedText { color: var(--muted); }

.srOnly {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  border: 0;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

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

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 1040px) {
  .levelGrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topicGrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero,
  .lessonLayout { grid-template-columns: 1fr; }
  .lessonCard { max-width: 100%; }
  .sideStack { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .page { padding: 16px 16px 80px; }
  .page.hasBottomBar { padding-bottom: calc(118px + env(safe-area-inset-bottom)); }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 34px;
    border-radius: 24px;
  }

  .nav {
    display: grid;
    gap: 4px;
    width: 100%;
    max-width: none;
  }

  .nav-1 { grid-template-columns: 1fr; }
  .nav-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .nav-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .nav-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  .nav a {
    padding: 8px 4px;
    overflow: clip;
    font-size: 0.8rem;
    text-align: center;
    text-overflow: ellipsis;
  }

  .hero { margin-top: 24px; }

  h1 {
    max-width: none;
    font-size: clamp(1.9rem, 8.7vw, 2.6rem);
    line-height: 1.12;
    letter-spacing: -0.035em;
  }

  .lessonHeader h1 {
    max-width: none;
    font-size: clamp(1.45rem, 6.5vw, 1.9rem);
    letter-spacing: -0.02em;
  }

  .japaneseText {
    font-size: clamp(1.15rem, 4.8vw, 1.36rem);
    line-height: 1.9;
  }

  .languageGrid,
  .levelGrid,
  .topicGrid,
  .sideStack { grid-template-columns: 1fr; }

  .languageCard.available { grid-column: span 1; }
  .miniStats { grid-template-columns: 1fr; }
  .sectionHead { align-items: flex-start; flex-direction: column; gap: 4px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .lessonHeader { flex-direction: column; }
  .lessonNavigation { grid-template-columns: 1fr; }
  .bottomBar { display: grid; }
  .vocabItem { grid-template-columns: 42px minmax(0, 1fr); }
  .vocabItem .pos { grid-column: 2; text-align: left; }
}

@media (max-width: 340px) {
  .card,
  .lessonCard,
  .sideCard { padding: 16px; border-radius: 18px; }

  h1 { font-size: 1.78rem; }
  .lessonHeader h1 { font-size: 1.36rem; }
  .heroJapanese { font-size: 1.35rem; }
  .japaneseText { font-size: 1.12rem; }
  .bottomBar { right: 8px; left: 8px; gap: 5px; padding: 7px; }
  .bottomBar button,
  .bottomBar a { font-size: 0.76rem; }
}
