:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #f3f1eb;
  color: #202329;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
}

button,
input,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

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

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: #626b75;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 5vw, 3.1rem);
  line-height: 1.05;
}

h2 {
  font-size: 1rem;
}

.top-actions,
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.primary-action,
.secondary-action,
.branch-button,
.icon-button {
  border: 1px solid #202329;
  border-radius: 7px;
  background: #202329;
  color: #fff;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 700;
}

.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: #202329;
  text-decoration: none;
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 1.25rem;
}

.branch-button {
  background: #fff;
  color: #202329;
  min-width: 64px;
  min-height: 58px;
  padding: 8px 14px;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: 1.35rem;
}

.branch-button ruby {
  ruby-position: over;
}

.branch-button rt {
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 0.56rem;
  font-weight: 700;
}

.primary-action:hover,
.icon-button:hover {
  background: #353a42;
}

.secondary-action:hover {
  background: #e7f0ed;
  border-color: #2f6f62;
  color: #21574d;
}

.branch-button:hover {
  background: #e7f0ed;
  border-color: #2f6f62;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
}

.question-panel,
.path-panel {
  border: 1px solid #d8d2c5;
  border-radius: 8px;
  background: #fffdf8;
  box-shadow: 0 12px 30px rgba(31, 35, 41, 0.08);
}

.question-panel {
  min-height: 640px;
  padding: 28px;
}

.mobile-help {
  display: none;
}

.path-panel {
  padding: 20px;
  align-self: start;
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 36px);
  overflow: auto;
}

.question-header,
.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.panel-heading span {
  color: #66717a;
  font-size: 0.86rem;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #e7f0ed;
  color: #21574d;
  font-size: 0.82rem;
  font-weight: 700;
}

.kanji-display,
.vocab-display {
  display: grid;
  place-items: center;
  min-height: 210px;
  margin-bottom: 24px;
  border: 1px solid #e3ded4;
  border-radius: 8px;
  background:
    linear-gradient(#ece7dc 1px, transparent 1px),
    linear-gradient(90deg, #ece7dc 1px, transparent 1px),
    #fbfaf6;
  background-size: 48px 48px;
  color: #171a1f;
  text-align: center;
}

.kanji-display {
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: clamp(6rem, 18vw, 12rem);
  line-height: 1;
}

.vocab-display {
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: clamp(3rem, 10vw, 7rem);
  line-height: 1.1;
  padding: 20px;
  word-break: keep-all;
}

.answer-form {
  display: grid;
  gap: 14px;
  max-width: 620px;
}

.help-panel {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  max-width: 720px;
  margin: -6px 0 20px;
  padding: 14px;
  border: 1px solid #d8d2c5;
  border-radius: 8px;
  background: #f6f3ea;
  color: #3e4650;
}

.help-panel h2 {
  margin-bottom: 6px;
  font-size: 0.95rem;
}

.help-panel p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.55;
}

.help-panel p + p {
  margin-top: 4px;
}

.help-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #2f6f62;
  color: #fff;
  font-weight: 900;
}

.mobile-help summary {
  cursor: pointer;
  font-weight: 800;
}

.mobile-help p {
  margin: 0;
}

.mobile-help p + p {
  margin-top: 5px;
}

label {
  display: grid;
  gap: 8px;
  color: #4f5863;
  font-size: 0.9rem;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid #c9c2b4;
  border-radius: 7px;
  background: #fff;
  color: #171a1f;
  padding: 0 14px;
  font-size: 1.05rem;
}

input:focus {
  outline: 3px solid rgba(47, 111, 98, 0.2);
  border-color: #2f6f62;
}

.result-panel {
  margin-top: 22px;
  padding: 18px;
  border-radius: 8px;
  border: 1px solid #d8d2c5;
  background: #faf8f1;
}

.result-panel.is-correct {
  border-color: #80b09d;
  background: #f0f7f4;
}

.result-title {
  margin-bottom: 14px;
  font-size: 1.05rem;
  font-weight: 800;
}

.meaning-row,
.branch-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  padding: 12px 0;
  border-top: 1px solid #e3ded4;
}

.meaning-row span,
.branch-row span {
  color: #626b75;
  font-size: 0.86rem;
  font-weight: 800;
}

.meaning-copy {
  display: grid;
  gap: 5px;
}

.meaning-copy strong {
  color: #202329;
}

.meaning-copy span {
  color: #626b75;
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.5;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  font-weight: 800;
}

.pill.correct {
  background: #d8efe4;
  color: #1f5d4d;
}

.pill.missing {
  background: #fff0c7;
  color: #765400;
}

.pill.extra {
  background: #f8d7da;
  color: #7b2631;
}

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

.path-list li {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 42px;
  gap: 10px;
  align-items: center;
}

.path-index {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #ece7dc;
  color: #5c6470;
  font-size: 0.78rem;
  font-weight: 800;
}

.path-node {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 7px;
  border: 1px solid #e1dace;
  background: #fff;
  color: #1d2026;
  text-align: left;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.path-node:hover,
.path-node:focus-visible {
  border-color: #2f6f62;
  outline: 2px solid rgba(47, 111, 98, 0.18);
  outline-offset: 1px;
}

.path-node.choice {
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: 1.8rem;
  line-height: 1;
  background: #e7f0ed;
}

.path-node.prompt {
  background: #f8efd9;
}

.branch-message {
  margin: 10px 0 0;
  color: #8a3a43;
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.5;
}

.retry-message {
  margin: 0;
  color: #8a3a43;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.55;
}

.path-type,
.empty-path {
  color: #66717a;
  font-size: 0.82rem;
}

.source-footer {
  display: grid;
  gap: 5px;
  margin-top: 18px;
  color: #66717a;
  font-size: 0.78rem;
  line-height: 1.5;
}

.copyright-line {
  color: #7a8189;
}

.copyright-line a {
  color: inherit;
}

.source-footer a {
  color: #2f6f62;
  font-weight: 700;
}

.empty-path {
  padding: 28px 0;
  text-align: center;
}

@media (max-width: 860px) {
  .workspace {
    width: min(100% - 20px, 1180px);
    padding: 16px 0;
  }

  .topbar,
  .question-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

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

  .question-panel {
    display: flex;
    flex-direction: column;
    min-height: auto;
    padding: 18px;
  }

  .question-order-header {
    order: 1;
  }

  .question-order-prompt {
    order: 2;
  }

  .question-order-form {
    order: 3;
  }

  .question-order-help {
    order: 4;
  }

  .question-order-result {
    order: 5;
  }

  .desktop-help {
    display: none;
  }

  .mobile-help {
    display: block;
    margin: 14px 0 0;
    border: 1px solid #d8d2c5;
    border-radius: 8px;
    background: #f6f3ea;
    color: #3e4650;
    font-size: 0.86rem;
    line-height: 1.5;
  }

  .mobile-help summary {
    padding: 12px 14px;
    color: #21574d;
    list-style-position: inside;
  }

  .mobile-help[open] summary {
    border-bottom: 1px solid #d8d2c5;
  }

  .mobile-help > div {
    padding: 12px 14px;
  }

  .prompt-display {
    min-height: 160px;
    margin-bottom: 16px;
    transition:
      min-height 160ms ease,
      font-size 160ms ease,
      box-shadow 160ms ease;
  }

  .kanji-display {
    font-size: 6rem;
  }

  .vocab-display {
    font-size: clamp(2.2rem, 13vw, 4.3rem);
    overflow-wrap: anywhere;
    word-break: normal;
  }

  .answer-form {
    scroll-margin-top: 136px;
  }

  .question-panel:focus-within .question-order-header {
    display: none;
  }

  .question-panel:focus-within .prompt-display {
    position: sticky;
    z-index: 4;
    top: 8px;
    min-height: 112px;
    margin-bottom: 12px;
    box-shadow: 0 8px 20px rgba(31, 35, 41, 0.14);
  }

  .question-panel:focus-within .kanji-display {
    font-size: 4.8rem;
  }

  .question-panel:focus-within .vocab-display {
    font-size: clamp(1.7rem, 9vw, 3rem);
    padding: 12px;
  }

  .path-panel {
    position: static;
    max-height: none;
  }

  .meaning-row,
  .branch-row {
    grid-template-columns: 1fr;
  }
}
