:root {
  --bg: #f2eadb;
  --surface: #fffaf0;
  --ink: #17201c;
  --muted: #6a756f;
  --line: #dacdb7;
  --teal: #176b5c;
  --teal-dark: #0e4d44;
  --coral: #e05d3f;
  --amber: #e9a63a;
  --mint: #dcecdf;
  --shadow: 0 24px 70px rgba(64, 46, 22, 0.13);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    linear-gradient(135deg, rgba(23, 107, 92, 0.12), transparent 35%),
    linear-gradient(315deg, rgba(224, 93, 63, 0.12), transparent 35%),
    var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: "Fraunces", "Noto Serif SC", "Source Han Serif SC", Georgia, serif;
}

button,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  max-width: 1440px;
  margin: 0 auto 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 18px;
  background: var(--coral);
  color: white;
  font-size: 1.6rem;
  font-weight: 900;
  box-shadow: 6px 6px 0 var(--ink);
}

.brand strong {
  display: block;
  font-size: clamp(1.35rem, 2.5vw, 1.9rem);
  letter-spacing: -0.04em;
}

.brand small,
.eyebrow,
label,
.button,
.stats,
.mini-list,
.hint,
.toast,
.recorder-display {
  font-family: "Aptos", "Segoe UI", sans-serif;
}

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

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.language-switch {
  display: inline-flex;
  gap: 4px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 250, 240, 0.78);
  font-family: "Aptos", "Segoe UI", sans-serif;
}

.language-switch button {
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.language-switch button.active {
  background: var(--ink);
  color: white;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.stats > span {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 250, 240, 0.72);
}

.stats > span > span {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.stats b {
  margin-right: 4px;
  font-size: 1.1rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(230px, 300px) minmax(0, 1fr) minmax(240px, 320px);
  gap: 18px;
  max-width: 1440px;
  margin: 0 auto;
}

.panel,
.stage {
  border: 1px solid rgba(23, 32, 28, 0.1);
  border-radius: 30px;
  background: rgba(255, 250, 240, 0.88);
  box-shadow: var(--shadow);
}

.panel {
  padding: 20px;
}

.stage {
  padding: clamp(22px, 4vw, 42px);
  background:
    linear-gradient(150deg, rgba(255, 255, 255, 0.95), rgba(255, 250, 240, 0.82)),
    repeating-linear-gradient(0deg, transparent, transparent 31px, rgba(23, 32, 28, 0.045) 32px);
}

.side {
  display: grid;
  gap: 18px;
  align-content: start;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--teal);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  letter-spacing: -0.045em;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2.2rem, 5vw, 4.8rem);
  line-height: 0.94;
}

h2 {
  margin-bottom: 16px;
}

.topic-list,
.mini-list,
.controls {
  display: grid;
  gap: 10px;
}

.topic-button,
.mini-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.64);
  color: var(--ink);
  text-align: left;
}

.topic-button {
  padding: 14px;
}

.topic-button.active {
  border-color: var(--ink);
  background: var(--mint);
  box-shadow: 4px 4px 0 var(--ink);
}

.topic-button strong,
.topic-button span,
.mini-item strong,
.mini-item span {
  display: block;
}

.topic-button span,
.mini-item span {
  color: var(--muted);
  font-family: "Aptos", "Segoe UI", sans-serif;
  font-size: 0.84rem;
  line-height: 1.45;
}

.controls {
  margin-top: 18px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 900;
}

select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: white;
  color: var(--ink);
  outline: none;
}

select {
  min-height: 48px;
  padding: 0 14px;
}

textarea {
  resize: vertical;
  min-height: 120px;
  padding: 14px;
  line-height: 1.55;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  font-weight: 900;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.button:not(:disabled):hover {
  transform: translateY(-1px);
}

.button.loading {
  opacity: 1;
}

.button.loading::before {
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  content: "";
  animation: spin 760ms linear infinite;
}

.primary {
  background: var(--teal);
  color: white;
  box-shadow: 4px 4px 0 var(--ink);
}

.secondary {
  background: var(--amber);
  color: var(--ink);
}

.ghost {
  background: white;
  color: var(--ink);
}

.danger {
  background: #fff;
  color: #9b2f1d;
  border-color: #9b2f1d;
}

.record {
  background: var(--coral);
  color: white;
  box-shadow: 4px 4px 0 var(--ink);
}

.stage-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.prompt-card {
  margin: clamp(26px, 5vw, 54px) 0 18px;
  padding: clamp(22px, 4vw, 34px);
  border: 2px solid var(--ink);
  border-radius: 24px;
  background: white;
  box-shadow: 10px 10px 0 var(--ink);
}

#promptText {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.3rem);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -0.05em;
}

.hint {
  margin-top: 18px;
  padding: 12px 14px;
  border-radius: 16px;
  background: #fff3cf;
  color: #6f4610;
}

.recorder,
.debug-box,
.feedback-panel {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid rgba(23, 32, 28, 0.1);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.62);
}

.recorder-display {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.record-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
}

.record-dot.live {
  background: var(--coral);
  box-shadow: 0 0 0 8px rgba(224, 93, 63, 0.14);
}

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

#audioPreview {
  width: 100%;
  margin-top: 14px;
}

.debug-box summary {
  cursor: pointer;
  font-family: "Aptos", "Segoe UI", sans-serif;
  font-weight: 900;
}

.debug-box textarea {
  margin: 12px 0;
}

.feedback-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 16px;
  align-items: center;
}

.feedback-panel.good,
.feedback-panel.easy {
  background: rgba(220, 236, 223, 0.95);
}

.feedback-panel.hard {
  background: rgba(255, 243, 207, 0.96);
}

.feedback-panel.again {
  background: rgba(224, 93, 63, 0.13);
}

.feedback-panel.loading {
  background:
    linear-gradient(120deg, rgba(220, 236, 223, 0.92), rgba(255, 243, 207, 0.9));
}

.score {
  display: grid;
  width: 82px;
  height: 82px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: white;
  font-size: 1.45rem;
  font-weight: 900;
  box-shadow: 5px 5px 0 var(--ink);
}

.loading-score::before {
  width: 38px;
  height: 38px;
  border: 4px solid rgba(23, 32, 28, 0.2);
  border-top-color: var(--teal);
  border-radius: 50%;
  content: "";
  animation: spin 850ms linear infinite;
}

.feedback-panel h2,
.feedback-panel p {
  margin-bottom: 8px;
}

.feedback-panel p {
  color: var(--muted);
  font-family: "Aptos", "Segoe UI", sans-serif;
  line-height: 1.55;
}

.feedback-panel .reading {
  color: var(--teal-dark);
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
  font-size: 1.05rem;
}

.mini-item {
  padding: 12px 13px;
}

.mini-empty {
  color: var(--muted);
  font-family: "Aptos", "Segoe UI", sans-serif;
}

.beta-note,
.privacy-panel p {
  color: var(--muted);
  font-family: "Aptos", "Segoe UI", sans-serif;
  line-height: 1.55;
}

.beta-note {
  margin-top: 18px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  background: rgba(255, 243, 207, 0.58);
}

.beta-note strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
}

.beta-note p,
.privacy-panel p {
  margin-bottom: 0;
}

.privacy-panel .button {
  width: 100%;
  margin-top: 14px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: min(420px, calc(100vw - 48px));
  padding: 14px 16px;
  border: 1px solid var(--ink);
  border-radius: 18px;
  background: var(--ink);
  color: white;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

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

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 250px minmax(0, 1fr);
  }

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

@media (max-width: 760px) {
  .app-shell {
    padding: 16px;
  }

  .topbar,
  .stage-head {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-right {
    align-items: stretch;
  }

  .language-switch {
    align-self: flex-start;
  }

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

  .stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stage {
    padding: 20px;
  }

  .prompt-card {
    box-shadow: 6px 6px 0 var(--ink);
  }

  .feedback-panel {
    grid-template-columns: 1fr;
  }
}
