:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  color: #f8ecd2;
  background: #102b36;
  --gold: #f9ce7c;
  --ink: #102b36;
  --muted: #bbcdca;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }
button, input { font: inherit; }
button {
  min-height: 44px;
  border: 1px solid #68818a;
  border-radius: 12px;
  background: #234550;
  color: #f8ecd2;
  cursor: pointer;
  touch-action: manipulation;
  padding: 9px 12px;
  transition: background .14s, transform .14s, border-color .14s;
}
button:hover:not(:disabled) { background: #315c66; }
button:active:not(:disabled) { transform: translateY(2px); }
button:focus-visible, input:focus-visible { outline: 3px solid #fff1b3; outline-offset: 2px; }
button:disabled { opacity: .48; cursor: default; }
[hidden] { display: none !important; }
.primary { background: var(--gold); color: var(--ink); border-color: #ffe2a3; font-weight: 800; }
.primary:hover:not(:disabled) { background: #ffe3a9; }
#app { height: 100%; width: 100%; max-width: 1400px; margin: auto; position: relative; isolation: isolate; }
#harbor { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; touch-action: none; }
header {
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  gap: 8px;
  background: #102b36e8;
  border-bottom: 1px solid #57777d;
}
h1 { font: bold 23px Georgia, serif; margin: 0; color: #ffe0a0; white-space: nowrap; }
header p { margin: 2px 0 0; color: var(--muted); font-size: 10px; }
nav { display: flex; gap: 5px; }
nav button { width: 44px; padding: 5px; font-size: 21px; }
#table { height: calc(100% - 66px); display: grid; grid-template-rows: 34px 190px minmax(0, 1fr); }
.tally { position: relative; display: flex; justify-content: space-between; align-items: center; padding: 5px 12px; font-size: 12px; background: #122f39dd; }
.tally strong { color: #ffdf9c; font-size: 17px; }
#best { color: var(--muted); }
#tray { padding: 7px 12px 2px; text-align: center; position: relative; background: #123a3b80; }
#dice { display: flex; gap: 7px; justify-content: center; height: 78px; align-items: center; }
.die {
  width: min(16.2vw, 64px);
  height: min(16.2vw, 64px);
  padding: 0;
  border: 2px solid #d2a764;
  background: #f4ddad;
  border-radius: 13px;
  position: relative;
  box-shadow: 0 5px 0 #8a6741, 0 8px 9px #0006;
  color: #233b41;
  opacity: 1 !important;
}
.die:hover:not(:disabled) { background: #fff0cb; }
.die svg { width: 100%; height: 100%; display: block; }
.die.held { border: 3px solid #a7f2d2; background: #d7f2d3; box-shadow: 0 5px 0 #428d78, 0 0 16px #8ee0b444; transform: translateY(-4px); }
.hold-tag { display: none; position: absolute; bottom: -17px; width: 100%; left: 0; color: #c2ffe0; font-size: 9px; font-weight: 900; letter-spacing: 1px; }
.held .hold-tag { display: block; }
.die.tumble { animation: tumble .43s ease-out both; }
@keyframes tumble {
  0% { transform: translateY(0) rotate(0); }
  25% { transform: translateY(-12px) rotate(-16deg); }
  55% { transform: translateY(-4px) rotate(12deg); }
  78% { transform: translateY(-7px) rotate(-6deg); }
  100% { transform: translateY(0) rotate(0); }
}
#cue { font-size: 12px; min-height: 18px; margin: 8px 0 5px; color: #fbe7bb; }
#roll { width: 100%; max-width: 400px; font-size: 17px; }
#roll small { font-size: 11px; font-weight: 600; margin-left: 8px; }
.keys { color: var(--muted); font-size: 9px; margin: 4px 0; }
#ledger { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 7px 10px 10px; background: #102b36ed; scrollbar-width: thin; }
.ledger-head { display: flex; align-items: center; justify-content: space-between; margin: 0 2px 6px; gap: 8px; }
h2 { font: bold 18px Georgia, serif; margin: 0; }
#preview-label { color: var(--muted); font-size: 10px; }
#categories { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.category { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 3px; padding: 5px 9px; font-size: 12px; border-radius: 9px; text-align: left; }
.category strong { color: var(--gold); font-size: 17px; }
.category.used { opacity: .65; background: #18363c; border-color: #35545a; }
.category.used strong { color: #bed4cf; }
.category.selected { outline: 2px solid #f9ce7c; background: #3f5951; }
.category.zero strong { color: #c9b9b1; }
.category:last-child { grid-column: 1 / -1; }
#bonus { display: flex; align-items: center; gap: 8px; font-size: 10px; margin: 9px 2px; color: var(--muted); }
#bonus span { display: flex; gap: 5px; white-space: nowrap; }
#bonus strong { color: var(--gold); white-space: nowrap; }
progress { width: 100%; min-width: 20px; height: 7px; accent-color: #f9ce7c; }
#confirm { border-top: 1px solid #526b6d; padding-top: 7px; }
#choice { margin: 0 0 6px; font-size: 12px; min-height: 30px; line-height: 1.3; color: #ddd7bf; }
#bank { width: 100%; }
#overlay { position: absolute; inset: 66px 0 0; display: flex; padding: 16px; overflow-y: auto; background: #092330b0; backdrop-filter: blur(4px); }
#panel { width: 100%; max-width: 460px; flex-shrink: 0; margin: auto; padding: 22px; border: 1px solid #92a99a; border-radius: 22px; background: linear-gradient(145deg, #254e52f5, #132f3cf5); box-shadow: 0 20px 60px #0006; }
#panel h2 { font-size: 35px; color: #ffe0a0; margin: 0 0 12px; }
#panel p { font-size: 14px; line-height: 1.5; color: #d2ded4; }
#panel .eyebrow { font-size: 10px; text-transform: uppercase; letter-spacing: 2px; color: var(--gold); margin-top: 0; }
#panel button { width: 100%; margin: 4px 0; }
#panel .small { font-size: 11px; color: #b6cdc7; }
#panel label { font-size: 12px; display: block; margin-top: 14px; }
#panel input { width: 100%; padding: 11px; border-radius: 9px; border: 1px solid #7d9895; background: #102f37; color: #fff2d1; margin: 5px 0; text-transform: uppercase; }
#panel .crest { font-size: 44px; line-height: 1; color: #ffdc93; margin: 10px 0; }
#panel .result-score { font: bold 64px Georgia, serif; margin: 8px 0 0; color: #ffe3a2; }
#panel dl { display: grid; grid-template-columns: 1fr auto; font-size: 12px; gap: 5px; }
#panel dt, #panel dd { margin: 0; }
#panel dd { color: var(--gold); font-weight: bold; }
/* Score feedback occupies the non-interactive tally, never a dice or banking control. */
#toast { pointer-events: none; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; opacity: 0; background: #ffe1a0; color: #15343b; padding: 3px 8px; font-size: 13px; font-weight: bold; text-align: center; transition: opacity .2s; z-index: 1; }
#toast.show { opacity: 1; }
@media (min-width: 700px) {
  #table { grid-template-columns: minmax(240px, 1fr) minmax(310px, 1fr); grid-template-rows: 36px minmax(0, 1fr); }
  .tally { grid-column: 1 / -1; }
  #tray { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 20px; }
  #dice { gap: 10px; width: 100%; height: 110px; }
  .die { width: min(6.4vw, 78px); height: min(6.4vw, 78px); }
  #cue { margin: 15px 0; }
  #ledger { padding: 14px; border-left: 1px solid #68818a; }
  .category { min-height: 47px; }
}
@media (max-height: 650px) and (max-width: 699px) {
  header { height: 56px; padding: 5px 9px; }
  h1 { font-size: 20px; }
  header p { font-size: 8px; }
  nav button { width: 40px; min-height: 40px; }
  #overlay { top: 56px; padding: 10px; }
  #panel { padding: 18px; }
  #table { height: calc(100% - 56px); grid-template-rows: 30px 175px minmax(0, 1fr); }
  #dice { height: 66px; }
  #tray { padding-top: 4px; }
  #cue { margin-top: 7px; }
  #panel h2 { font-size: 28px; }
}
@media (max-height: 450px) and (min-width: 600px) {
  header { height: 52px; }
  #overlay { top: 52px; padding: 8px; }
  #table { height: calc(100% - 52px); grid-template-columns: 1fr 1.15fr; grid-template-rows: 30px minmax(0, 1fr); }
  .tally { grid-column: 1 / -1; }
  #tray { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 7px 10px; }
  #dice { height: 74px; gap: 7px; width: 100%; }
  .die { width: min(6.7vw, 58px); height: min(6.7vw, 58px); }
  #cue { margin: 11px 0 5px; }
  #ledger { padding: 7px; }
  .category { min-height: 44px; }
  #panel { max-width: 570px; padding: 16px; }
  #panel h2 { font-size: 28px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
