:root {
  color-scheme: light;
  --ink: #182e32;
  --muted: #506662;
  --page: #f6f1e6;
  --paper: #fffdf7;
  --line: #bdc7ba;
  --mint: #dcebe1;
  --green: #214b43;
  --rust: #a23c28;
  --tile: #ffedbb;
  --board-line: #a8b7a7;
  font: 16px/1.45 system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(#d9d0bf 0.75px, transparent 0.75px) 0 0 / 17px 17px, var(--page);
  color: var(--ink);
}
h1, h2, p, dl, dd { margin: 0; }
button, select, input { font: inherit; color: inherit; }
button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 6px 13px;
  font-weight: 730;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover:not(:disabled) { border-color: var(--green); background-color: #edf3e9; }
button:disabled { opacity: .48; cursor: default; }
:focus-visible { outline: 3px solid #8b2b1e; outline-offset: 2px; }
a { color: var(--green); font-weight: 700; }
.primary { color: white; background: var(--green); border-color: var(--green); }
.primary:hover:not(:disabled) { background: #143b32; }
.quiet { background: transparent; border-color: transparent; }
.muted { color: var(--muted); font-size: .86rem; }

.shell { width: min(100% - 44px, 1340px); margin-inline: auto; padding: 21px 0 27px; }
.masthead {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 13px;
  border-block-end: 1px solid #aebbad;
}
.masthead > .quiet { justify-self: end; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 900; line-height: 1.04; letter-spacing: -.025em; }
.brand-tile {
  position: relative;
  display: grid;
  place-items: center;
  width: 41px;
  aspect-ratio: 1;
  background: var(--tile);
  border: 1.5px solid var(--ink);
  border-radius: 8px 7px 8px 6px;
  box-shadow: 1px 3px 0 var(--ink);
  transform: rotate(-8deg);
  font: 900 1.55rem/1 Georgia, serif;
}
.brand-tile small { position: absolute; bottom: 4px; right: 4px; font: 700 .49rem/1 system-ui, sans-serif; }
.tabs { display: flex; gap: 3px; padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: #ece9dd; }
.tabs button { min-width: 94px; border-color: transparent; background: transparent; }
.tabs button[aria-pressed="true"] { background: var(--paper); border-color: #a4b2a5; box-shadow: 0 2px 0 #afbcab; }

.intro {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin: clamp(23px, 5vh, 55px) 0 19px;
}
.intro h1, .setup h1 { font-size: clamp(2rem, 5.2vw, 4.2rem); font-weight: 900; letter-spacing: -.046em; line-height: 1.12; }
.period { color: var(--rust); }
.intro p, .setup > p { color: var(--muted); font-size: clamp(.84rem, 1.5vw, 1.05rem); margin-top: 8px; }
.practice-scores {
  display: flex;
  gap: 3px;
  border: 1px solid #a8b9ab;
  border-radius: 12px;
  padding: 5px;
  background: var(--mint);
}
.practice-scores div { min-width: 85px; text-align: center; padding: 5px 9px; }
.practice-scores div + div { border-inline-start: 1px solid #a6b8ac; }
dt { color: var(--muted); font-size: .76rem; white-space: nowrap; }
dd { font-size: clamp(1.3rem, 2.4vw, 2.1rem); font-weight: 900; line-height: 1.1; font-variant-numeric: tabular-nums; }

.workspace { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: clamp(12px, 2vw, 23px); }
.card { min-width: 0; border: 1px solid #9baea1; border-radius: 17px; background: var(--paper); box-shadow: 2px 4px 0 #a2aa99; }
.practice-board, .practice-hand, .board-card, .match-side { padding: clamp(12px, 2.45vw, 30px); }
.practice-board { min-height: 375px; display: grid; grid-template-rows: auto minmax(120px, 1fr) auto; gap: 18px; }
.card h2, .board-card h1 { font-size: clamp(.97rem, 1.65vw, 1.23rem); font-weight: 850; }
.word-paper {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 15px;
  padding: 18px clamp(8px, 2vw, 23px);
  background:
    repeating-linear-gradient(0deg, transparent 0 23px, #d8dfd1 23px 24px),
    repeating-linear-gradient(90deg, transparent 0 23px, #d8dfd1 23px 24px), #f3f5ed;
  border: 1px solid #c4d1bd;
  border-radius: 11px 9px 13px 9px;
}
.word-row, .rack {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: clamp(3px, .7vw, 9px);
  width: min(100%, 510px);
  margin-inline: auto;
}
.word-slot, .tile { width: 100%; min-width: 0; min-height: 0; aspect-ratio: 1; border-radius: 8px; padding: 0; }
.word-slot { border: 1.5px dashed #779186; background: #fffdf7ad; }
.tile { display: grid; background: var(--tile); border: 1px solid #7b6840; box-shadow: 1px 2px 0 #9c854f; }
.tile[aria-pressed="true"] { outline: 2px solid var(--rust); outline-offset: 2px; background: #ffe095; }
.tile:hover:not(:disabled) { background: #ffe095; }
.face {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font: 850 clamp(.9rem, 3vw, 2.25rem)/1 system-ui, sans-serif;
  user-select: none;
}
.face small { position: absolute; bottom: 5%; right: 7%; font-size: .43em; color: #65552f; }
.face.blank { color: #5f466c; }
.notice { min-height: 1.45em; color: var(--muted); font-size: clamp(.78rem, 1.5vw, .92rem); text-align: center; overflow-wrap: anywhere; }
.notice.valid { color: #1f6542; font-weight: 800; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions button { flex: 1 1 auto; }
.practice-hand { display: grid; grid-template-rows: auto auto auto 1fr; gap: 18px; }
.practice-history { border-block-start: 1px dashed var(--line); padding-top: 12px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 7px; }
.section-head .quiet { min-height: 32px; font-size: .8rem; padding: 3px 5px; }
.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 6px 9px;
  margin: 4px 0;
  border: 1px solid #d4ded1;
  border-radius: 8px;
  background: #f5f7ef;
  font-size: .86rem;
}
.history-item strong { letter-spacing: .075em; }

.setup { margin: clamp(16px, 7vh, 72px) auto 0; max-width: 770px; padding: clamp(14px, 4vw, 43px); }
.setup h1 { font-size: clamp(1.7rem, 4vw, 3rem); }
.fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 11px; margin: 21px 0 16px; }
label { display: grid; gap: 4px; font-size: .83rem; font-weight: 760; }
input, select { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 7px; background: #edf3ea; padding: 7px 8px; min-height: 40px; }
.setup .actions button { flex: 0 1 auto; min-width: 100px; }
.setup > .setup-note { font-size: .77rem; margin-top: 13px; }

.match { margin-top: 17px; grid-template-columns: minmax(0, 1.55fr) minmax(0, .95fr); align-items: center; }
.board-card { background: #eff4e9; padding: clamp(8px, 1.5vw, 19px); }
.board-card h1 { font-size: clamp(.9rem, 2vw, 1.35rem); }
.board-scroll {
  width: min(100%, max(190px, calc(100dvh - 247px)));
  aspect-ratio: 1;
  overflow: auto;
  overscroll-behavior: contain;
  margin: 8px auto;
  border: 1px solid #687d70;
  border-radius: 8px;
  background: var(--board-line);
  container-type: inline-size;
  scrollbar-width: thin;
}
.board-grid {
  display: grid;
  grid-template: repeat(15, minmax(0, 1fr)) / repeat(15, minmax(0, 1fr));
  aspect-ratio: 1;
  width: calc(100cqw * var(--zoom, 1));
  gap: 1px;
}
.square {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #faf7eb;
  color: var(--green);
  font-size: clamp(.6rem, calc(2.5cqw * var(--zoom, 1)), 1.4rem);
}
.square:focus-visible { outline-offset: -2px; z-index: 1; }
.square .face { font-size: clamp(.58rem, calc(3.1cqw * var(--zoom, 1)), 2rem); }
.square.locked, .square.locked:hover { background: #f6dd9f; color: var(--ink); }
.square.draft, .square.draft:hover { background: #fff2ac; color: var(--ink); outline: 2px solid #a46c16; outline-offset: -2px; }
.square .face small { display: none; }
.square.l2, .legend .l2 { background: #cbd8f0; }
.square.l3, .legend .l3 { background: #92cfc3; }
.square.w2, .legend .w2 { background: #f1ceaf; }
.square.w3, .legend .w3 { background: #d88976; }
.legend { display: flex; justify-content: center; gap: 4px 11px; flex-wrap: wrap; color: var(--muted); font-size: .72rem; }
.legend span { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.legend i { width: .8em; aspect-ratio: 1; border: 1px solid #748d80; border-radius: 2px; }
.zoom { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: .72rem; }
.zoom button { padding: 0; min-height: 31px; min-width: 31px; font-size: 1rem; }
.match-side { display: grid; gap: 12px; }
.match-scores { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; }
.score-card { display: grid; gap: 4px; background: #f4f2e7; border: 1px solid #c3cfbf; padding: 7px 10px; border-radius: 8px; }
.score-card.current { background: var(--mint); border-color: #709786; }
.score-card span { color: var(--muted); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-card strong { font-size: clamp(1.2rem, 3vw, 2rem); line-height: 1.03; font-variant-numeric: tabular-nums; }
.bag { color: var(--muted); font-size: .79rem; white-space: nowrap; }
.match-notice { text-align: left; border-left: 3px solid #a6bcb0; padding: 4px 6px; background: #f0f4ec; }
.match-actions { margin-top: 10px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.match-side .rack { width: 100%; }
.match-side .face { font-size: clamp(.9rem, 2.4vw, 1.62rem); }
.match-footer { gap: 3px; border-top: 1px dashed var(--line); padding-top: 4px; }

dialog {
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid #819789;
  border-radius: 15px;
  box-shadow: 5px 7px 0 #22382e63;
  width: min(93%, 580px);
  max-height: 90dvh;
  padding: clamp(11px, 2.8vw, 25px);
  overflow: auto;
}
dialog::backdrop { background: #1837338c; }
.modal-head { margin-bottom: 9px; }
.modal-head h2 { font-size: clamp(1rem, 2.4vw, 1.35rem); }
.modal-head h2:focus { outline: none; }
.modal-list { max-height: min(49dvh, 390px); overflow: auto; }
.letters { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.letters button { padding: 0; }
.exchange-rack { margin-bottom: 13px; }
.rules-copy ul { padding-inline-start: 22px; }
.rules-copy li { margin: 8px 0; }
.score-summary { color: var(--green); font-weight: 850; margin-bottom: 5px; }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th, td { padding: 5px; border-bottom: 1px solid var(--line); text-align: start; }
th { background: var(--mint); }
td { overflow-wrap: anywhere; }

@media (max-width: 720px) {
  .shell { width: calc(100% - 22px); padding-top: 8px; }
  .intro { align-items: start; }
  .practice-scores div { min-width: 59px; padding-inline: 4px; }
}
@media (orientation: portrait) and (max-width: 690px) {
  .workspace, .match { grid-template-columns: 1fr; }
  .intro { flex-direction: column; gap: 12px; }
  .practice-board { min-height: 245px; }
  .practice-hand { gap: 11px; }
  .match { align-items: stretch; }
  .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 430px) {
  .masthead { padding-inline: 0; grid-template-columns: auto 1fr auto; gap: 4px; }
  .brand { font-size: .77rem; gap: 5px; }
  .brand-tile { width: 28px; font-size: 1.12rem; }
  .tabs { justify-self: center; padding: 2px; }
  .tabs button { min-width: 0; padding-inline: 8px; font-size: .84rem; }
  .masthead > .quiet { padding-inline: 3px; font-size: .76rem; }
}
@media (max-height: 570px) and (orientation: landscape) {
  .shell { padding: 6px 0 9px; }
  .masthead { padding: 3px 5px; }
  .brand-tile { width: 29px; font-size: 1.1rem; }
  .brand { font-size: .82rem; }
  button { min-height: 31px; padding: 3px 6px; font-size: .79rem; }
  .tabs { padding: 2px; }
  .tabs button { min-width: 75px; }
  .intro { margin: 9px 0 7px; gap: 6px; align-items: center; }
  .intro h1 { font-size: clamp(1.45rem, 3.9vw, 2.2rem); }
  .intro p { margin-top: 3px; }
  .practice-scores div { padding-block: 2px; }
  .practice-board { min-height: 166px; grid-template-rows: auto minmax(67px, 1fr) auto; gap: 6px; }
  .practice-board, .practice-hand, .match-side, .board-card { padding: 8px; }
  .practice-hand, .match-side { gap: 6px; }
  .practice-history { padding-top: 4px; }
  .word-paper { padding: 5px; gap: 6px; }
  .setup { margin-top: 9px; }
  .fields { margin: 9px 0; gap: 5px; }
  input, select { min-height: 32px; padding: 2px 5px; }
  .setup > .setup-note { margin-top: 6px; }
  .match { margin-top: 7px; gap: 8px; }
  .board-scroll { width: min(100%, max(110px, calc(100dvh - 144px))); margin-block: 4px; }
  .zoom button, .section-head .quiet { min-height: 25px; }
  .score-card { padding: 4px 6px; }
  .match-actions { margin-top: 5px; gap: 4px; }
  .legend { font-size: .66rem; gap: 3px 7px; }
}

@media (max-height: 440px) and (orientation: landscape) {
  .match { grid-template-columns: minmax(0, 1.12fr) minmax(0, 1fr); }
  .match-side { grid-template-columns: minmax(0, 1fr) auto; gap: 5px; }
  .match-side > .section-head:first-child { grid-column: 2; grid-row: 1; }
  .match-side > .section-head:first-child h2 { display: none; }
  .match-side > :not(.section-head:first-child) { grid-column: 1 / -1; }
  .match-side > .match-scores { grid-column: 1; grid-row: 1; gap: 4px; }
  .score-card { display: flex; align-items: baseline; justify-content: space-between; gap: 3px; }
  .score-card span, .bag { font-size: .69rem; }
  .match-notice { padding-block: 2px; }
  .match-side .rack { max-width: 234px; }
  .match-actions button { min-height: 27px; }
}

@media (max-height: 290px) and (orientation: landscape) {
  .match-side { gap: 3px; padding: 6px; }
  .match-side .rack { max-width: 203px; }
  .match-actions { gap: 3px; }
  .match-actions button, .match-side .section-head .quiet { min-height: 23px; padding-block: 1px; }
}
