:root {
  color-scheme: light;
  --bg: #f7f3ec;
  --panel: #fffaf2;
  --panel-strong: #ffffff;
  --ink: #25211b;
  --muted: #80766b;
  --line: #e6ded1;
  --accent: #8f5b3e;
  --accent-2: #557c70;
  --danger: #b65b55;
  --warn: #b68644;
  --good: #4f7d63;
  --shadow: 0 20px 60px rgba(54, 38, 23, 0.1);
}

body.dark {
  color-scheme: dark;
  --bg: #151515;
  --panel: #1f1f1e;
  --panel-strong: #262624;
  --ink: #f0ebe2;
  --muted: #aaa093;
  --line: #3a3834;
  --accent: #d39d78;
  --accent-2: #8fb8a9;
  --danger: #d77d77;
  --warn: #d0a05d;
  --good: #83b894;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, rgba(143, 91, 62, 0.08), transparent 26rem), var(--bg);
  color: var(--ink);
  font-family: Inter, "Hiragino Sans", "Yu Gothic", "Noto Sans JP", "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar,
.layout,
.metrics-grid,
.section-head,
.search-row,
.answer-row,
.stats-grid {
  display: grid;
  gap: 16px;
}

.topbar {
  grid-template-columns: 1fr auto;
  align-items: center;
  margin-bottom: 20px;
}

.kicker {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(32px, 6vw, 58px);
  font-weight: 500;
}

h2 {
  font-size: 22px;
  font-weight: 650;
}

.top-actions {
  display: flex;
  gap: 10px;
}

.icon-button,
.soft-button,
.primary-button,
.answer-row button,
.nav-button,
.choice-grid button,
.speak-pill {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  min-height: 42px;
}

.icon-button {
  width: 44px;
  font-size: 18px;
}

.layout {
  grid-template-columns: 230px 1fr;
  align-items: start;
}

.sidebar,
.content,
.word-card,
.test-card,
.settings-panel,
.list-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  box-shadow: var(--shadow);
}

.sidebar {
  position: sticky;
  top: 20px;
  padding: 18px;
}

.progress-ring {
  position: relative;
  width: 148px;
  height: 148px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
}

.progress-ring svg {
  position: absolute;
  inset: 0;
  transform: rotate(-90deg);
}

.progress-ring circle {
  fill: none;
  stroke: var(--line);
  stroke-width: 10;
}

.progress-ring #masteryCircle {
  stroke: var(--accent-2);
  stroke-linecap: round;
  stroke-dasharray: 327;
  stroke-dashoffset: 327;
  transition: stroke-dashoffset 0.3s ease;
}

.progress-ring div {
  text-align: center;
}

.progress-ring strong {
  display: block;
  font-size: 28px;
}

.progress-ring span,
.metric span,
.card-topline,
.source-note,
.test-result {
  color: var(--muted);
  font-size: 13px;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-button {
  text-align: left;
  padding: 0 14px;
}

.nav-button.active {
  border-color: color-mix(in srgb, var(--accent) 60%, var(--line));
  background: color-mix(in srgb, var(--accent) 12%, var(--panel-strong));
  color: var(--accent);
}

.content {
  padding: 18px;
}

.metrics-grid {
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 16px;
}

.metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  padding: 14px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-head {
  grid-template-columns: 1fr auto;
  align-items: center;
  margin: 18px 0 14px;
}

.soft-button,
.primary-button {
  padding: 0 16px;
}

.primary-button {
  width: min(240px, 100%);
  margin: 28px auto 0;
  display: block;
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.word-card,
.test-card {
  position: relative;
  min-height: 390px;
  padding: 28px;
  overflow: hidden;
}

.card-topline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 22px;
}

.speak-pill {
  position: absolute;
  right: 24px;
  top: 64px;
  width: 46px;
  min-height: 46px;
  border-radius: 50%;
}

.word-card h3,
.test-card h3 {
  margin-top: 34px;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(54px, 10vw, 96px);
  font-weight: 500;
  line-height: 1.05;
}

.kana {
  margin-top: 12px;
  color: var(--accent);
  font-size: 24px;
}

.meaning {
  margin-top: 26px;
  font-size: 24px;
  line-height: 1.45;
}

.example-block {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
  line-height: 1.7;
}

.example-block span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.answer-row {
  grid-template-columns: repeat(3, 1fr);
  margin-top: 14px;
}

.answer-row button {
  min-height: 54px;
  color: #fff;
  border: 0;
}

.answer-row .danger {
  background: var(--danger);
}

.answer-row .warn {
  background: var(--warn);
}

.answer-row .good {
  background: var(--good);
}

.hidden {
  display: none !important;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 28px;
}

.choice-grid button {
  min-height: 72px;
  padding: 12px;
  text-align: left;
  line-height: 1.45;
}

.choice-grid button.correct {
  border-color: var(--good);
  background: color-mix(in srgb, var(--good) 18%, var(--panel-strong));
}

.choice-grid button.wrong {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 16%, var(--panel-strong));
}

.test-card h3 {
  font-size: clamp(42px, 8vw, 78px);
}

.test-card > p {
  margin-top: 8px;
  color: var(--accent);
  font-size: 20px;
}

.search-row {
  grid-template-columns: 1fr 160px;
}

.search-row input,
.search-row select,
.settings-panel input,
.settings-panel select {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  padding: 0 12px;
}

.list-panel {
  max-height: 560px;
  overflow: auto;
  padding: 8px;
}

.list-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
}

.list-item:last-child {
  border-bottom: 0;
}

.list-item strong {
  display: block;
  font-size: 18px;
}

.list-item span {
  color: var(--muted);
  font-size: 13px;
}

.stats-grid {
  grid-template-columns: repeat(4, 1fr);
}

.heatmap {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  gap: 6px;
}

.heat-cell {
  aspect-ratio: 1;
  border-radius: 4px;
  background: var(--line);
}

.heat-cell[data-level="1"] {
  background: color-mix(in srgb, var(--accent-2) 30%, var(--line));
}

.heat-cell[data-level="2"] {
  background: color-mix(in srgb, var(--accent-2) 55%, var(--line));
}

.heat-cell[data-level="3"] {
  background: color-mix(in srgb, var(--accent-2) 80%, var(--line));
}

.settings-panel {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.settings-panel label {
  display: grid;
  gap: 8px;
}

.toggle-line {
  grid-template-columns: 1fr auto;
  align-items: center;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 20px, 720px);
    padding: 16px 0 92px;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    top: auto;
    z-index: 10;
    padding: 8px;
  }

  .progress-ring {
    display: none;
  }

  .nav-tabs {
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
  }

  .nav-button {
    min-height: 44px;
    padding: 0;
    text-align: center;
    font-size: 13px;
  }

  .metrics-grid,
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .section-head,
  .search-row,
  .answer-row,
  .choice-grid {
    grid-template-columns: 1fr;
  }

  .word-card,
  .test-card {
    min-height: 420px;
    padding: 22px;
  }
}

/* Reference-inspired compact dark layout */
body {
  background: #0c0c0c;
}

body:not(.dark) {
  --bg: #f7f3ec;
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  padding: 0;
}

.topbar {
  min-height: 70px;
  grid-template-columns: 180px 1fr 44px;
  gap: 0;
  align-items: stretch;
  margin: 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: center;
  padding: 0 10px;
  color: var(--ink);
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
}

.brand::first-letter {
  color: #ff563f;
}

.topbar .icon-button {
  align-self: center;
  justify-self: center;
  width: 28px;
  min-height: 28px;
  border-radius: 50%;
  color: #f0b35a;
  font-size: 13px;
}

.layout {
  display: block;
}

.content {
  width: min(520px, calc(100% - 28px));
  margin: 0 auto;
  padding: 14px 0 36px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.nav-tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
}

.nav-button {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  text-align: center;
  min-height: 70px;
  padding: 0;
  border-bottom: 2px solid transparent;
}

.nav-button.active {
  background: transparent;
  color: #ffc15d;
  border-color: #ff4f39;
}

.metrics-grid {
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 0 0 10px;
}

.metric {
  min-height: 44px;
  padding: 6px 8px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.metric span {
  display: none;
}

.metric strong {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
}

.study-status {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  padding: 5px 0 8px;
  border-bottom: 1px solid var(--line);
}

.study-status b {
  color: #ffc15d;
}

.status-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.daily-stepper {
  display: grid;
  grid-template-columns: auto 26px 54px 26px;
  align-items: center;
  gap: 4px;
  min-height: 32px;
  padding: 2px 4px 2px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
}

.daily-stepper button,
.daily-stepper input {
  min-height: 24px;
  border: 0;
  border-radius: 6px;
  background: #272727;
  color: var(--ink);
  text-align: center;
}

.daily-stepper button {
  padding: 0;
  color: #ffc15d;
}

.daily-stepper input {
  width: 54px;
  padding: 0 3px;
}

.study-tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.study-tile {
  min-height: 120px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
}

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

.study-tile strong {
  color: #ffc15d;
  font-size: 14px;
}

.study-tile small {
  color: var(--muted);
}

.word-card,
.test-card,
.settings-panel,
.list-panel {
  box-shadow: none;
}

.word-card {
  min-height: 280px;
  margin-top: 16px;
  padding: 22px 20px;
  background: var(--panel);
}

.word-card h3 {
  margin-top: 18px;
  font-size: clamp(48px, 10vw, 72px);
  text-align: center;
}

.kana,
.meaning {
  text-align: center;
}

.kana {
  font-size: 18px;
}

.meaning {
  font-size: 20px;
}

.speak-pill {
  right: 16px;
  top: 54px;
  width: 28px;
  min-height: 20px;
  border-radius: 6px;
  font-size: 12px;
}

.example-block {
  border-top: 0;
  background: color-mix(in srgb, var(--panel-strong) 78%, transparent);
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
}

.primary-button {
  min-height: 20px;
  width: 28px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border-color: var(--muted);
  font-size: 0;
}

.primary-button::after {
  content: "";
  display: block;
  width: 14px;
  height: 2px;
  margin: auto;
  border-radius: 2px;
  background: var(--muted);
}

.answer-row {
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 10px;
}

.answer-row button {
  min-height: 38px;
  border-radius: 8px;
  background: #272727;
}

.answer-row .danger {
  color: #ff4f39;
}

.answer-row .warn {
  color: #ffc15d;
}

.answer-row .good {
  color: #71ca75;
}

.answer-row .master {
  color: #6ec7ff;
}

.audio-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
}

.audio-bar button {
  border: 0;
  background: transparent;
  color: var(--ink);
}

.audio-bar .soft-button {
  border-left: 1px solid var(--line);
  border-radius: 0 18px 18px 0;
  min-height: 36px;
  color: #ffc15d;
}

.section-head {
  margin-top: 0;
}

.test-card,
.settings-panel,
.list-panel {
  background: var(--panel);
}

.search-row {
  grid-template-columns: 1fr 122px;
}

.stats-grid {
  grid-template-columns: repeat(4, 1fr);
}

.progress-ring {
  display: none;
}

@media (max-width: 700px) {
  .topbar {
    grid-template-columns: 86px 1fr 36px;
    min-height: 58px;
  }

  .brand {
    font-size: 14px;
  }

  .nav-button {
    min-height: 58px;
    font-size: 12px;
  }

  .content {
    width: min(100% - 18px, 520px);
    padding-bottom: 18px;
  }

  .metrics-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
  }

  .study-status {
    grid-template-columns: 1fr;
  }

  .status-actions {
    justify-content: space-between;
  }

  .metric strong {
    font-size: 11px;
  }

  .study-tiles,
  .answer-row,
  .choice-grid,
  .search-row {
    grid-template-columns: 1fr;
  }
}
