:root {
  color-scheme: light;
  --bg: #f7f3ea;
  --panel: #fffdf8;
  --text: #22302d;
  --muted: #68756f;
  --line: #ded7c9;
  --primary: #1f7a70;
  --primary-dark: #155f57;
  --accent: #d86e49;
  --good: #2f7d4d;
  --bad: #b94b45;
  --shadow: 0 18px 36px rgba(44, 36, 26, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(31, 122, 112, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(216, 110, 73, 0.14), transparent 40%),
    var(--bg);
  color: var(--text);
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Hiragino Sans",
    "Yu Gothic",
    "Meiryo",
    sans-serif;
}

button {
  font: inherit;
}

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

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary-dark);
  font-size: 0.94rem;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1.08;
  letter-spacing: 0;
}

.score {
  min-width: 92px;
  padding: 10px 14px;
  border: 2px solid rgba(31, 122, 112, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--primary-dark);
  font-size: 1.16rem;
  font-weight: 900;
  text-align: center;
}

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

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(96px, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.mode-button,
.small-button {
  min-height: 46px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 900;
}

.mode-button {
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
}

.mode-button.is-active {
  background: var(--primary);
  color: #fff;
}

.small-button {
  padding: 0 18px;
  border: 1px solid rgba(31, 122, 112, 0.2);
  background: var(--panel);
  color: var(--primary-dark);
  box-shadow: 0 8px 18px rgba(44, 36, 26, 0.08);
}

.length-filter {
  position: relative;
}

.length-panel {
  position: absolute;
  z-index: 5;
  top: calc(100% + 8px);
  left: 0;
  width: min(360px, calc(100vw - 28px));
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.length-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(82px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.length-button,
.length-reset {
  min-height: 44px;
  border: 2px solid rgba(31, 122, 112, 0.18);
  border-radius: 6px;
  background: #fff;
  color: var(--primary-dark);
  cursor: pointer;
  font-weight: 900;
}

.length-button.is-active {
  border-color: var(--primary);
  background: rgba(31, 122, 112, 0.12);
}

.length-reset {
  width: 100%;
}

.question-area {
  display: grid;
  grid-template-columns: minmax(240px, 430px) 1fr;
  gap: 18px;
  align-items: stretch;
}

.picture-wrap,
.prompt-wrap,
.answer-area,
.feedback {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
}

.picture-wrap {
  display: grid;
  place-items: center;
  min-height: 360px;
  padding: 16px;
}

.picture {
  width: min(100%, 330px);
  aspect-ratio: 1;
  object-fit: contain;
  display: block;
}

.prompt-wrap {
  display: grid;
  align-content: center;
  gap: 12px;
  min-height: 360px;
  padding: clamp(20px, 4vw, 34px);
}

.word-label {
  margin: 0;
  color: var(--primary-dark);
  font-size: clamp(2.1rem, 7vw, 5rem);
  line-height: 1.05;
  font-weight: 900;
  letter-spacing: 0;
}

.prompt {
  margin: 0;
  color: var(--text);
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  line-height: 1.3;
  font-weight: 900;
  letter-spacing: 0;
}

.answer-area {
  margin-top: 14px;
  min-height: 158px;
  padding: 16px;
}

.kana-row,
.choice-grid {
  display: grid;
  gap: 10px;
}

.kana-row {
  grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
}

.choice-grid {
  grid-template-columns: repeat(4, minmax(86px, 1fr));
}

.answer-button {
  min-height: 86px;
  border: 2px solid rgba(31, 122, 112, 0.22);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: clamp(2rem, 7vw, 3.7rem);
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(44, 36, 26, 0.08);
}

.answer-button:focus-visible,
.small-button:focus-visible,
.mode-button:focus-visible,
.length-button:focus-visible,
.length-reset:focus-visible {
  outline: 4px solid rgba(216, 110, 73, 0.35);
  outline-offset: 2px;
}

.answer-button.is-correct {
  border-color: rgba(47, 125, 77, 0.8);
  background: rgba(47, 125, 77, 0.12);
  color: var(--good);
}

.answer-button.is-wrong {
  border-color: rgba(185, 75, 69, 0.75);
  background: rgba(185, 75, 69, 0.1);
  color: var(--bad);
}

.answer-button:disabled {
  cursor: default;
}

.feedback {
  min-height: 62px;
  margin-top: 14px;
  padding: 14px 18px;
  color: var(--primary-dark);
  font-size: clamp(1.1rem, 3.5vw, 1.6rem);
  font-weight: 900;
  text-align: center;
}

.is-hidden {
  display: none;
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1040px);
    padding-top: 16px;
  }

  .topbar {
    align-items: flex-start;
  }

  .question-area {
    grid-template-columns: 1fr;
  }

  .picture-wrap,
  .prompt-wrap {
    min-height: auto;
  }

  .picture {
    width: min(100%, 260px);
  }

  .choice-grid {
    grid-template-columns: repeat(2, minmax(108px, 1fr));
  }

  .answer-button {
    min-height: 78px;
  }

  .length-filter {
    width: 100%;
  }

  .length-filter .small-button {
    width: 100%;
  }

  .length-panel {
    left: 0;
    right: 0;
    width: 100%;
  }
}

/* LiNest v3: 問題画像と正誤色を保ち、練習カードの外観を統一する。 */
body.linest-themed {
  --bg: var(--linest-bg);
  --panel: var(--linest-surface);
  --text: var(--linest-text);
  --muted: var(--linest-muted);
  --line: var(--linest-border);
  --primary: var(--linest-green);
  --primary-dark: var(--linest-green-dark);
  --accent: var(--linest-warm);
  --shadow: var(--linest-shadow);
}

body.linest-themed .topbar {
  padding: 16px 18px;
  border: 1px solid var(--linest-border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--linest-shadow);
}

body.linest-themed :where(.controls, .picture-wrap, .prompt-wrap, .answer-area, .feedback, .length-panel) {
  border-color: var(--linest-border);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--linest-shadow);
}

body.linest-themed .controls {
  padding: 10px;
  border: 1px solid var(--linest-border);
  border-radius: 8px;
}

body.linest-themed :where(.segmented, .small-button, .length-button, .length-reset, .answer-button) {
  border-color: var(--linest-border);
  background-color: #ffffff;
  color: var(--linest-text);
}

body.linest-themed :where(.mode-button.is-active, .length-button.is-active) {
  border-color: var(--linest-green);
  background: var(--linest-green);
  color: #ffffff;
}

@media (max-width: 760px) {
  body.linest-themed .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }
}

@media (max-width: 430px) {
  body.linest-themed .app-shell {
    width: min(100% - 16px, 1040px);
  }

  body.linest-themed .topbar {
    grid-template-columns: 1fr;
  }

  body.linest-themed .score {
    justify-self: start;
  }

  body.linest-themed :where(.mode-button, .small-button, .length-button, .length-reset) {
    min-width: 0;
    padding-inline: 8px;
    white-space: normal;
    word-break: keep-all;
  }

  body.linest-themed .length-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
