:root {
  color-scheme: light;
  --ink: #171717;
  --muted: #5f6368;
  --line: #d8d2c7;
  --paper: #f7f3ea;
  --panel: #fffdf8;
  --red: #bf2b2b;
  --red-dark: #8d1f24;
  --blue: #245f8f;
  --green: #27765c;
  --gold: #d99b2b;
  --shadow: 0 24px 60px rgba(30, 28, 24, 0.16);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  background:
    linear-gradient(90deg, rgba(36, 95, 143, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(191, 43, 43, 0.08) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  color: var(--ink);
}

button {
  font: inherit;
}

.app {
  width: min(1120px, calc(100vw - 32px));
  min-height: 100svh;
  margin: 0 auto;
  padding: 32px 0;
  display: grid;
  place-items: center;
}

.start-view,
.quiz-shell,
.result-view {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.start-view {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(0, 1.2fr);
  min-height: min(640px, calc(100svh - 64px));
}

.start-art {
  background: #050713;
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.start-panel {
  padding: clamp(28px, 5vw, 56px);
  display: grid;
  align-content: center;
}

.course-grid {
  display: grid;
  gap: 14px;
  margin-top: 28px;
}

.start-summary {
  max-width: 34rem;
  margin: 16px 0 0;
  color: #303236;
  font-size: 1.05rem;
  line-height: 1.8;
}

.course-button {
  min-height: 84px;
  padding: 18px 20px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.course-button:hover,
.course-button:focus-visible {
  border-color: var(--blue);
  background: #e9f2fa;
  outline: none;
  transform: translateY(-1px);
}

.course-button strong,
.course-button span {
  display: block;
}

.course-button strong {
  margin-bottom: 6px;
  font-size: 1.35rem;
}

.course-button span {
  color: var(--muted);
  font-weight: 700;
}

.share-button {
  width: min(220px, 100%);
  min-height: 44px;
  margin-top: 18px;
  border: 1px solid #8b2f2a;
  border-radius: 8px;
  background: #a33a32;
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

.share-button:hover,
.share-button:focus-visible {
  background: #7f2825;
  outline: none;
}

.topbar,
.controls,
.result-header {
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--red-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.6rem, 4vw, 2.75rem);
  line-height: 1.08;
}

.scoreboard {
  min-width: 136px;
  display: grid;
  gap: 5px;
  text-align: right;
  color: var(--muted);
}

.scoreboard strong {
  color: var(--ink);
  font-size: 1.45rem;
}

.stage {
  display: grid;
  grid-template-columns: minmax(220px, 0.75fr) minmax(0, 1.25fr);
  min-height: min(500px, calc(100svh - 170px));
}

.console-art {
  background: #050713;
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.quiz-picture,
.quiz-art {
  width: 100%;
  height: 100%;
  display: block;
}

.quiz-art {
  object-fit: cover;
  object-position: center;
}

.question-panel {
  padding: clamp(24px, 5vw, 48px);
  display: grid;
  align-content: center;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.meta-row span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  color: var(--muted);
  background: #fbf7ee;
  font-size: 0.9rem;
}

.question-panel h2,
.result-header h2 {
  margin-bottom: 14px;
  font-size: clamp(1.4rem, 3vw, 2.2rem);
  line-height: 1.2;
}

#descriptionText,
#resultMessage {
  color: #303236;
  font-size: 1.05rem;
  line-height: 1.8;
}

.choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 26px;
}

.choice-button {
  min-height: 68px;
  padding: 14px 16px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.choice-button:hover:not(:disabled),
.choice-button:focus-visible {
  border-color: var(--blue);
  transform: translateY(-1px);
  outline: none;
}

.choice-button.selected {
  border-color: var(--blue);
  background: #e9f2fa;
  box-shadow: inset 0 0 0 2px rgba(36, 95, 143, 0.18);
}

.choice-button.correct {
  border-color: var(--green);
  background: #e9f6ef;
}

.choice-button.wrong {
  border-color: var(--red);
  background: #faeaea;
}

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

.answer-button {
  width: min(220px, 100%);
  margin-top: 14px;
  justify-self: end;
}

.feedback {
  min-height: 32px;
  margin: 18px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.answer-popup {
  position: fixed;
  z-index: 20;
  top: 50%;
  left: 50%;
  min-width: min(300px, calc(100vw - 48px));
  padding: 22px 28px;
  border: 4px solid #fff;
  border-radius: 8px;
  color: #fff;
  font-size: clamp(2rem, 8vw, 4rem);
  font-weight: 900;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.86);
  transition: opacity 140ms ease, transform 180ms ease;
}

.answer-popup.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.answer-popup.correct {
  background: var(--green);
}

.answer-popup.wrong {
  background: var(--red);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
  border-top: 1px solid var(--line);
}

.primary-button,
.ghost-button {
  min-height: 44px;
  border-radius: 8px;
  padding: 0 18px;
  border: 1px solid transparent;
  font-weight: 800;
  cursor: pointer;
}

.primary-button {
  background: var(--red);
  color: white;
}

.controls #nextButton {
  background: var(--blue);
}

.primary-button:disabled {
  background: #b9b1a5;
  cursor: default;
}

.controls #nextButton:disabled {
  background: #b9b1a5;
}

.ghost-button {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.result-view {
  padding-bottom: 24px;
}

.result-header {
  border-bottom: 1px solid var(--line);
}

.review-list {
  display: grid;
  gap: 12px;
  padding: 24px;
}

.review-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
}

.review-item strong {
  display: block;
  margin-bottom: 6px;
}

.review-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.result-view .primary-button {
  margin-left: 24px;
}

@media (max-width: 980px) {
  .app {
    width: min(100vw - 24px, 860px);
    padding: 20px 0;
  }

  .topbar,
  .controls,
  .result-header {
    padding: 20px;
  }

  .start-view {
    grid-template-columns: minmax(220px, 0.75fr) minmax(0, 1.25fr);
    min-height: auto;
  }

  .start-panel {
    padding: 34px;
  }

  .stage {
    grid-template-columns: minmax(180px, 0.65fr) minmax(0, 1.35fr);
    min-height: auto;
  }

  .question-panel {
    padding: 28px;
  }

  .choices {
    gap: 10px;
  }
}

@media (min-width: 761px) and (max-height: 850px) {
  .app {
    padding: 10px 0;
  }

  .topbar,
  .controls,
  .result-header {
    padding: 16px 20px;
  }

  .start-view {
    min-height: calc(100svh - 20px);
  }

  .start-panel {
    padding: 28px 34px;
  }

  .course-grid {
    gap: 10px;
    margin-top: 22px;
  }

  .course-button {
    min-height: 72px;
    padding: 14px 16px;
  }

  h1 {
    font-size: clamp(1.55rem, 3vw, 2.15rem);
  }

  .stage {
    min-height: auto;
  }

  .question-panel {
    padding: 24px 32px;
  }

  .question-panel h2,
  .result-header h2 {
    font-size: clamp(1.3rem, 2.6vw, 1.85rem);
  }

  #descriptionText,
  #resultMessage {
    font-size: 1rem;
    line-height: 1.65;
  }

  .choices {
    margin-top: 18px;
  }

  .choice-button {
    min-height: 58px;
    padding: 12px 14px;
  }

  .answer-button {
    margin-top: 12px;
  }

  .feedback {
    margin-top: 14px;
  }
}

@media (max-width: 760px) {
  .app {
    width: min(100vw - 20px, 540px);
    padding: 10px 0;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
  }

  .start-view {
    grid-template-columns: 1fr;
  }

  .start-art {
    height: 230px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .start-panel {
    padding: 28px 22px;
  }

  .scoreboard {
    width: 100%;
    grid-template-columns: 1fr auto;
    align-items: end;
    text-align: left;
  }

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

  .console-art {
    height: 210px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .quiz-art {
    object-position: center 42%;
  }

  .choices {
    grid-template-columns: 1fr;
    margin-top: 20px;
  }

  .choice-button {
    min-height: 56px;
    padding: 13px 14px;
  }

  .answer-button {
    width: 100%;
  }

  .controls {
    justify-content: stretch;
    flex-direction: column;
  }

  .controls button,
  .result-view .primary-button {
    width: 100%;
  }

  .result-view .primary-button {
    margin: 0 24px;
    width: calc(100% - 48px);
  }
}

@media (max-width: 420px) {
  .app {
    width: 100%;
    padding: 0;
  }

  .start-view,
  .quiz-shell,
  .result-view {
    min-height: 100svh;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .topbar,
  .controls,
  .result-header,
  .review-list {
    padding: 18px;
  }

  .start-art {
    height: 190px;
  }

  .start-panel {
    padding: 22px 18px;
  }

  .course-button {
    min-height: 72px;
  }

  .console-art {
    height: 172px;
  }

  .question-panel {
    padding: 22px 18px;
  }

  #descriptionText,
  #resultMessage {
    font-size: 1rem;
    line-height: 1.72;
  }

  .controls {
    position: sticky;
    bottom: 0;
    background: var(--panel);
  }
}
