@font-face {
  font-family: Chivo;
  src: url('./assets/fonts/Chivo-Regular.otf') format('opentype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: Chivo;
  src: url('./assets/fonts/Chivo-SemiBold.otf') format('opentype');
  font-weight: 600;
  font-display: swap;
}
:root {
  color-scheme: light;
  --ink: #16222a;
  --muted: #55636b;
  --sky: #eaf3f8;
  --accent: #ffd23f;
  --rule: 1px solid var(--ink);
  --pad: clamp(16px, 1.65vw, 26px);
  font: 400 16px/1.45 Chivo, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body, h1, h2, p, dl, dd { margin: 0; }
body { background: white; }
button, select, input { font: inherit; color: inherit; }
button, select {
  border: var(--rule);
  border-radius: 0;
  background: white;
  padding: 8px 13px;
}
button { cursor: pointer; }
button:hover:enabled, a:hover { background-color: var(--sky); }
button:disabled { cursor: default; color: var(--muted); }
:focus-visible { outline: 3px solid #176597; outline-offset: 2px; }
[hidden] { display: none !important; }
::selection { background: var(--accent); }
a, .link { color: inherit; text-decoration: underline; text-underline-offset: .2em; }
.skip-link { position: absolute; left: -999px; }
.skip-link:focus { left: 10px; top: 10px; padding: 10px; background: white; z-index: 5; }
.page-shell { max-width: 1700px; margin: auto; padding: clamp(12px, 2vw, 32px); }
.masthead, h1 { display: flex; align-items: center; }
.masthead { justify-content: space-between; gap: 12px; margin-bottom: var(--pad); }
.masthead a { font-size: 14px; }
h1, h2 { font-weight: 600; text-transform: uppercase; line-height: 1; }
h1 { gap: .22em; font-size: clamp(35px, 5vw, 78px); letter-spacing: -.055em; }
h1 img { width: .9em; border: var(--rule); }
h2 { font-size: 23px; letter-spacing: -.035em; }
.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) clamp(255px, 20vw, 315px); border: var(--rule); }
.play-area { min-width: 0; }
.scorebar, .scorebar dl, .actions, #photo-tools { display: flex; align-items: center; }
.scorebar { justify-content: space-between; gap: 8px; padding-right: var(--pad); }
.scorebar dl { align-items: stretch; }
.scorebar dl > div { padding: 9px clamp(12px, 2vw, 34px); border-right: var(--rule); }
.scorebar dt, .label, legend, #limit-row label, .result-stats dt {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .055em;
  text-transform: uppercase;
}
.scorebar dd, .result-stats dd { font: 600 clamp(20px, 2vw, 32px)/1.16 ui-monospace, monospace; letter-spacing: -.065em; }
#pairs-total { color: var(--muted); }
.timer-item.urgent { background: var(--accent); }
#pause-button { font-size: 14px; }
.field { padding: clamp(10px, 1.3vw, 22px); border-block: var(--rule); background: var(--sky); }
.board-stage { position: relative; }
.board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(7px, .85vw, 15px); }
.board.large { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.card {
  position: relative;
  height: clamp(108px, calc((100dvh - 278px) / 4), 220px);
  padding: 0;
  border: 0;
  background: transparent;
  perspective: 800px;
  touch-action: manipulation;
}
.card:focus-visible { z-index: 1; }
.card-inner, .card-back, .card-front { position: absolute; inset: 0; }
.card-inner { transform-style: preserve-3d; transition: transform .26s ease; }
.is-flipped .card-inner, .is-matched .card-inner { transform: rotateY(180deg); }
.card-back, .card-front {
  display: grid;
  place-items: center;
  border: var(--rule);
  border-radius: 4px;
  overflow: hidden;
  backface-visibility: hidden;
}
.card-back {
  background-color: #31536a;
  background-image: repeating-linear-gradient(42deg, transparent 0 7px, #b5d0de26 7px 8px),
                    repeating-linear-gradient(-42deg, transparent 0 7px, #b5d0de26 7px 8px);
  box-shadow: inset 0 0 0 4px #fff, inset 0 0 0 5px var(--ink);
}
.card-back::before, .card-back::after {
  content: '';
  position: absolute;
  width: clamp(16px, 2.4vw, 36px);
  aspect-ratio: 1;
  transform: rotate(45deg);
  border: 1px solid #c7dce6;
  background: #31536a;
}
.card-back::after { width: clamp(8px, 1.1vw, 16px); background: #d7e6ef; border: none; }
@media (hover: hover) {
  .card[aria-disabled="false"]:hover .card-back { background-color: #40647c; box-shadow: inset 0 0 0 4px var(--accent); }
}
.card-front { transform: rotateY(180deg); background: white; }
.card-front img { width: 100%; height: 100%; object-fit: contain; min-height: 0; }
.match-badge { display: none; position: absolute; right: 4px; bottom: 4px; background: var(--ink); color: white; padding: 0 5px; font-size: 13px; }
.is-matched .match-badge { display: block; }
.pause-overlay { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 15px; background: var(--sky); border: var(--rule); }
#game-status { padding: 10px var(--pad); font-size: 14px; }
aside { border-left: var(--rule); }
.settings, .statistics, .dialog-body, dialog header { padding: var(--pad); }
.settings { display: grid; gap: 21px; }
fieldset { min-width: 0; border: 0; padding: 0; margin: 0; }
legend, .label, #limit-row label { padding: 0; margin-bottom: 6px; }
.options { display: flex; border: var(--rule); }
.options label { flex: 1; position: relative; cursor: pointer; }
.options label + label { border-left: var(--rule); }
.options input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.options span { display: block; text-align: center; padding: 9px 3px; font-size: 15px; }
.options input:checked + span, .collection-tabs button[aria-pressed=true] { background: var(--sky); font-weight: 600; box-shadow: inset 0 -3px var(--ink); }
.options input:disabled + span { color: var(--muted); cursor: default; }
.options input:focus-visible + span { outline: 3px solid #176597; outline-offset: -3px; }
#time-limit, #photos-button { width: 100%; }
#photos-button { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 15px; }
#photos-button span:last-child { color: var(--muted); font-size: 13px; }
.primary { background: var(--accent); font-weight: 600; }
.primary:hover:enabled { background: #ffdf78; }
.primary:disabled { background: #eee; }
.hint { color: var(--muted); font-size: 14px; }
.hint:empty { display: none; }
.statistics { border-top: var(--rule); }
.statistics dl { margin: 16px 0; }
.statistics dl > div { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #cbd5da; }
.statistics dt, .link { font-size: 14px; }
.statistics dd { font-variant-numeric: tabular-nums; font-weight: 600; }
.link { border: 0; padding: 4px 0; }
dialog { color: var(--ink); padding: 0; border: var(--rule); width: min(530px, calc(100% - 26px)); max-height: 90dvh; }
dialog::backdrop { background: #16222a70; }
dialog header { display: flex; justify-content: space-between; align-items: center; border-bottom: var(--rule); background: var(--sky); }
.close-dialog { font-size: 24px; padding: 0; width: 36px; height: 36px; line-height: 1; }
.dialog-body { display: grid; gap: 16px; }
.collection-tabs, .result-stats { display: grid; grid-template-columns: 1fr 1fr; }
.collection-tabs button { text-align: left; }
.collection-tabs button + button { border-left: none; }
.collection-tabs small { color: var(--muted); display: block; }
.actions, #photo-tools { gap: 8px; flex-wrap: wrap; }
#photo-tools button { font-size: 14px; }
.photo-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 5px; max-height: 36dvh; overflow-y: auto; }
.photo-grid img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.photo-grid:empty { display: none; }
.result-stats { grid-template-columns: repeat(3, 1fr); padding-block: 12px; border-block: var(--rule); }
#new-best { font-weight: 600; }
.history-row { display: grid; grid-template-columns: 1fr auto; padding-bottom: 8px; border-bottom: 1px solid #cbd5da; }
.history-row small { grid-column: 1 / -1; color: var(--muted); }
#toast { position: fixed; bottom: 12px; inset-inline: 12px; margin: auto; width: fit-content; padding: 10px 16px; color: white; background: var(--ink); }
@media (max-width: 830px) {
  .game-layout { grid-template-columns: 1fr; }
  aside { display: grid; grid-template-columns: 1fr 1fr; border-left: none; border-top: var(--rule); }
  .statistics { border-top: 0; border-left: var(--rule); }
  .card { height: auto; aspect-ratio: 1.2; }
}
@media (max-width: 560px) {
  .masthead { margin-bottom: 12px; }
  .masthead a { font-size: 13px; }
  .scorebar { padding-right: 6px; gap: 4px; }
  .scorebar dl { flex: 1; justify-content: space-around; }
  .scorebar dl > div { padding: 8px 2px; border: 0; }
  .scorebar dt { font-size: 10px; }
  .scorebar dd { font-size: 18px; }
  #pause-button { font-size: 13px; padding: 7px; }
  .field { padding: 7px; }
  .board, .board.large { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .card { aspect-ratio: .91; }
  .card-back { box-shadow: inset 0 0 0 3px white; }
  aside { grid-template-columns: 1fr; }
  .statistics { border-left: 0; border-top: var(--rule); }
  .settings { gap: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  .card-inner { transition: none; }
}
