* { box-sizing: border-box; margin: 0; padding: 0 }
[hidden] { display: none !important }
html, body { min-height: 100% }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 650; letter-spacing: -.01em; line-height: 1.25 }
h1 { font-size: clamp(26px, 3vw, 34px) }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer }
button:disabled { cursor: not-allowed; opacity: .45 }
a { color: var(--accent-ink) }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px }
.muted { color: var(--muted) }
kbd {
  font: 12px var(--font-body); padding: 1px 6px; border-radius: 6px;
  border: 1px solid var(--hairline); background: var(--surface); box-shadow: 0 1px 0 var(--hairline);
}

/* --- Pieces ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: 14px; font-weight: 700; text-decoration: none;
  background: var(--accent); color: var(--on-accent);
  box-shadow: 0 2px 0 var(--accent-2);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px) }
.btn:active:not(:disabled) { transform: translateY(1px); box-shadow: none }
.btn.ghost { background: var(--surface-2); color: var(--text); box-shadow: none }
.btn.small { padding: 7px 13px; font-size: 13.5px; border-radius: 11px }
.btn.full { width: 100% }
.pill {
  font-size: 12.5px; font-weight: 700; padding: 4px 11px; border-radius: 999px;
  background: var(--accent-wash); color: var(--accent-ink);
}
.sheet {
  background: var(--surface); border-radius: var(--radius); padding: 22px;
  box-shadow: var(--shadow); border: 1px solid var(--hairline);
}
.sheet.narrow { max-width: 440px; text-align: center; display: grid; gap: 14px; justify-items: center }
.mascot { width: 120px; height: 120px; object-fit: contain }
.notice {
  display: grid; gap: 4px; padding: 14px 16px; border-radius: 14px; margin-bottom: 14px;
  background: var(--warning-wash); color: var(--text); font-size: 14.5px;
}
.warn { color: var(--warning); font-weight: 700 }
.sub { font-size: 15px; margin: 18px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em }
.sheet > .sub:first-child { margin-top: 0 }

/* --- Top bar ----------------------------------------------------------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 10px 22px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--hairline);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-family: var(--font-display); font-weight: 700 }
.brand img { width: 34px; height: 34px; object-fit: contain }
.brand em { font-style: normal; font-weight: 500; color: var(--muted); padding-left: 10px; border-left: 1px solid var(--hairline) }
.bar-mid { display: flex; align-items: center; gap: 14px }
.section-name { font-weight: 700; color: var(--accent-ink); max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.timer {
  font: 700 18px var(--font-display); font-variant-numeric: tabular-nums;
  padding: 4px 12px; border-radius: 10px; background: var(--surface-2);
}
.timer.low { color: var(--danger); background: var(--danger-wash) }
.bar-end { display: flex; justify-content: flex-end; align-items: center; gap: 10px }

/* --- Lobby ------------------------------------------------------------- */
.page { max-width: 1120px; margin: 0 auto; padding: 32px 22px 60px }
.page.center { min-height: 70vh; display: grid; place-items: center }
.lobby-head { position: relative; max-width: 100%; display: grid; gap: 8px; margin-bottom: 22px; padding-right: 150px; min-height: 120px }
.lobby-head p { max-width: 680px }
.lobby-yugi { position: absolute; right: 0; bottom: -8px; width: 140px; height: 140px; object-fit: contain }
@media (max-width: 760px) { .lobby-head { padding-right: 96px } .lobby-yugi { width: 90px; height: 90px } }
.exam-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px }
.exam-tabs button {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 18px 7px 8px; border-radius: 999px; font-weight: 700;
  background: var(--surface); border: 1px solid var(--hairline);
}
.exam-tabs button img { width: 28px; height: 28px; object-fit: contain; border-radius: 8px }
.exam-tabs button[aria-selected="true"] { background: var(--text); color: var(--bg); border-color: var(--text) }
.lobby-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; align-items: start }
.length { display: grid; grid-template-columns: 1fr 1fr; gap: 10px }
.length-opt {
  display: grid; gap: 2px; text-align: left; padding: 14px 16px; border-radius: 14px;
  border: 1.5px solid var(--hairline); background: var(--surface-2);
}
.length-opt span { font-size: 13.5px; color: var(--muted); font-variant-numeric: tabular-nums }
.length-opt[aria-checked="true"] { border-color: var(--accent); background: var(--accent-wash) }
.length-opt[aria-checked="true"] strong { color: var(--accent-ink) }
.sections { width: 100%; border-collapse: collapse; font-size: 14.5px }
.sections td { padding: 7px 0; border-bottom: 1px solid var(--hairline) }
.sections tr:last-child td { border-bottom: 0 }
.sections td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700 }
.sections .good { color: var(--success) }
.sections .weak { color: var(--warning) }
.note { font-size: 13px; margin-top: 12px }
.papers { list-style: none; display: grid; gap: 8px }
.paper {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 14px; border-radius: 14px; background: var(--surface-2);
  transition: background .12s ease;
}
.paper:hover:not(:disabled) { background: var(--accent-wash) }
.paper .num {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none;
  background: var(--surface); font: 700 15px var(--font-display);
}
.paper .body { flex: 1; display: grid; line-height: 1.35 }
.paper .body small { color: var(--muted); font-size: 13px }
.paper .best { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--success) }
.paper .go { color: var(--accent-ink); font-weight: 700; font-size: 14px }
.foot { margin-top: 24px; font-size: 13.5px; text-align: center }

/* --- Session ----------------------------------------------------------- */
.session {
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr) 244px; gap: 18px;
  max-width: 1500px; margin: 0 auto; padding: 18px 22px 28px; align-items: start;
}
.session.no-passage { grid-template-columns: minmax(0, 1fr) 244px; max-width: 1100px }
.session.no-passage .reader { display: none }
.reader {
  position: sticky; top: 72px; max-height: calc(100vh - 92px); overflow: auto;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius);
  padding: 26px 28px; box-shadow: var(--shadow);
}
.passage { font-size: 17px; line-height: 1.8; white-space: pre-wrap; max-width: 68ch }
.passage mark { background: var(--accent-wash); color: var(--accent-ink); padding: 0 3px; border-radius: 4px; font-weight: 700 }
.question { display: grid; gap: 16px }
.q-head { display: flex; align-items: center; gap: 10px }
.q-num { font: 700 20px var(--font-display) }
.q-kind { color: var(--muted); font-size: 13.5px; flex: 1 }
.mark { padding: 6px 12px; border-radius: 10px; font-size: 13.5px; font-weight: 700; background: var(--surface-2) }
.mark[aria-pressed="true"] { background: var(--warning-wash); color: var(--warning) }
.stem { font-size: 17px; line-height: 1.7; white-space: pre-wrap }
.options { display: grid; gap: 8px }
.option {
  display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%;
  padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--hairline); background: var(--surface);
  transition: border-color .12s ease, background .12s ease;
}
.option:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--hairline)) }
.option .letter {
  width: 28px; height: 28px; flex: none; border-radius: 9px; display: grid; place-items: center;
  background: var(--surface-2); font: 700 14px var(--font-display);
}
.option[aria-checked="true"] { border-color: var(--accent); background: var(--accent-wash) }
.option[aria-checked="true"] .letter { background: var(--accent); color: var(--on-accent) }
.option .text { padding-top: 1px; line-height: 1.55 }
.q-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 4px }
.map { position: sticky; top: 72px; max-height: calc(100vh - 92px); overflow: auto; padding: 16px; display: grid; gap: 12px }
.map-legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted) }
.map-legend span { display: inline-flex; align-items: center; gap: 5px }
.dot { width: 10px; height: 10px; border-radius: 3px; border: 1.5px solid var(--hairline); background: var(--surface-2); display: inline-block }
.dot.done { background: var(--accent); border-color: var(--accent) }
.dot.marked { background: var(--warning-wash); border-color: var(--warning) }
.map-section { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 8px 0 5px }
.map-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px }
.cell {
  height: 30px; border-radius: 8px; font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--surface-2); border: 1.5px solid transparent;
}
.cell.done { background: var(--accent); color: var(--on-accent) }
.cell.marked { border-color: var(--warning); box-shadow: inset 0 -3px 0 var(--warning) }
.cell.here { outline: 2px solid var(--text); outline-offset: 1px }
.map-count { font-size: 13px; text-align: center }

/* --- Result ------------------------------------------------------------ */
.score-card { text-align: center; display: grid; gap: 4px; margin-bottom: 18px; padding: 30px }
.score { font: 700 64px/1.05 var(--font-display); color: var(--accent-ink); font-variant-numeric: tabular-nums }
.caption { font-weight: 700; color: var(--muted) }
.review-filter { display: flex; gap: 6px; margin-bottom: 12px }
.review-filter button { padding: 6px 12px; border-radius: 999px; font-size: 13.5px; font-weight: 700; background: var(--surface-2) }
.review-filter button[aria-pressed="true"] { background: var(--text); color: var(--bg) }
.review { list-style: none; display: grid; gap: 10px; max-height: 70vh; overflow: auto; padding-right: 4px }
.review li { padding: 12px 14px; border-radius: 14px; background: var(--surface-2); font-size: 14.5px; display: grid; gap: 6px }
.review .r-head { display: flex; gap: 8px; align-items: center; font-weight: 700 }
.review .tag { font-size: 12px; padding: 2px 8px; border-radius: 999px }
.review .tag.right { background: var(--success-wash); color: var(--success) }
.review .tag.wrong { background: var(--danger-wash); color: var(--danger) }
.review .tag.blank { background: var(--surface); color: var(--muted) }
.review .r-stem { white-space: pre-wrap; color: var(--muted); max-height: 7.5em; overflow: hidden }
.review .r-ans { font-size: 14px }
.review .r-ans b.ok { color: var(--success) }
.review .r-ans b.no { color: var(--danger) }
.review .r-note { font-size: 13.5px; color: var(--muted); border-left: 3px solid var(--accent-wash); padding-left: 10px }
.result-actions { display: flex; justify-content: center; margin-top: 22px }

dialog {
  margin: auto; border: 0; border-radius: var(--radius); padding: 24px; max-width: 420px; width: calc(100% - 32px);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(20, 16, 10, .45) }
.dialog-body { display: grid; gap: 10px }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px }

/* --- Narrow screens: the session still works on a tablet or a phone,
       it is simply laid out in one column. ------------------------------- */
@media (max-width: 1080px) {
  .session, .session.no-passage { grid-template-columns: minmax(0, 1fr); padding: 14px 16px 24px }
  .reader, .map { position: static; max-height: none }
  .map { order: 3 }
  .map-grid { grid-template-columns: repeat(10, 1fr) }
}
@media (max-width: 760px) {
  .lobby-grid { grid-template-columns: 1fr }
  .page { padding: 22px 16px 48px }
  .bar { grid-template-columns: auto 1fr auto; padding: 8px 16px }
  .brand em, .brand span, #who, #finishEarly { display: none }
  .section-name { max-width: 42vw }
  .reader { padding: 20px }
  .q-kind { display: none }
  .map-grid { grid-template-columns: repeat(6, 1fr) }
  .q-nav { flex-wrap: wrap }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important }
}
img[src="/yuggie-icon.png"] { border-radius: 22% }
.notice.soft { background: var(--accent-wash); color: var(--accent-ink) }
.result-yugi { width: 110px; height: 110px; object-fit: contain; justify-self: center; margin: -8px auto 4px }
