:root {
  color-scheme: light;
  --ink: #24211d;
  --muted: #736d64;
  --paper: #fffdf7;
  --paper-deep: #f5efe2;
  --line: #c9bdab;
  --accent: #a52a2a;
  --accent-dark: #772020;
  --gold: #a67c35;
  --correct: #b8205b;
  --near: #b86314;
  --wrong: #1f477e;
  --shadow: 0 22px 70px rgb(59 42 25 / 14%);
  font-family:
    "Yu Mincho", "Hiragino Mincho ProN", "Hiragino Mincho Pro",
    "Noto Serif JP", serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    radial-gradient(circle at 20% 0%, rgb(255 255 255 / 75%), transparent 34%),
    linear-gradient(135deg, #eee5d6, #f8f3e8 50%, #e9dfcf);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    repeating-linear-gradient(
      0deg,
      rgb(100 78 49 / 2%) 0,
      rgb(100 78 49 / 2%) 1px,
      transparent 1px,
      transparent 5px
    );
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgb(165 42 42 / 35%);
  outline-offset: 3px;
}

img {
  display: block;
  max-width: 100%;
}

#app {
  width: min(100%, 1080px);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(16px, 3vw, 34px);
}

.loading {
  display: grid;
  min-height: 75vh;
  place-items: center;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.paper {
  position: relative;
  min-height: calc(100vh - clamp(32px, 6vw, 68px));
  overflow: hidden;
  border: 1px solid rgb(114 93 67 / 28%);
  background:
    linear-gradient(rgb(255 253 247 / 96%), rgb(255 253 247 / 96%)),
    repeating-linear-gradient(
      90deg,
      transparent 0,
      transparent 22px,
      rgb(96 75 46 / 3%) 23px
    );
  box-shadow: var(--shadow);
}

.paper::before,
.paper::after {
  position: absolute;
  z-index: 0;
  width: 76px;
  height: 76px;
  border-color: rgb(166 124 53 / 42%);
  content: "";
  pointer-events: none;
}

.paper::before {
  top: 12px;
  left: 12px;
  border-top: 1px solid;
  border-left: 1px solid;
}

.paper::after {
  right: 12px;
  bottom: 12px;
  border-right: 1px solid;
  border-bottom: 1px solid;
}

.page {
  position: relative;
  z-index: 1;
  width: min(100%, 900px);
  margin: 0 auto;
  padding: clamp(34px, 7vw, 78px) clamp(20px, 6vw, 68px);
  text-align: center;
}

.site-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  color: var(--accent);
  font-size: 0.78rem;
  letter-spacing: 0.28em;
}

.site-mark::before,
.site-mark::after {
  width: 34px;
  height: 1px;
  background: currentColor;
  content: "";
}

.hero-title {
  margin: 0;
  font-size: clamp(3rem, 10vw, 6.7rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1.05;
}

.hero-subtitle {
  margin: 24px 0 0;
  color: var(--muted);
  font-size: clamp(0.95rem, 2.5vw, 1.15rem);
  letter-spacing: 0.08em;
}

.edition {
  display: inline-block;
  margin-top: 18px;
  padding: 4px 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.18em;
}

.grade-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: clamp(50px, 9vw, 88px) 0 0;
}

.grade-button {
  position: relative;
  min-height: 150px;
  padding: 26px 12px 20px;
  border: 1px solid var(--ink);
  border-radius: 0;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  transition:
    color 160ms ease,
    background 160ms ease,
    transform 160ms ease,
    box-shadow 160ms ease;
}

.grade-button::before {
  position: absolute;
  inset: 6px;
  border: 1px solid rgb(36 33 29 / 28%);
  content: "";
  pointer-events: none;
}

.grade-button:hover {
  color: var(--paper);
  background: var(--ink);
  box-shadow: 7px 7px 0 rgb(165 42 42 / 18%);
  transform: translate(-2px, -2px);
}

.grade-label {
  display: block;
  font-size: clamp(1.7rem, 5vw, 2.4rem);
  font-weight: 700;
  letter-spacing: 0.12em;
}

.grade-time {
  display: block;
  margin-top: 14px;
  color: currentColor;
  font-size: 0.78rem;
  opacity: 0.7;
}

.history {
  width: min(100%, 620px);
  margin: 74px auto 0;
  padding-top: 26px;
  border-top: 1px solid var(--line);
}

.history-title {
  margin: 0 0 18px;
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0.18em;
}

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

.history-link {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 4px;
  border-bottom: 1px dotted var(--line);
  color: var(--ink);
  text-decoration: none;
}

.history-link:hover {
  color: var(--accent);
}

.text-button {
  margin-top: 22px;
  padding: 8px 2px;
  border: 0;
  border-bottom: 1px solid currentColor;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 0.8rem;
}

.exam-progress {
  display: grid;
  grid-template-columns: repeat(var(--question-count), 1fr);
  margin: -1px -1px 0;
  border-bottom: 1px solid var(--line);
}

.progress-cell {
  min-width: 0;
  padding: 8px 2px 7px;
  border-right: 1px solid var(--line);
  color: #a29a8f;
  background: var(--paper-deep);
  font-size: 0.72rem;
}

.progress-cell:last-child {
  border-right: 0;
}

.progress-cell.is-current {
  color: var(--paper);
  background: var(--accent);
}

.progress-cell.is-complete {
  color: var(--ink);
  background: #e8ddca;
}

.exam-heading {
  margin: 0;
  font-size: clamp(2.2rem, 7vw, 4rem);
  letter-spacing: 0.12em;
}

.exam-heading-sub {
  display: block;
  margin-top: 8px;
  color: var(--accent);
  font-size: 0.52em;
}

.candidate-number {
  width: min(100%, 520px);
  margin: 34px auto 0;
  padding: 22px;
  border: 4px double var(--ink);
  background: rgb(255 255 255 / 50%);
}

.candidate-number strong {
  display: block;
  margin: 12px 0 8px;
  color: var(--accent);
  font-size: clamp(2rem, 7vw, 3.2rem);
  letter-spacing: 0.16em;
}

.notice {
  width: min(100%, 720px);
  margin: 42px auto;
  padding: 24px clamp(20px, 5vw, 36px);
  border: 1px solid var(--line);
  text-align: left;
}

.notice h2 {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0.12em;
}

.notice ul {
  margin: 0;
  padding-left: 1.4em;
  color: #4d4841;
  font-size: 0.9rem;
  line-height: 2;
}

.primary-button,
.answer-button {
  min-width: 190px;
  padding: 15px 30px;
  border: 1px solid var(--ink);
  color: var(--paper);
  background: var(--ink);
  cursor: pointer;
  letter-spacing: 0.14em;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.primary-button:hover,
.answer-button:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent);
  transform: translateY(-2px);
}

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

.answer-button:disabled {
  border-color: #b8b1a8;
  color: #aaa39b;
  background: transparent;
  cursor: not-allowed;
}

.section-cover {
  display: grid;
  min-height: 66vh;
  place-items: center;
}

.section-kicker {
  color: var(--accent);
  font-size: 0.82rem;
  letter-spacing: 0.28em;
}

.section-title {
  margin: 10px 0 44px;
  font-size: clamp(2.6rem, 9vw, 5rem);
  letter-spacing: 0.12em;
}

.problem-title {
  margin: 0;
  font-size: clamp(1.9rem, 6vw, 3.2rem);
  letter-spacing: 0.1em;
}

.phase-nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(100%, 620px);
  margin: 26px auto 36px;
  padding: 6px;
  border: 1px solid var(--line);
}

.phase-step {
  padding: 10px 6px;
  color: #aaa198;
  font-size: 0.72rem;
}

.phase-step.is-active {
  color: var(--paper);
  background: var(--accent);
}

.memory-stage {
  min-height: 360px;
}

.timer {
  --progress: 0deg;
  display: grid;
  width: 116px;
  height: 116px;
  margin: 30px auto;
  border-radius: 50%;
  background: conic-gradient(
    var(--accent) var(--progress),
    var(--paper-deep) var(--progress)
  );
  place-items: center;
}

.timer-inner {
  display: grid;
  width: 92px;
  height: 92px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
  place-items: center;
}

.timer-seconds {
  display: block;
  font-size: 2rem;
  line-height: 1;
}

.timer-label {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.64rem;
  letter-spacing: 0.12em;
}

.skip-button {
  padding: 8px 2px;
  border: 0;
  border-bottom: 1px solid var(--ink);
  color: var(--ink);
  background: transparent;
  cursor: pointer;
}

.face-grid,
.figure-grid,
.color-grid,
.option-grid,
.space-item-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.face-card,
.figure-card,
.color-card,
.space-item-card {
  position: relative;
  border: 1px solid var(--line);
  background: #fff;
}

.face-card {
  width: min(160px, 30vw);
  padding: 0;
}

.face-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.figure-card {
  width: 102px;
  padding: 10px;
}

.figure-card img {
  width: 80px;
  height: 80px;
  object-fit: contain;
}

.color-card {
  width: 112px;
  height: 112px;
}

.color-card span {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: end center;
  padding: 6px;
  color: rgb(255 255 255 / 85%);
  font: 0.68rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-shadow: 0 1px 3px #000;
}

button.face-card,
button.figure-card,
button.color-card,
button.space-item-card {
  padding: 0;
  cursor: pointer;
}

.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(165 42 42 / 20%);
}

.is-selected::after {
  position: absolute;
  top: 5px;
  right: 5px;
  display: grid;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: #fff;
  background: var(--accent);
  content: "✓";
  font-family: system-ui, sans-serif;
  font-weight: 700;
  place-items: center;
}

.word-table,
.profile-table,
.result-table {
  width: min(100%, 640px);
  margin: 0 auto;
  border-collapse: collapse;
}

.word-table {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.word-table td {
  padding: 8px 10px;
}

.word-table td:first-child {
  width: 45%;
  text-align: right;
}

.word-table td:nth-child(2) {
  width: 10%;
  color: var(--muted);
}

.word-table td:last-child {
  width: 45%;
  text-align: left;
}

.profile-table tr {
  border-bottom: 1px solid var(--line);
}

.profile-table td {
  padding: 10px;
  text-align: left;
  vertical-align: middle;
}

.profile-table td:first-child {
  width: 110px;
}

.profile-table img {
  width: 90px;
  height: 90px;
  object-fit: cover;
}

.profile-name {
  font-size: 1.1rem;
}

.profile-detail {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.number-plate {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  margin: 8px;
  padding: 9px 14px;
  border: 4px double var(--ink);
  border-radius: 4px;
  background: #fff;
  font-family: "Yu Gothic", sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
}

.number-plate-char {
  font-size: 0.72em;
}

.space-scene {
  width: min(100%, 600px);
  margin: 0 auto;
  border: 1px solid var(--line);
}

.space-item-card {
  width: 96px;
  border-radius: 9px;
  overflow: hidden;
}

.space-item-card img {
  width: 94px;
  height: 94px;
  object-fit: cover;
}

.question-desc {
  margin: 26px auto;
  font-size: clamp(1.05rem, 3vw, 1.32rem);
  line-height: 1.8;
}

.input-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.exam-input,
.exam-select {
  min-height: 52px;
  padding: 10px 13px;
  border: 1px solid var(--ink);
  border-radius: 0;
  color: var(--ink);
  background: #fff;
  text-align: center;
}

.exam-input {
  width: min(100%, 300px);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.answer-face {
  width: 150px;
  margin: 0 auto 22px;
  border: 1px solid var(--line);
}

.result-header {
  cursor: pointer;
}

.result-title {
  margin: 0;
  font-size: clamp(2.2rem, 7vw, 4.2rem);
  letter-spacing: 0.08em;
}

.certificate {
  width: min(100%, 800px);
  margin: 30px auto 20px;
  border: 1px solid var(--line);
  box-shadow: 0 14px 40px rgb(43 32 21 / 12%);
}

.share-button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 11px 22px;
  border-radius: 5px;
  color: #fff;
  background: #111;
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
}

.result-section-heading {
  width: min(100%, 800px);
  margin: 58px auto 34px;
  padding: 12px;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  font-size: 1.3rem;
  font-weight: 400;
  letter-spacing: 0.2em;
}

.result-question {
  width: min(100%, 820px);
  margin: 0 auto 64px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}

.result-question-title {
  margin: 0 0 24px;
  font-size: clamp(1.6rem, 5vw, 2.3rem);
  letter-spacing: 0.08em;
}

.result-memory {
  margin-bottom: 34px;
  padding: 20px;
  background: var(--paper-deep);
}

.result-subquestion {
  margin-top: 34px;
}

.result-table {
  table-layout: fixed;
}

.result-table th,
.result-table td {
  width: 50%;
  padding: 12px;
  border: 1px solid var(--line);
  overflow-wrap: anywhere;
}

.result-table th {
  background: var(--paper-deep);
  font-size: 0.78rem;
  font-weight: 400;
  letter-spacing: 0.12em;
}

.result-table .face-card,
.result-table .figure-card,
.result-table .color-card,
.result-table .space-item-card {
  margin: 0 auto;
}

.result-badge {
  display: inline-block;
  margin-top: 12px;
  font-weight: 700;
}

.result-badge.is-correct {
  color: var(--correct);
}

.result-badge.is-near {
  color: var(--near);
}

.result-badge.is-wrong {
  color: var(--wrong);
}

.credits {
  margin-top: 70px;
  color: var(--muted);
  font-size: 0.72rem;
}

.credits a {
  color: inherit;
}

.error-panel {
  width: min(100%, 620px);
  margin: 30px auto;
  padding: 24px;
  border: 1px solid var(--accent);
  color: var(--accent-dark);
  background: #fff7f4;
  text-align: left;
  line-height: 1.8;
}

.qa-badge {
  position: fixed;
  z-index: 10;
  right: 10px;
  bottom: 10px;
  padding: 5px 8px;
  color: #fff;
  background: #5a3484;
  font: 0.7rem/1.2 system-ui, sans-serif;
}

@media (max-width: 720px) {
  #app {
    padding: 0;
  }

  .paper {
    min-height: 100vh;
    border: 0;
    box-shadow: none;
  }

  .page {
    padding: 44px 18px 62px;
  }

  .grade-list {
    grid-template-columns: 1fr;
    width: min(100%, 360px);
    margin-right: auto;
    margin-left: auto;
  }

  .grade-button {
    min-height: 104px;
  }

  .history-link {
    display: grid;
    text-align: left;
  }

  .progress-cell {
    font-size: 0.62rem;
  }

  .phase-nav {
    gap: 2px;
  }

  .phase-step {
    padding: 9px 3px;
    font-size: 0.62rem;
  }

  .face-card {
    width: min(140px, 40vw);
  }

  .figure-card {
    width: 88px;
  }

  .figure-card img {
    width: 66px;
    height: 66px;
  }

  .color-card {
    width: 90px;
    height: 90px;
  }

  .space-item-card {
    width: 76px;
  }

  .space-item-card img {
    width: 74px;
    height: 74px;
  }

  .profile-table td:first-child {
    width: 82px;
  }

  .profile-table img {
    width: 70px;
    height: 70px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
