@font-face {
  font-family: Board Sans;
  src: local("Aptos"), local("Segoe UI");
  font-display: swap;
}

:root {
  color-scheme: dark;
  font-family: Board Sans, system-ui, sans-serif;
  color: #edfaff;
  background: #0a1c24;
  --surface: #142f3a;
  --inset: #0e242d;
  --line: #456773;
  --muted: #b7cfd7;
  --ice: #b3eaf5;
  --lime: #cdeca8;
  --gold: #f0d47a;
  --focus: #ffe68e;
  --digit-width: 63px;
  --digit-height: 84px;
  --operator-width: 51px;
  --operator-height: 65px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 42% 0, #2b5061 0, transparent 56%),
    repeating-linear-gradient(90deg, #a4d7e403 0 1px, transparent 1px 42px),
    #0a1c24;
}
button, select { font: inherit; }
button, select, summary { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.table, .copyright { width: min(1190px, calc(100% - 3.5rem)); margin: 0 auto; }
.table { padding: 2rem 0 1.5rem; }
.copyright { padding: 1rem 0 2rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .875rem; line-height: 1.5; }
.copyright p + p { margin-top: .25rem; }
.masthead, .brand, .mode-controls { display: flex; align-items: center; }
.masthead { justify-content: space-between; gap: 1.5rem; margin-bottom: 1.5rem; }
.brand { gap: .85rem; }
.brand-mark {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 13%;
  width: 3.35rem;
  aspect-ratio: 1;
  flex: none;
  border: 2px solid #d5f8ff;
  border-radius: 50%;
  background: radial-gradient(circle at 37% 27%, #426b7c, #172f3a 75%);
  box-shadow: inset 0 0 0 3px #769daa83, 0 0 18px #98e3ff35, 0 3px 4px #071920b0;
}
.brand-mark::before, .brand-mark::after {
  content: "";
  display: block;
  width: 1.42rem;
  height: .29rem;
  border-radius: 2px;
  background: #e5faff;
  box-shadow: 0 1px 5px #93e8ff;
}
h1, h2, p { margin: 0; }
.brand h1 { font-size: clamp(1.7rem, 3.3vw, 2.45rem); letter-spacing: -.052em; line-height: 1.08; }
.brand p { margin-top: .24rem; color: var(--muted); line-height: 1.35; }
.mode-controls { gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
.preferences { display: flex; align-items: center; flex-wrap: wrap; gap: .45rem; }
.preferences select { min-width: 6rem; }
.mode-controls label { color: var(--muted); font-size: .875rem; font-weight: 650; }
.sound-setting {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: .4rem;
  padding: 0 .58rem;
  border: 1px solid var(--line);
  border-radius: .4rem;
  cursor: pointer;
}
.sound-setting input { width: 1rem; height: 1rem; margin: 0; accent-color: var(--lime); }
select {
  appearance: none;
  min-height: 44px;
  min-width: 7rem;
  padding: .5rem 1.95rem .5rem .7rem;
  border: 1px solid var(--line);
  border-radius: .4rem;
  color: inherit;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%) calc(100% - 15px) center / 5px 5px no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) calc(100% - 10px) center / 5px 5px no-repeat,
    var(--inset);
}

.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(235px, 280px); gap: 1rem; align-items: start; }
.panel { border: 1px solid var(--line); border-radius: .75rem; background: var(--surface); }
.board {
  min-width: 0;
  padding: 1.15rem;
  border-top: 2px solid var(--gold);
  background: linear-gradient(158deg, #284b59, #142f3a 63%);
  box-shadow: 0 20px 52px #04111778, inset 0 0 0 3px #9dcddb12;
}
.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: .5rem;
  padding: .64rem .8rem;
  border: 1px solid #41626f;
  border-radius: .42rem;
  background: #0c202a;
  box-shadow: inset 0 2px 6px #091820b0;
}
.scoreboard > div { display: grid; gap: .14rem; }
.scoreboard > div:nth-child(2) { justify-items: center; }
.scoreboard > div:last-child { justify-items: end; text-align: right; }
.scoreboard strong { font: 700 1.15rem/1.3 ui-monospace, Consolas, monospace; font-variant-numeric: tabular-nums; }
#clock { color: var(--lime); }
#clock[data-urgent] { color: var(--gold); }
.label { color: var(--muted); font-size: .875rem; font-weight: 720; letter-spacing: .09em; line-height: 1.25; text-transform: uppercase; }
.tray { margin-top: .95rem; }
.tray-heading { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; margin-bottom: .45rem; }
.used { font-size: .875rem; color: var(--muted); }
.hand-actions { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.tokens { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-start; }

.token, .played-card {
  --card-paper: #c1e1ea;
  --card-light: #edfaff;
  --card-ink: #113d55;
  --card-edge: #658e9f;
  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  padding: 0;
  border: 1px solid var(--card-edge);
  color: var(--card-ink);
  background:
    repeating-linear-gradient(135deg, #ffffff1a 0 1px, transparent 1px 5px),
    linear-gradient(145deg, var(--card-light) 0%, var(--card-paper) 80%);
  box-shadow: inset 0 0 0 2px #f4fdff89, 0 2px var(--card-edge), 0 4px 6px #041d2966;
  font: 750 1.85rem/1 ui-monospace, Consolas, monospace;
}
.token {
  width: var(--digit-width);
  height: var(--digit-height);
  min-width: 44px;
  min-height: 44px;
  border-radius: .54rem;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}
.operator-card {
  --card-paper: #b7d9a8;
  --card-light: #e9f6db;
  --card-ink: #243f28;
  --card-edge: #719879;
}
.token.operator-card { width: var(--operator-width); height: var(--operator-height); font-size: 1.45rem; }
.token::before, .token::after {
  content: attr(data-glyph);
  position: absolute;
  font: 740 .62rem/1 ui-monospace, Consolas, monospace;
  pointer-events: none;
}
.token::before { top: .36rem; left: .38rem; }
.token::after { bottom: .36rem; right: .38rem; transform: rotate(180deg); }
.token:not(:disabled):hover { filter: brightness(1.07); }
.token:active { cursor: grabbing; }
.token[aria-pressed="true"] { outline: 2px solid var(--ice); outline-offset: 3px; }
.token[aria-pressed="true"]:focus-visible { outline: 3px solid var(--focus); }
.token[data-used] {
  color: #c0d8e0;
  border-color: #426673;
  background:
    repeating-linear-gradient(45deg, #8cb8c327 0 1px, transparent 1px 5px),
    repeating-linear-gradient(135deg, #8cb8c32e 0 1px, transparent 1px 5px),
    #1c3a47;
  box-shadow: inset 0 0 0 3px #244650;
}
.token[data-used]::before, .token[data-used]::after { content: none; }
.token:disabled { cursor: default; touch-action: manipulation; }
.token[data-carried] { opacity: .43; }
.drag-card {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 20;
  pointer-events: none;
  box-shadow: inset 0 0 0 2px #f4fdff89, 0 3px var(--card-edge), 0 12px 24px #020e1cb0;
}

.equation { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: start; gap: .58rem; margin-top: 1rem; }
.lane { min-width: 0; display: grid; gap: .42rem; }
.lane h2 { padding: 0 .1rem; }
.equals { width: 2.7rem; margin-top: 2.6rem; }
.equals::before, .equals::after { width: 1.1rem; height: .24rem; }
.expression {
  display: flex;
  min-height: 5.85rem;
  align-items: center;
  align-content: center;
  flex-wrap: wrap;
  gap: .3rem;
  padding: .55rem;
  border: 1px dashed #648692;
  border-radius: .48rem;
  background:
    repeating-linear-gradient(0deg, #23465499 0 1px, transparent 1px 22px),
    #102731;
}
#left-expression, #left-expression .expression-token.digit { justify-content: flex-end; }
.board[data-dragging] .expression { border-color: #9abfc9; }
.lane[data-drop-over] .expression { border: 1px solid var(--gold); box-shadow: 0 0 0 2px #f0d47a75; background-color: #224957; }
.empty { color: var(--muted); text-align: center; width: 100%; font-size: .93rem; }
.expression-token.digit { display: inline-flex; gap: .11rem; max-width: 100%; flex-wrap: wrap; }
.played-card {
  width: 1.75rem;
  height: 2.35rem;
  border-radius: .28rem;
  font-size: 1.08rem;
  box-shadow: inset 0 0 0 1px #effdff80, 0 1px var(--card-edge);
}
button.played-card:not(:disabled) {
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.played-card[data-carried] { opacity: .43; }
.played-card[aria-pressed="true"] { outline: 2px solid var(--ice); outline-offset: 2px; }
.played-card[data-insert]::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: 2px;
  background: var(--gold);
  z-index: 1;
  pointer-events: none;
}
.played-card[data-insert="before"]::before { left: -3px; }
.played-card[data-insert="after"]::before { right: -3px; }
.board[data-edit-drag] [data-drop-tray] { outline: 1px dashed #9abfc9; outline-offset: .3rem; }
.board[data-edit-drag] [data-drop-tray][data-drop-over] { outline: 2px solid var(--gold); }

.lane-actions { display: flex; flex-wrap: wrap; gap: .34rem; }
.button { min-height: 44px; padding: .46rem .68rem; border: 1px solid transparent; border-radius: .4rem; font-weight: 690; line-height: 1.2; }
.secondary { color: #e3f7ff; border-color: #507584; background: #15333f; }
.place { flex: 1; color: #e8faff; background: #254c5d; border-color: #5b8392; }
.primary { color: #15291a; background: var(--lime); border-color: #e8fbd6; }
.button:not(:disabled):hover { filter: brightness(1.15); }
.button:disabled { opacity: .52; }
.rotate { white-space: nowrap; }
.rotate span:not(.rotate-label) { color: var(--ice); }
.feedback { min-height: 1.3rem; margin: .72rem 0 .55rem; color: var(--lime); line-height: 1.35; }
.feedback[data-error] { color: #ffd1b9; }
.board-footer { display: flex; justify-content: space-between; gap: .75rem; }
.board-footer .primary { min-width: 10rem; margin-left: auto; }

.sidebar { display: grid; gap: .78rem; min-width: 0; }
.sidebar .panel { padding: .9rem; }
.guide { background: linear-gradient(145deg, #284c5a, #173541 72%); border-color: #567986; }
.guide .label { color: var(--gold); }
.sidebar h2 { margin: .35rem 0 .4rem; font-size: 1.25rem; line-height: 1.15; letter-spacing: -.02em; }
.sidebar p { line-height: 1.45; color: #d3e7ed; }
.progress-track { display: flex; gap: .3rem; margin-top: .78rem; }
.progress-track:empty { display: none; }
.progress-track span { flex: 1; height: 4px; background: #50707d; border-radius: 4px; }
.progress-track span[data-done] { background: var(--gold); }
[data-guide]:not(:disabled) { outline: 2px solid var(--gold); outline-offset: 2px; }
.result { border-color: #729781; }
.result .button { margin-top: .85rem; width: 100%; }
.sidebar dl { display: grid; gap: .4rem; margin: .82rem 0 .35rem; }
.sidebar dl > div { display: flex; justify-content: space-between; gap: .5rem; }
.sidebar dt { color: var(--muted); }
.sidebar dd { text-align: right; margin: 0; font-variant-numeric: tabular-nums; }
.sidebar summary { min-height: 28px; cursor: pointer; font-weight: 650; }
#score-form { margin-top: .9rem; padding-top: .75rem; border-top: 1px solid var(--line); }
#score-form h3 { margin: 0 0 .62rem; font-size: 1rem; color: var(--lime); }
#score-form label { display: block; font-size: .875rem; margin-bottom: .28rem; }
#score-name { width: 100%; min-height: 44px; padding: .5rem; border: 1px solid var(--line); border-radius: .4rem; color: inherit; background: var(--inset); font: inherit; }
#score-name[aria-invalid="true"] { border-color: #ffd1b9; }
#score-status { margin-top: .65rem; }
.high-scores summary ~ p { margin-top: .45rem; font-size: .875rem; }
.high-scores table { width: 100%; margin-top: .45rem; border-collapse: collapse; font-size: .875rem; }
.high-scores caption { text-align: left; color: var(--muted); margin: 0 0 .35rem; }
.high-scores th, .high-scores td { text-align: right; padding: .35rem .25rem; border-bottom: 1px solid var(--line); }
.high-scores :is(th, td):nth-child(2) { text-align: left; overflow-wrap: anywhere; }
.high-scores td { font-variant-numeric: tabular-nums; }
.shortcuts p { margin-top: .7rem; font-size: .875rem; }
kbd { border: 1px solid #587888; border-radius: .22rem; padding: .05rem .25rem; color: #e8faff; }

@media (max-width: 800px) {
  .table, .copyright { width: min(100% - 1.5rem, 660px); }
  .table { padding-top: 1.15rem; }
  .masthead { align-items: flex-start; flex-wrap: wrap; gap: .9rem; margin-bottom: .9rem; }
  .mode-controls { justify-content: flex-start; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: .65rem; }
  .sidebar { display: contents; }
  .sidebar .guide { grid-row: 1; }
  .board { padding: .8rem; }
}
@media (max-width: 440px) {
  :root { --digit-width: 46px; --digit-height: 61px; --operator-width: 44px; --operator-height: 53px; }
  .table, .copyright { width: calc(100% - 1rem); }
  .masthead { gap: .75rem; }
  .brand { gap: .65rem; }
  .brand-mark { width: 2.65rem; }
  .brand-mark::before, .brand-mark::after { width: 1.1rem; }
  .brand p { font-size: .9rem; }
  .guide h2 { margin-top: .2rem; }
  .hand-actions { align-items: flex-start; flex-direction: column; }
  .tokens { gap: .35rem; }
  .scoreboard .label { font-size: .78rem; letter-spacing: .035em; }
  .scoreboard strong { font-size: 1.02rem; }
  .equation { gap: .3rem; }
  .expression { min-height: 4.5rem; padding: .35rem; }
  .lane-actions > .button { flex: 1 1 100%; }
  .equals { width: 1.9rem; margin-top: 2.6rem; }
  .equals::before, .equals::after { width: .8rem; height: .17rem; }
}
