:root {
  --bg: #f7f3ec;
  --ink: #241f1b;
  --muted: #756b62;
  --card: rgba(255, 255, 255, 0.78);
  --line: rgba(45, 35, 25, 0.11);
  --red: #e85d75;
  --orange: #f59f3a;
  --green: #3fb984;
  --blue: #4f7cff;
  --purple: #8067dc;
  --shadow: 0 24px 70px rgba(69, 46, 20, 0.14);
  --radius: 28px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Noto Sans JP", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(232, 93, 117, .25), transparent 35%),
    radial-gradient(circle at top right, rgba(79, 124, 255, .2), transparent 30%),
    linear-gradient(135deg, #fff8ed 0%, #f2eadf 100%);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  padding: 22px clamp(18px, 4vw, 60px);
  backdrop-filter: blur(18px);
  background: rgba(247, 243, 236, 0.72);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  color: white;
  font-family: "Noto Sans JP", sans-serif;
  font-size: 30px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--red), var(--purple));
  box-shadow: 0 14px 34px rgba(232, 93, 117, .35);
}
h1, h2, p { margin: 0; }
h1 { font-size: 24px; letter-spacing: -0.04em; }
.tagline, .sub, .hint { color: var(--muted); }
.tagline { font-size: 13px; margin-top: 2px; }

.tabs { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.tab, .chip, .btn, .qa {
  border: 0;
  font: inherit;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.tab, .chip {
  border-radius: 999px;
  padding: 10px 14px;
  background: rgba(255,255,255,.58);
  color: var(--muted);
  border: 1px solid transparent;
}
.tab:hover, .chip:hover, .qa:hover, .btn:hover { transform: translateY(-1px); }
.tab.active, .chip.active {
  color: var(--ink);
  background: white;
  border-color: var(--line);
  box-shadow: 0 10px 28px rgba(50, 35, 20, .08);
}

main { padding: 34px clamp(18px, 4vw, 60px) 110px; }
.view { display: none; animation: fade .22s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}
.stat-card, .panel {
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.stat-card {
  padding: 22px;
  border-radius: 24px;
}
.stat-num { display: block; font-size: 40px; font-weight: 800; letter-spacing: -0.06em; }
.stat-label { color: var(--muted); font-size: 14px; }
.panel {
  border-radius: var(--radius);
  padding: clamp(18px, 3vw, 30px);
  margin-bottom: 18px;
}
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.panel-head h2 { font-size: 24px; letter-spacing: -0.04em; }
.pill {
  border-radius: 999px;
  padding: 9px 13px;
  background: #fff0cc;
  color: #9a5a00;
  font-weight: 700;
}

.heatmap { display: grid; grid-template-columns: repeat(14, 1fr); gap: 8px; }
.day {
  aspect-ratio: 1;
  min-height: 24px;
  border-radius: 9px;
  background: rgba(36,31,27,.08);
  border: 1px solid rgba(36,31,27,.06);
}
.day.level-1 { background: rgba(63,185,132,.32); }
.day.level-2 { background: rgba(63,185,132,.58); }
.day.level-3 { background: rgba(63,185,132,.88); }

.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 14px; }
.qa {
  text-align: left;
  padding: 18px;
  border-radius: 20px;
  background: white;
  border: 1px solid var(--line);
  font-weight: 700;
  box-shadow: 0 14px 28px rgba(50, 35, 20, .08);
}

.form { display: grid; gap: 16px; }
label { display: grid; gap: 7px; font-weight: 700; }
input, textarea, .search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 13px 14px;
  background: rgba(255,255,255,.82);
  color: var(--ink);
  font: inherit;
  outline: none;
}
textarea { resize: vertical; font-family: "Noto Sans JP", Inter, sans-serif; }
input:focus, textarea:focus, .search:focus { border-color: rgba(79, 124, 255, .55); box-shadow: 0 0 0 4px rgba(79, 124, 255, .1); }
.row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.tabs-inline, .filter-row, .mode-switch { display: flex; flex-wrap: wrap; gap: 8px; }

.btn {
  border-radius: 16px;
  padding: 13px 16px;
  font-weight: 800;
}
.btn.primary { color: white; background: linear-gradient(135deg, var(--blue), var(--purple)); box-shadow: 0 16px 32px rgba(79, 124, 255, .28); }
.btn.ghost { background: rgba(255,255,255,.7); border: 1px solid var(--line); color: var(--ink); }
.btn.small { padding: 9px 12px; font-size: 13px; }
.btn.danger { background: #fff0f2; color: #b92c43; border: 1px solid rgba(232,93,117,.25); }

.list, .cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.list li, .mistake-card {
  padding: 16px;
  border-radius: 20px;
  background: rgba(255,255,255,.76);
  border: 1px solid var(--line);
}
.mistake-card { display: grid; gap: 10px; }
.japanese { font-family: "Noto Sans JP", sans-serif; font-size: 21px; line-height: 1.6; }
.wrong { color: #b92c43; text-decoration: line-through; text-decoration-thickness: 2px; }
.right { color: #147b54; font-weight: 800; }
.meta { display: flex; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: 13px; }
.meta span { background: rgba(36,31,27,.06); padding: 6px 9px; border-radius: 999px; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.practice-panel { min-height: 520px; }
.practice-area { display: grid; place-items: center; min-height: 390px; }
.flashcard {
  width: min(720px, 100%);
  min-height: 300px;
  padding: 34px;
  border-radius: 30px;
  background: linear-gradient(145deg, #fff, #fff8ed);
  border: 1px solid var(--line);
  box-shadow: 0 30px 80px rgba(50, 35, 20, .13);
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 20px;
  text-align: center;
}
.prompt-label { color: var(--muted); text-transform: uppercase; letter-spacing: .12em; font-size: 12px; font-weight: 800; }
.big-jp { font-family: "Noto Sans JP", sans-serif; font-size: clamp(30px, 5vw, 56px); line-height: 1.45; }
.answer-box { width: min(560px, 100%); }
.choice-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; width: 100%; }
.choice { padding: 14px; border-radius: 16px; border: 1px solid var(--line); background: white; cursor: pointer; font: inherit; }
.choice.correct { background: #e8fff4; border-color: rgba(63,185,132,.5); }
.choice.wrong-choice { background: #fff0f2; border-color: rgba(232,93,117,.45); }
.review-buttons { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.review-buttons .btn:nth-child(1) { background: #fff0f2; }
.review-buttons .btn:nth-child(2) { background: #fff6dd; }
.review-buttons .btn:nth-child(3) { background: #e8fff4; }
.review-buttons .btn:nth-child(4) { background: #edf1ff; }

.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px clamp(18px, 4vw, 60px);
  background: rgba(247, 243, 236, .78);
  backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}
.footer-actions { display: flex; gap: 8px; }
.toast {
  position: fixed;
  right: 24px;
  bottom: 78px;
  max-width: 340px;
  padding: 14px 16px;
  border-radius: 18px;
  background: #241f1b;
  color: white;
  box-shadow: var(--shadow);
  z-index: 10;
}

.dictionary-grid, .game-grid, .diagnosis-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.lookup-box, .line-import-box, .dict-card, .game-card {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255,255,255,.72);
  padding: 18px;
}
.line-import-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
}
.dict-results, .sentence-board, .mission-area, .diagnosis-area { display: grid; gap: 14px; }
.dict-card { display: grid; gap: 9px; }
.dict-section {
  display: grid;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.grammar-pill {
  display: inline-flex;
  margin: 0 8px 8px 0;
  padding: 8px 11px;
  border-radius: 999px;
  background: #edf1ff;
  color: #3047a8;
  font-weight: 700;
}
.coach-list { margin: 0; padding-left: 22px; color: var(--muted); line-height: 1.8; }
.game-grid { grid-template-columns: repeat(4, 1fr); margin-bottom: 18px; }
.game-card {
  text-align: left;
  display: grid;
  gap: 8px;
  min-height: 150px;
  box-shadow: 0 16px 36px rgba(50,35,20,.09);
}
.game-card span { font-size: 34px; }
.game-card b { font-size: 18px; }
.game-card small { color: var(--muted); line-height: 1.5; }
.mini-stats { margin-bottom: 0; }
.game-mission { width: min(860px, 100%); }
.builder-grid { margin-bottom: 4px; }
code { background: rgba(36,31,27,.08); padding: 2px 6px; border-radius: 8px; }

@media (max-width: 900px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .stats-grid, .quick-actions, .row, .choice-grid, .dictionary-grid, .game-grid, .diagnosis-grid { grid-template-columns: 1fr; }
  .line-import-box { align-items: flex-start; flex-direction: column; }
  .tabs { justify-content: flex-start; }
  .footer { position: static; flex-direction: column; align-items: flex-start; }
  main { padding-bottom: 34px; }
}
