:root {
  color-scheme: light;
  --ink: #181f3a;
  --muted: #555e79;
  --accent: #263eaa;
  --line: #cad0e3;
  --paper: #fffdf5;
  --yellow: #ffcd42;
  font-family: system-ui, "Malgun Gothic", sans-serif;
  color: var(--ink);
  background: #f5f1e7;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background-image: linear-gradient(#253caa0c 1px, transparent 1px), linear-gradient(90deg, #253caa0c 1px, transparent 1px);
  background-size: 27px 27px;
}
header {
  min-height: 72px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px max(24px, calc((100vw - 1080px) / 2));
  border-bottom: 4px solid var(--yellow);
  background: var(--ink);
  color: white;
}
#identity {
  border: 1px solid #ffffff65;
  color: white;
  background: #ffffff14;
  overflow-wrap: anywhere;
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 800; }
.mark {
  display: inline-grid;
  place-items: center;
  width: 36px;
  aspect-ratio: 1;
  background: var(--yellow);
  color: var(--ink);
  border-radius: 10px;
  font-size: 24px;
}
main { max-width: 1080px; margin: 0 auto; padding: 36px 24px; }
.panel {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 20px;
  padding: clamp(16px, 4vw, 32px);
  box-shadow: 5px 5px 0 var(--ink);
}
.welcome {
  max-width: 450px;
  margin: clamp(18px, 8vh, 84px) auto 0;
}
.welcome h1 { font-size: clamp(30px, 5.5vw, 52px); margin: 0 0 24px; letter-spacing: -.075em; line-height: 1.12; }
dialog {
  width: min(380px, calc(100% - 32px));
  padding: 24px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 5px 5px 0 var(--ink);
}
dialog::backdrop { background: #181f3a80; }
dialog h2, dialog [role="status"] { margin: 0; }
dialog [role="status"] { color: #a42a27; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
#cancel-rename, .dialog-cancel { background: #e2e7fb; color: var(--ink); }
form { display: grid; gap: 12px; text-align: left; }
label, button { font-weight: 700; }
input, button { font: inherit; }
input {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: inherit;
}
button {
  border: 0;
  padding: 10px 16px;
  border-radius: 9px;
  color: white;
  background: var(--accent);
  font-weight: 750;
  cursor: pointer;
}
button:hover:not(:disabled) { filter: brightness(1.09); }
button:disabled { opacity: .46; cursor: default; }
:focus-visible { outline: 3px solid #8d621c; outline-offset: 3px; }
.secondary { background: #e2e7fb; color: var(--ink); margin-bottom: 16px; }
.lobby-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, .4fr); gap: 18px; align-items: start; }
aside button { width: 100%; }
h1, h2 { margin: 0 0 18px; letter-spacing: -.035em; }
h2 { font-size: 20px; }
#capacity, #waiting, #rooms, #message { color: var(--muted); }
#capacity { font-size: 14px; margin-left: 4px; }
.room-row { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); }
.room-row strong { display: block; color: var(--ink); }
.room-row > div { min-width: 0; }
.room-row strong, #room-title { overflow-wrap: anywhere; }
.room-row button { flex-shrink: 0; }
.room-row small { display: block; margin-top: 4px; }
#players { padding-left: 22px; line-height: 1.9; }
#countdown { text-align: center; font-size: 96px; color: var(--accent); font-weight: 800; }
#play { max-width: 480px; margin: auto; }
.board-head { display: flex; justify-content: space-between; margin-bottom: 12px; font-variant-numeric: tabular-nums; }
#board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  border: 2px solid var(--ink);
  border-radius: 6px;
  overflow: hidden;
}
#board button {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border-radius: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--accent);
  font-size: clamp(14px, 3vw, 23px);
}
#board button:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid var(--ink); }
#board button:nth-child(n+19):nth-child(-n+27),
#board button:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--ink); }
#board button.given { background: #edf0fa; color: var(--ink); }
#board button.related { background: #e0e8fc; }
#board button.matching { background: #c3d2fb; }
#board button.selected { background: #ffe28a; box-shadow: inset 0 0 0 2px var(--ink); }
#board button:focus-visible { outline-offset: -4px; }
.candidates {
  position: absolute;
  inset: 2px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  place-items: center;
  color: var(--muted);
  font-size: clamp(8px, 1.5vw, 12px);
  line-height: 1;
}
#marking { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 14px; }
#marking button { color: var(--ink); background: #edf0fa; }
#marking button[aria-pressed="true"] { color: white; background: var(--accent); }
#numbers { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin-top: 14px; }
#numbers button { padding-inline: 2px; background: #e2e7fb; color: var(--ink); }
#results h2 { text-align: center; font-size: clamp(30px, 7vw, 58px); color: var(--accent); margin: 6px 0 24px; }
#ranking { margin: 0 auto; max-width: 440px; padding-left: 34px; }
#ranking li { padding: 10px 4px; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
@media (max-width: 650px) {
  main { padding: 20px 12px; }
  .lobby-grid { grid-template-columns: 1fr; }
}
