:root {
  color-scheme: light;
  --ink: #102f33;
  --sea: #174f52;
  --cream: #fff0cd;
  --gold: #edbe69;
  --muted: #476368;
  --paper: #fcf3de;
  --line: #c5bca4;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: "Avenir Next", system-ui, sans-serif;
  font: 16px/1.4 var(--sans);
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); }
button, input, select { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid #fa9e2b; outline-offset: 2px;
}
[hidden] { display: none !important; }
h1, h2, h3, p, dl, dd { margin: 0; }
button, a, .die { -webkit-user-select: none; user-select: none; }
#play {
  height: 100vh; height: 100dvh;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 9px;
  justify-items: center; isolation: isolate; position: relative;
  background: #194f50 url(regatta.webp) 80% center / cover no-repeat;
}
#play::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(180deg, #082f354a, transparent 30%, transparent 64%, #082f353d);
}
.hud {
  display: flex; align-items: center; gap: 8px; width: min(100%, 880px);
  color: var(--cream); text-shadow: 0 2px 3px #112f36;
}
.hud h1 {
  display: flex; align-items: center; gap: 8px;
  font: italic bold clamp(31px, 6vw, 51px)/1 var(--serif);
  letter-spacing: -.065em;
  text-shadow: 0 2px 0 #174443, 1px 0 3px #163f42, 0 3px 8px #0b3439aa;
}
.sails { width: .76em; height: .8em; position: relative; transform: skewX(-8deg); filter: drop-shadow(0 2px 1px #163c3a); }
.sails::before, .sails::after { content: ""; position: absolute; bottom: 0; }
.sails::before { inset: 0 31% 20% 0; clip-path: polygon(100% 0, 100% 100%, 0 100%); background: #fff2cc; }
.sails::after { inset: 15% 0 0; clip-path: polygon(71% 0, 98% 72%, 71% 72%, 71% 83%, 100% 83%, 82% 100%, 12% 100%, 0 83%, 71% 83%); background: #f58b5a; }
.score-meter, .menu-knob {
  min-height: 44px; background: #143e40; color: var(--cream);
  border: 1px solid #ceb77d; box-shadow: inset 0 1px 0 #539091, 0 3px 0 #123337;
}
.score-meter {
  margin-left: auto; border-radius: 30px; padding: 0 13px; gap: 7px;
  display: flex; align-items: center; font-weight: 750;
}
.score-meter span { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; }
.score-meter strong { font: bold 24px/1 var(--serif); font-variant-numeric: tabular-nums; }
.score-meter i { font: 18px/1 var(--sans); color: var(--gold); }
.menu-knob { width: 44px; border-radius: 50%; display: grid; place-items: center; }
.menu-knob i { width: 17px; height: 13px; border-block: 2px solid var(--cream); background: linear-gradient(var(--cream),var(--cream)) center / 100% 2px no-repeat; }
.console {
  align-self: center; width: min(100%, 465px); height: min(100%, 680px);
  display: grid; grid-template-rows: minmax(0, 1fr) auto;
  color: var(--cream); border-radius: 20px;
  background: #143d3d;
  border: 2px solid #22423a;
  box-shadow: 0 0 0 1px #f2d392bb, 0 5px 0 #103335, 0 12px 30px #0d33395e;
}
.chart {
  min-height: 0; min-width: 0; display: grid; grid-template-rows: auto minmax(0,1fr) auto;
  padding: 10px 12px 6px; margin: 5px 5px 0; border-radius: 14px 14px 7px 7px;
  background-color: #2a6562;
  background-image: repeating-linear-gradient(39deg, transparent 0 3px, #0f414008 3px 4px),
    radial-gradient(ellipse at top left, #44827b, #296967 48%, #265455);
  border: 1px solid #b1b891;
  box-shadow: inset 0 0 0 3px #255452, inset 0 0 0 4px #8ca68c77;
}
.chart-head, .tray-head, .sheet-head, .section-head, .intro, .buttons, .chart-key, .statline {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.chart-head { padding: 0 4px 5px; }
.chart-head h2, .tray-head h2, .tray-head span, #pile-zone h3, .chart-key, .group-title {
  font: 650 12px/1.3 var(--sans); text-transform: uppercase; letter-spacing: .085em;
}
#round-marks { display: flex; gap: 4px; }
#round-marks i { width: 12px; height: 4px; background: #163f40; border-radius: 3px; }
#round-marks .filled { background: #f6ce77; }
.chart-field { min-height: 0; container-type: size; display: grid; place-items: center; }
#board {
  width: min(100cqw, 100cqh); aspect-ratio: 1;
  display: grid; grid-template-columns: 12px repeat(var(--n),minmax(0,1fr));
  grid-template-rows: 12px repeat(var(--n),minmax(0,1fr));
  padding: 0 5px 5px 0; gap: clamp(3px, 1vw, 7px);
}
.coord { align-self: center; text-align: center; color: #e4dfbf; font: 650 10px/1 var(--sans); }
.coord.paid { border-radius: 3px; background: #f0c578; color: #244744; }
.cell {
  position: relative; padding: 0; display: grid; place-items: center; min-width: 0; min-height: 0;
  border-radius: 15%; border: 1px solid #87a697; color: inherit;
  background: linear-gradient(145deg, #1f5453, #316464);
  box-shadow: inset 0 2px 5px #102d333e, 0 1px 0 #96b2a450;
}
.cell:empty::after { content: ""; width: 3px; height: 3px; border-radius: 50%; background: #a5bdae77; }
.cell.corner { border-color: #d6bb7e; }
.cell.corner:empty::after {
  content: "✦"; width: auto; height: auto; background: none; border-radius: 0;
  font-size: clamp(15px, 4vw, 26px); line-height: 1; color: #d7ba79;
}
.cell.corner:not(:empty)::before { content: ""; position: absolute; top: 5%; left: 5%; width: 11%; height: 11%; background: var(--gold); clip-path: polygon(0 0,100% 0,0 100%); }
.cell.pending, .pile-slot.pending { border-color: #ffdd8c; background: #587c67; box-shadow: inset 0 0 0 1px #f8cd79; cursor: grab; }
.cell.drop-target, .pile-slot.drop-target, #dice.drop-target { background: #7c9f73; outline: 3px solid #ffdf83; outline-offset: -3px; }
.chart-key { min-height: 21px; justify-content: center; font-size: 10px; color: #f1e9ce; }
.chart-key b, .star { color: #ffcf72; }
.star { font-size: 15px; }
.tray {
  min-width: 0; display: grid; align-content: center; gap: 7px;
  padding: 12px 15px 15px; border-radius: 0 0 17px 17px;
  background: linear-gradient(125deg,#224f50,#153b40 70%);
}
.tray-head h2 { color: #f6d898; }
.tray-head span { font-size: 10px; letter-spacing: .06em; color: #c8d8cb; }
#dice {
  width: 100%; display: flex; justify-content: center; align-items: center;
  min-height: 62px; gap: clamp(3px, 1.4vw, 12px); padding: 5px 4px 8px;
  background: #102f32; border: 1px solid #4a7066; border-radius: 12px;
  box-shadow: inset 0 3px 6px #071f24a0, 0 1px 0 #87a48d44;
}
.die-btn, .pile-slot { position: relative; min-width: 0; padding: 0; border: 0; background: none; border-radius: 20%; display: grid; place-items: center; }
.die-btn { flex: 0 1 54px; aspect-ratio: 1; cursor: grab; }
.die-btn.used .die { opacity: .14; box-shadow: none; }
.die-btn.selected .die { outline: 3px solid #ffc763; outline-offset: 2px; transform: translateY(-2px); }
.die {
  display: grid; grid-template: repeat(3,1fr) / repeat(3,1fr); place-items: center;
  width: 88%; aspect-ratio: 1; padding: 12%; border-radius: 20%; pointer-events: none;
  background: linear-gradient(135deg,#fffdec 10%,#faecca 69%,#ebd2a7);
  box-shadow: inset 0 0 0 1px #fff7d4, inset -2px -2px 2px #bda47e, 0 3px 0 #aa8e67, 0 5px 5px #0b252b85;
}
.die i { width: 72%; aspect-ratio: 1; border-radius: 50%; background: #193638; box-shadow: inset 0 1px 1px #021b20; }
.die i:only-child { width: 96%; background: #b74a35; }
.cell .die { width: 77%; padding: 10%; }
.stack-count { position: absolute; bottom: -2px; right: -2px; padding: 1px 4px; border-radius: 7px; background: #f1c172; color: var(--ink); font: bold 11px var(--sans); pointer-events: none; }
#guide { color: #e0e8d9; min-height: 1.35em; font-size: 13px; text-align: center; }
.controls { display: flex; gap: 9px; }
.game-btn {
  min-height: 46px; border-radius: 11px; flex: 1; padding: 4px 6px;
  font-weight: 800; border: 1px solid #ffe2a0; background: #f3c46d;
  color: #273a31; box-shadow: 0 3px 0 #9c6e39, 0 4px 6px #102a2e;
}
.game-btn.secondary { border-color: #a8c5ae; background: #cee0c9; box-shadow: 0 3px 0 #6f9586, 0 4px 6px #102a2e; }
.game-btn.secondary span { font-size: 20px; vertical-align: -1px; }
#reroll-count { display: inline-block; padding: 1px 5px; border-radius: 5px; background: #0001; font-size: 12px; }
.game-btn:disabled { background: #365858; color: #b0c4b9; border-color: #537271; box-shadow: 0 2px 0 #123234; }
.game-btn:enabled:active { transform: translateY(2px); box-shadow: none; }
#pile-zone { display: flex; gap: 8px; align-items: center; justify-content: center; }
#pile-zone h3 { font-size: 10px; }
#pile { display: flex; gap: 4px; }
.pile-slot { width: clamp(25px, 8vw, 38px); aspect-ratio: 1; border: 1px dashed #9cae96; color: #f2d89e; }
.drag-ghost {
  position: fixed; top: 0; left: 0; z-index: 5; pointer-events: none; width: 54px; aspect-ratio: 1;
  display: grid; place-items: center; filter: drop-shadow(2px 6px 4px #092d3699);
}
.drag-source .die { opacity: .25; }
.die-btn, .cell, .pile-slot { touch-action: none; -webkit-touch-callout: none; }
@keyframes tumble { from { transform: translateY(-7px) rotate(-13deg); } 65% { transform: translateY(1px) rotate(5deg); } }
@media (prefers-reduced-motion: no-preference) {
  #dice.rolling .die-btn:enabled .die { animation: tumble .28s ease-out; }
}
@media (orientation: portrait) {
  #play { grid-template-rows: clamp(72px, 15dvh, 126px) minmax(0,1fr); background: radial-gradient(ellipse at 50% 90%, #225c5c, #1b4d4c 68%); }
  #play::before {
    height: clamp(135px, 29dvh, 260px);
    background: linear-gradient(180deg,#123c4340,transparent 68%,#1b4d4c),
      url(regatta.webp) 50% 52% / cover;
  }
  .hud { align-self: start; }
  .console { height: min(100%, calc(100vw + 240px), 680px); }
}

@media (min-width: 760px) and (min-aspect-ratio: 11/10), (orientation: landscape) and (max-height: 540px) {
  #play { padding-inline: max(22px, env(safe-area-inset-left), env(safe-area-inset-right)); padding-top: max(12px, env(safe-area-inset-top)); }
  .console {
    width: min(100%, 806px); height: min(100%, 468px);
    grid-template: minmax(0,1fr) / minmax(0,1.35fr) minmax(0,1fr);
  }
  .chart { margin: 5px 0 5px 5px; border-radius: 14px 7px 7px 14px; }
  .tray { border-radius: 0 17px 17px 0; padding: clamp(12px,2vw,25px); gap: 13px; }
  .hud { padding-block: 4px; }
  .tray-head h2 { font: italic bold 29px/1 var(--serif); letter-spacing: -.04em; text-transform: none; }
  .controls { flex-wrap: wrap; }
  .game-btn { flex-basis: 100%; }
  #dice { gap: 4px; }
}
@media (max-height: 620px) {
  .chart { padding: 6px 8px 3px; }
  .tray { gap: 4px; padding: 8px 10px 10px; }
  #dice { min-height: 48px; padding-block: 3px 6px; }
  .die-btn { max-width: 45px; }
  .hud { padding-block: 0; }
}

/* The sheets use the same printed stock as the dice faces. */
dialog, .panel {
  color: var(--ink); background: var(--paper); border: 1px solid #baab86;
  border-radius: 18px; padding: 20px;
}
dialog { width: min(425px, calc(100% - 22px)); max-height: 88dvh; overflow: auto; overscroll-behavior: contain; box-shadow: 0 12px 62px #062e3690; }
dialog::backdrop { background: #092f34a6; }
dialog h2, #tune h1, #tune h2 { font: bold 28px/1.1 var(--serif); letter-spacing: -.045em; }
dialog h3 { margin: 15px 0 6px; font-size: 14px; }
dialog p, .panel p, .intro p { margin: 9px 0; color: var(--muted); font-size: 14px; }
dialog ol { padding-left: 22px; }
dialog li { margin: 8px 0; }
dialog form { margin-top: 15px; }
.sheet-head form { margin: 0; }
.close { display: grid; place-items: center; width: 44px; height: 44px; font-size: 26px; border-radius: 50%; border: 1px solid var(--line); background: transparent; }
.board-choices { display: flex; gap: 8px; }
.board-choices button, .outline, .primary:not(.game-btn) {
  border-radius: 9px; border: 1px solid var(--line); min-height: 44px; padding: 8px 14px;
  font: 700 14px/1.35 var(--sans); text-decoration: none; color: var(--ink); background: #fff9e9;
}
.board-choices button { flex: 1; }
.board-choices [aria-pressed=true], .primary:not(.game-btn) { background: var(--sea); color: var(--cream); border-color: var(--sea); }
.menu-list { display: grid; margin-top: 16px; }
.menu-list > * {
  display: flex; justify-content: space-between; align-items: center; min-height: 48px;
  background: none; border: 0; border-top: 1px solid var(--line); padding: 8px 0;
  color: var(--ink); text-decoration: none; font-weight: 650;
}
.score-figure { font-style: italic; margin: 5px 0; }
.score-figure strong { font: bold 40px/1 var(--serif); }
.hand { display: flex; align-items: baseline; gap: 8px; padding: 4px 0; border-bottom: 1px dotted var(--line); font-size: 14px; }
.hand small { margin-left: auto; text-align: right; color: var(--muted); }
.hand b { min-width: 22px; text-align: right; }
.hand.special { color: #875e26; }
#hand-values { display: grid; grid-template-columns: 1fr auto; gap: 3px; font-size: 14px; }
#pile-rule { display: block; margin-block: 8px; }
#tune { max-width: 1040px; margin: auto; padding: 20px max(14px,env(safe-area-inset-left)) 32px; }
#tune .intro { margin-bottom: 15px; }
.lab-layout { display: grid; grid-template-columns: 1fr 1.12fr; align-items: start; gap: 14px; }
.values { grid-column: 1; grid-row: 2; }
.stats { grid-column: 2; grid-row: 1/span 2; }
#setup label { display: block; margin: 12px 0 5px; font-weight: 650; }
#setup select { width: 100%; }
select, input[type=number] { border: 1px solid var(--line); background: #fffaf0; border-radius: 6px; padding: 7px; }
input[type=number] { width: 65px; text-align: right; }
input[type=checkbox] { accent-color: var(--sea); }
#point-inputs label, #multipliers label { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); padding: 5px 0; }
#multipliers { margin: 12px 0; }
.text-btn { background: none; border: 0; padding: 8px 0; text-decoration: underline; }
.statline { justify-content: flex-start; margin-block: 12px; }
.statline strong { font: bold 32px var(--serif); }
.statline span, .stats small { color: var(--muted); font-size: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 6px 0; border-bottom: 1px solid var(--line); text-align: right; }
th:first-child, td:first-child { text-align: left; }
#tune hr { margin-block: 22px; border: 0; border-top: 1px solid var(--line); }
@media (max-width: 650px) {
  .lab-layout { grid-template-columns: 1fr; }
  .values, .stats { grid-column: auto; grid-row: auto; }
  dialog { margin: auto auto max(6px,env(safe-area-inset-bottom)); }
}
