:root {
  color-scheme: light;
  --ink: #293235;
  --muted: #4c5a5d;
  --paper: #d2dada;
  --edge: #92a0a3;
  font-family: Bahnschrift, "Segoe UI", "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  color: var(--ink);
  background: #c1caca;
  font-synthesis: none;
}
* { box-sizing: border-box; }
body {
  min-height: 100svh;
  margin: 0;
  padding: 16px;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 25% 4%, #e1e6e3, #bac5c6 84%);
}
.game { width: min(100%, 29rem, calc(100svh - 21rem)); min-width: min(100%, 18.5rem); }
.heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.heading-actions { display: flex; gap: 5px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.36rem, 5vw, 2rem); font-weight: 580; letter-spacing: -.034em; line-height: 1.05; }
button {
  color: inherit;
  white-space: nowrap;
  cursor: pointer;
  font: inherit;
  border-radius: 4px;
  border: 1px solid var(--edge);
  background: linear-gradient(#dce2e0, #cdd6d6);
  padding: 7px 10px;
}
button:hover { background: #e3e9e6; }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid #3c565e; outline-offset: 3px; }
button:disabled { opacity: .48; cursor: default; transform: none; }
[hidden] { display: none !important; }
#map, #restart { font-size: .82rem; padding: 5px 8px; }
#map { touch-action: none; -webkit-touch-callout: none; }
#map[aria-pressed="true"] { background: #e7ece9; }
kbd {
  font: 500 .71rem "Segoe UI", sans-serif;
  background: #bac7c8;
  border-radius: 3px;
  padding: 2px 4px;
}
.plate {
  overflow: hidden;
  border-radius: 6px 6px 3px 3px;
  background: #475256;
  box-shadow: 2px 8px 20px #2f3d413c, 0 2px 1px #33424545;
}
.rail {
  height: 39px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 11px;
  align-items: center;
  padding-inline: 12px;
  background: linear-gradient(#c7d1d0, #aebcbd);
  border-top: 1px solid #dde5e2;
  border-bottom: 2px solid #839295;
}
.rail > span:first-child { font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; }
#matched { font-size: 1.25rem; font-variant-numeric: tabular-nums; line-height: 1; }
.face { font-size: .76rem; letter-spacing: .025em; text-align: right; font-weight: 550; }
canvas { display: block; width: 100%; aspect-ratio: 1; }
.guide { min-height: 87px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 0 10px; }
.guide-copy { min-width: 0; }
.guide h2 { font-size: 1.02rem; font-weight: 620; margin-bottom: 4px; }
.guide p { font-size: .88rem; line-height: 1.43; color: var(--muted); text-wrap: pretty; }
.controls {
  --direction-key: clamp(44px, 10vw, 48px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 9px clamp(10px, 3.4vw, 19px) 11px;
  border: 1px solid #a0afb0;
  border-top-color: #e3eae7;
  border-radius: 8px 8px 17px 17px;
  background: linear-gradient(180deg, #cbd6d4, #b8c6c6);
  box-shadow: inset 0 -3px 0 #8ca0a16b, 0 4px 10px #33424522;
}
.controls button { touch-action: manipulation; user-select: none; -webkit-tap-highlight-color: transparent; }
.arrows {
  position: relative;
  display: grid;
  grid-template: repeat(3, var(--direction-key)) / repeat(3, var(--direction-key));
  isolation: isolate;
}
.arrows::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(150deg, #506065, #283639 75%);
  clip-path: polygon(35% 0, 65% 0, 67% 2%, 67% 33%, 98% 33%, 100% 35%, 100% 65%, 98% 67%, 67% 67%, 67% 98%, 65% 100%, 35% 100%, 33% 98%, 33% 67%, 2% 67%, 0 65%, 0 35%, 2% 33%, 33% 33%, 33% 2%);
}
.arrows::after {
  content: "";
  grid-area: 2 / 2;
  place-self: center;
  position: relative;
  width: 27px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #394a4e;
  box-shadow: inset 0 2px 5px #1e2a2d, 0 1px #71818685;
}
.arrows button {
  z-index: 1;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 5px;
  color: #e1ebe7;
  background: transparent;
  font: 600 1.35rem/1 "Segoe UI", sans-serif;
}
.arrows [data-direction="up"] { grid-area: 1 / 2; }
.arrows [data-direction="left"] { grid-area: 2 / 1; }
.arrows [data-direction="right"] { grid-area: 2 / 3; }
.arrows [data-direction="down"] { grid-area: 3 / 2; }
.arrows button[data-cue="true"] { background: #546e75; box-shadow: inset 0 0 0 2px #bad1d3; }
.arrows button:active { background: #253337; box-shadow: inset 0 2px 5px #152124; transform: none; }
.arrows button:focus-visible { outline-color: #e6ece8; outline-offset: -4px; }
.press-actions {
  --action-key: 52px;
  display: grid;
  grid-template-columns: repeat(2, 56px);
  gap: clamp(8px, 2vw, 17px);
  align-self: start;
  padding-block-start: calc((var(--direction-key) * 3 - var(--action-key)) / 2);
}
.press-actions button {
  display: grid;
  grid-template-rows: var(--action-key) 16px auto;
  place-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  font-size: .83rem;
  font-weight: 560;
}
.press-actions button:active { transform: none; }
.control-label { line-height: 16px; }
.press-actions kbd { line-height: 12px; }
.control-cap {
  display: grid;
  width: var(--action-key);
  height: var(--action-key);
  place-items: center;
  border: 1px solid #36484b;
  border-radius: 50%;
  color: #e7eeeb;
  background: linear-gradient(150deg, #647c80, #42565b 78%);
  box-shadow: inset 0 1px #a6b7b6, inset 0 -2px #27394080, 0 2px 0 #314347;
  font: 600 1.68rem/1 "Segoe UI", sans-serif;
}
#undo .control-cap {
  border-color: #6c8183;
  color: #304044;
  background: linear-gradient(150deg, #d5dfdc, #a8bbba 78%);
  box-shadow: inset 0 1px #ecf1ec, inset 0 -2px #6a818350, 0 2px 0 #6d8587;
}
#undo:disabled { opacity: .66; }
#phase[aria-pressed="true"] .control-cap { color: #304044; background: linear-gradient(145deg, #e4ece9, #b8cccc 76%); }
#phase[data-cue="true"] .control-cap { border-color: #31545c; box-shadow: inset 0 1px #e4eeea, inset 0 -2px #27394080, 0 2px 0 #314347; }
.press-actions button:active .control-cap { box-shadow: inset 0 2px 4px #263639a0; transform: translateY(2px); }
.controls:has(button[data-direction="up"]:disabled) .arrows::before { opacity: .68; }
#next { font-size: .84rem; display: flex; align-items: center; gap: 7px; min-height: 38px; }
.outcome { display: grid; gap: 5px; justify-items: end; flex: 0 0 auto; }
.quiet { background: transparent; border-color: transparent; color: var(--muted); padding: 3px 0; font-size: .79rem; text-decoration: underline; text-underline-offset: 3px; }
.score { display: flex; align-items: center; gap: 7px; background: #aebdbe; padding: 6px 8px; border-top: 1px solid #94a5a8; border-bottom: 1px solid #dfe6e5; border-radius: 3px; }
.score span { text-transform: uppercase; font-size: .67rem; letter-spacing: .09em; }
.score output { font-size: 1.23rem; line-height: 1; font-variant-numeric: tabular-nums; }
@media (max-width: 390px) {
  body { padding: 12px; }
  .guide { min-height: 66px; padding-block: 9px; }
  .press-actions kbd, #next kbd { display: none; }
}
@media (max-width: 340px) {
  #map kbd { display: none; }
  .press-actions button { font-size: .78rem; }
}
@media (pointer: coarse) {
  #map, #restart { min-height: 44px; }
  .press-actions kbd { display: none; }
}
@media (max-width: 390px), (pointer: coarse) {
  .press-actions button { grid-template-rows: var(--action-key) 16px; }
}
@media (hover: hover) {
  .arrows button:hover:not(:disabled):not(:active) { background-color: #4b6369; }
  .press-actions button:hover:not(:disabled) .control-cap { filter: brightness(1.1); }
}
@media (prefers-reduced-motion: reduce) {
  button:active, .press-actions button:active .control-cap { transform: none; }
}

.utilities { margin-top: 9px; display: flex; justify-content: space-between; align-items: center; gap: 9px; }
.utility-actions { display: flex; align-items: center; gap: 15px; margin-inline-start: auto; }
#sound::before {
  content: "";
  display: inline-block;
  width: .46em;
  height: .46em;
  margin-inline-end: .37em;
  border: 1px solid currentColor;
  border-radius: 50%;
  vertical-align: .05em;
}
#sound[aria-pressed="true"]::before { background: currentColor; }
#rules-dialog {
  --rules-inset: clamp(15px, 4vw, 25px);
  width: min(44rem, calc(100% - 26px));
  max-height: calc(100svh - 30px);
  overflow: hidden;
  color: var(--ink);
  background: linear-gradient(148deg, #e0e8e5, #cbd8d8 88%);
  border: 1px solid #a4b5b7;
  border-top-color: #edf2ed;
  border-radius: 6px;
  padding: 0;
  box-shadow: 2px 16px 42px #27393d5c;
}
#rules-dialog[open] { display: flex; flex-direction: column; }
#rules-dialog::backdrop { background: #28383b8a; }
.rules-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px var(--rules-inset);
  border-bottom: 1px solid #aebfc1;
}
#rules-dialog h2 { font-size: 1.54rem; font-weight: 590; }
.rules-header button { font-size: .84rem; }
.rules-scroll { min-height: 0; overflow: auto; padding: 15px var(--rules-inset) 22px; scrollbar-width: thin; scrollbar-color: #87999b transparent; }
.rules-scroll:focus-visible { outline: 2px solid #3c565e; outline-offset: -3px; }
.rules-intro { color: var(--ink); font-size: .96rem; line-height: 1.5; margin-bottom: 15px; }
.rules-body section {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, .94fr);
  align-items: start;
  gap: clamp(14px, 3vw, 25px);
  border-top: 1px solid #aebfc1;
  padding: 15px 0;
}
.rules-body section:last-child { padding-bottom: 0; }
.rules-body h3 { font-size: 1rem; font-weight: 650; margin: 0 0 7px; }
.rules-body p { font-size: .86rem; line-height: 1.56; color: var(--muted); text-wrap: pretty; }
.rules-body p + p { margin-top: 8px; }
.rules-body figure { margin: 0; }
.rules-body img { display: block; width: 100%; height: auto; border-radius: 4px; background: #475256; }
.rules-body figcaption { margin-top: 6px; font-size: .8rem; line-height: 1.45; color: var(--ink); text-wrap: pretty; }
@media (max-width: 590px) {
  .rules-body section { grid-template-columns: 1fr; gap: 11px; }
}
