:root {
  color-scheme: light;
  font-family: "Trebuchet MS", "Avenir Next", sans-serif;
  color: #252a25;
  background: #f3f6f1;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --paper: #f3f6f1;
  --white: #ffffff;
  --ink: #252a25;
  --muted: #788078;
  --line: #dedfd4;
  --line-dark: #c9cbbf;
  --lime: #d5f469;
  --coral: #e5674e;
  --teal: #5bb8a4;
  --serif: Georgia, "Times New Roman", serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--paper);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background-color: var(--paper);
  background-image:
    radial-gradient(ellipse at 12% 45%, rgb(213 244 105 / 13%), transparent 32%),
    linear-gradient(90deg, transparent 49.95%, rgb(37 42 37 / 2%) 50%, transparent 50.05%);
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
  font: inherit;
}

fieldset {
  min-inline-size: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 3px;
}

.app-shell {
  display: flex;
  width: min(100%, 1680px);
  min-height: 100vh;
  flex-direction: column;
  margin-inline: auto;
  padding: 0 clamp(20px, 4vw, 64px);
}

.topbar {
  display: grid;
  min-height: 82px;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid var(--line-dark);
}

.brand {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 34px;
  aspect-ratio: 1;
  place-items: center;
  border-radius: 10px;
  background: var(--lime);
  transform: rotate(-7deg);
}

.glyph {
  font-family: "Segoe UI Symbol", "Apple Symbols", sans-serif;
  font-weight: 400;
  line-height: 1;
}

.brand-mark.glyph {
  font-size: 22px;
}

.brand-dice {
  color: var(--ink);
}

.brand-cup {
  color: var(--teal);
}

.brand-five {
  color: var(--coral);
}

.turn-chip {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border: 1px solid var(--line-dark);
  border-radius: 99px;
  color: #525a52;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.turn-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--teal);
}

.utility-actions {
  display: flex;
  justify-self: end;
  gap: 7px;
}

.icon-button {
  display: grid;
  width: 38px;
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.icon-button:hover {
  border-color: var(--line-dark);
  background: var(--white);
  transform: translateY(-1px);
}

.icon-button .glyph {
  font-size: 19px;
}

.about-dialog {
  width: min(640px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line-dark);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 16px 64px rgb(37 42 37 / 20%);
}

.about-dialog::backdrop {
  background: rgb(37 42 37 / 48%);
}

.about-heading {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.about-title {
  margin: 0;
  font-size: 20px;
}

.about-heading .icon-button {
  flex: 0 0 38px;
}

.about-content {
  padding: 20px;
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.about-content h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.about-content section + section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.game-layout {
  display: grid;
  flex: 1;
  grid-template-columns: minmax(0, 1fr) minmax(310px, 390px);
  animation: arrive 520ms cubic-bezier(0.2, 0.7, 0.25, 1) both;
}

.play-area {
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: clamp(32px, 5vh, 58px) clamp(30px, 5vw, 76px) 25px 0;
}

.play-heading {
  display: flex;
  min-height: 82px;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.play-tagline {
  margin: 10px 0 16px;
  color: var(--muted);
  font-size: 8px;
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.13em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.05;
}

.roll-counter {
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding-top: 5px;
  color: var(--muted);
}

.roll-counter-label {
  margin-right: 7px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.roll-counter strong {
  color: var(--ink);
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.roll-count-total {
  font-size: 13px;
}

.dice-stage {
  position: relative;
  min-height: 305px;
  flex: 1;
  overflow: hidden;
  isolation: isolate;
  background-color: rgb(255 254 249 / 58%);
  background-image:
    radial-gradient(ellipse at 50% 87%, rgb(91 184 164 / 14%), transparent 43%),
    linear-gradient(180deg, rgb(255 254 249 / 20%) 0%, rgb(255 254 249 / 0%) 100%);
}

.dice-stage::before,
.dice-stage::after {
  position: absolute;
  z-index: -1;
  width: 145px;
  height: 145px;
  border: 1px solid rgb(37 42 37 / 8%);
  border-radius: 50%;
  content: "";
  pointer-events: none;
}

.dice-stage::before {
  top: -98px;
  right: 12%;
}

.dice-stage::after {
  bottom: -106px;
  left: 12%;
  width: 200px;
  height: 200px;
}

.stage-grid {
  position: absolute;
  z-index: -1;
  inset: 0;
  background-image: radial-gradient(rgb(37 42 37 / 12%) 0.7px, transparent 0.7px);
  background-position: center;
  background-size: 19px 19px;
  mask-image: linear-gradient(transparent, black 27%, black 77%, transparent);
  opacity: 0.27;
}

#dice-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

.dice-controls {
  position: absolute;
  z-index: 2;
  inset: 14px 0 42px;
  display: flex;
}

.turn-start-overlay {
  position: absolute;
  z-index: 4;
  inset: 14px 16px 42px;
  display: grid;
  place-items: center;
  padding: 20px;
  border: 1px solid var(--line-dark);
  background: rgb(255 255 255 / 50%);
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  pointer-events: none;
}

.turn-start-overlay[hidden] {
  display: none;
}

.die-toggle {
  position: relative;
  display: flex;
  width: 20%;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 0 2px 6px;
  border: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  color: transparent;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease;
}

.die-toggle:disabled {
  cursor: default;
}

.die-toggle:not(:disabled):hover {
  border-color: rgb(37 42 37 / 10%);
  background: rgb(255 255 255 / 28%);
}

.die-toggle.is-held {
  border-color: rgb(91 184 164 / 85%);
  background: rgb(91 184 164 / 12%);
}

.die-toggle.is-held:not(:disabled):hover {
  background: rgb(91 184 164 / 24%);
}

.die-value {
  color: transparent;
  font-size: 1px;
}

.die-hold-label {
  min-height: 19px;
  color: #677069;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.06em;
  opacity: 0;
  transition: opacity 160ms ease;
}

.die-toggle.is-held .die-hold-label {
  opacity: 1;
  color: #267c70;
}

.die-toggle:not(:disabled):hover .die-hold-label {
  opacity: 1;
}

.stage-caption {
  position: absolute;
  z-index: 3;
  right: 0;
  bottom: 12px;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #727970;
  font-size: 10px;
  letter-spacing: 0.02em;
  pointer-events: none;
}

.caption-marker {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--coral);
}

.play-footer {
  display: flex;
  min-height: 84px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line-dark);
}

.turn-hint {
  display: flex;
  max-width: 330px;
  align-items: center;
  gap: 11px;
  color: #5f665e;
  font-size: 12px;
  line-height: 1.45;
}

.hint-index {
  display: grid;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line-dark);
  border-radius: 50%;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.roll-button {
  display: inline-flex;
  min-width: 172px;
  min-height: 50px;
  align-items: center;
  justify-content: center;
  gap: 11px;
  padding: 0 15px;
  border: 0;
  border-radius: 3px;
  background: var(--lime);
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  transition:
    background 160ms ease,
    transform 160ms ease,
    opacity 160ms ease;
}

.roll-button:hover:not(:disabled) {
  background: #c5eb50;
  transform: translateY(-2px);
}

.roll-button:active:not(:disabled) {
  transform: translateY(0);
}

.roll-button:disabled {
  cursor: default;
  opacity: 0.48;
}

.roll-button .glyph {
  font-size: 19px;
}

.roll-button kbd {
  margin-left: 2px;
  padding: 3px 4px;
  border: 1px solid rgb(37 42 37 / 20%);
  border-radius: 2px;
  font-family: inherit;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.score-hint {
  margin: 11px 0 0;
  color: #898e85;
  font-size: 10px;
}

.score-panel {
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: clamp(32px, 5vh, 58px) 0 24px clamp(24px, 3vw, 42px);
  border-left: 1px solid var(--line-dark);
}

.score-heading {
  display: flex;
  min-height: 82px;
  align-items: flex-start;
  justify-content: space-between;
}

.score-heading .eyebrow {
  margin-bottom: 9px;
}

.score-heading h2 {
  display: flex;
  align-items: baseline;
  gap: 11px;
  margin: 0;
  font-family: var(--serif);
  font-size: 27px;
  font-weight: 500;
  letter-spacing: 0;
}

.scorecard-count {
  color: var(--muted);
  font-family: "Trebuchet MS", sans-serif;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.score-heading-mark {
  display: grid;
  width: 34px;
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid var(--line-dark);
  border-radius: 50%;
  color: var(--coral);
}

.score-heading-mark.glyph {
  font-size: 17px;
}

.score-sheet {
  border-top: 1px solid var(--line-dark);
}

.score-group-title {
  display: flex;
  min-height: 31px;
  align-items: center;
  justify-content: space-between;
  color: #777e74;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.score-group-title:not(:first-child) {
  border-top: 1px solid var(--line);
}

.score-group-title small {
  color: #969b91;
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.score-row {
  display: grid;
  width: 100%;
  min-height: 29px;
  grid-template-columns: minmax(0, 1fr) max-content 42px;
  align-items: center;
  gap: 5px;
  padding: 0 7px 0 0;
  border: 0;
  border-top: 1px solid rgb(201 203 191 / 55%);
  background: transparent;
  text-align: left;
  cursor: default;
  transition:
    background 120ms ease,
    padding 120ms ease;
}

.score-row.is-available {
  padding-left: 7px;
  border: 1px dashed var(--teal);
  border-radius: 0;
  cursor: pointer;
}

.score-row.is-available:hover {
  padding-left: 8px;
  background: rgb(213 244 105 / 32%);
}

.score-row:disabled {
  color: inherit;
  opacity: 1;
}

.category-name {
  overflow: hidden;
  color: #333a33;
  font-size: 10px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-rule {
  overflow: hidden;
  color: #92978d;
  font-size: 8px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-score {
  min-width: 37px;
  color: #a4a89e;
  font-family: var(--serif);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.score-row.is-available .category-score {
  color: #438778;
  font-weight: 700;
}

.score-row.is-scored .category-score {
  color: var(--ink);
  font-weight: 700;
}

.score-row.is-scored .category-name::after {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: 7px;
  border-radius: 50%;
  background: var(--teal);
  content: "";
  vertical-align: 1px;
}

.totals {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line-dark);
}

.total-row {
  display: flex;
  min-height: 25px;
  align-items: center;
  justify-content: space-between;
  color: #5e655d;
  font-size: 10px;
}

.total-row strong {
  color: var(--ink);
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.total-row small {
  margin-left: 5px;
  color: #9a9e94;
  font-size: 8px;
}

.bonus-row strong {
  color: #438778;
}

.grand-total {
  min-height: 44px;
  margin-top: 5px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.grand-total strong {
  color: var(--coral);
  font-size: 25px;
  font-weight: 600;
}

.game-over {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 12px;
  color: #646b62;
  font-size: 10px;
}

.game-over-icon {
  display: grid;
  width: 26px;
  aspect-ratio: 1;
  place-items: center;
  border-radius: 50%;
  background: var(--lime);
  color: var(--ink);
}

.game-over-icon.glyph {
  font-size: 16px;
}

.text-button {
  margin-left: auto;
  padding: 5px 0;
  border: 0;
  background: transparent;
  color: #438778;
  cursor: pointer;
  font-size: 10px;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.game-over[hidden] {
  display: none;
}

@keyframes arrive {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 1500px) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr) minmax(350px, 430px);
  }

  .score-row {
    min-height: 32px;
  }
}

@media (max-width: 900px) {
  .app-shell {
    padding-inline: 24px;
  }

  .game-layout {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  }

  .play-area {
    padding-right: 24px;
  }

  .score-panel {
    padding-left: 22px;
  }

  .category-rule {
    display: none;
  }

  .score-row {
    grid-template-columns: minmax(0, 1fr) 42px;
  }
}

@media (max-width: 700px) {
  .app-shell {
    min-height: 100svh;
    padding-inline: 18px;
  }

  .topbar {
    min-height: 65px;
    grid-template-columns: 1fr auto;
  }

  .turn-chip {
    display: none;
  }

  .utility-actions {
    grid-column: 2;
  }

  .game-layout {
    display: flex;
    flex-direction: column;
  }

  .play-area {
    min-height: 540px;
    padding: 30px 0 22px;
  }

  .play-heading {
    min-height: 78px;
  }

  h1 {
    font-size: 17.5px;
  }

  .dice-stage {
    min-height: clamp(235px, 35svh, 320px);
    flex: 0 1 auto;
  }

  .play-footer {
    min-height: 78px;
    gap: 10px;
  }

  .turn-hint {
    max-width: 44%;
    gap: 8px;
    font-size: 10px;
  }

  .hint-index {
    width: 23px;
    height: 23px;
  }

  .roll-button {
    min-width: 150px;
    min-height: 47px;
    gap: 8px;
    padding-inline: 10px;
    font-size: 12px;
  }

  .roll-button kbd {
    display: none;
  }

  .score-hint {
    min-height: 14px;
    font-size: 9px;
  }

  .score-panel {
    padding: 27px 0 22px;
    border-top: 1px solid var(--line-dark);
    border-left: 0;
  }

  .score-heading {
    min-height: 72px;
  }

  .category-rule {
    display: inline;
  }

  .score-row {
    min-height: 37px;
    grid-template-columns: minmax(0, 1fr) 1fr 44px;
  }

  .category-name {
    font-size: 11px;
  }

  .category-rule {
    font-size: 9px;
  }

  .category-score {
    font-size: 17px;
  }

  .score-group-title {
    min-height: 36px;
  }

  .totals {
    margin-top: 18px;
  }

  .total-row {
    min-height: 30px;
    font-size: 11px;
  }

  .grand-total {
    min-height: 48px;
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding-inline: 13px;
  }

  .play-footer {
    align-items: flex-start;
    padding-block: 13px;
  }

  .turn-hint {
    max-width: 38%;
  }

  .roll-button {
    min-width: 138px;
  }

  .score-row {
    grid-template-columns: minmax(0, 1fr) 42px 38px;
  }

  .category-rule {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .game-layout {
    animation: none;
  }

  .icon-button,
  .die-toggle,
  .roll-button,
  .score-row,
  .die-hold-label {
    transition: none;
  }
}
