/* Skull King Scorekeeper — pirate parchment on dark seas */

:root {
  --bg0: #120e0b;
  --bg1: #1a1410;
  --bg2: #241c16;
  --parchment: #e8d9c0;
  --parchment-dim: #cbb892;
  --ink: #2a2118;
  --ink-soft: #5c4a38;
  --sea: #1e3a3a;
  --foam: #7eb8a8;
  --coral: #c45c3e;
  --gold: #c9a227;
  --danger: #b33a2b;
  --ok: #3d7a4a;
  --radius: 14px;
  --font-display: "Pirata One", "Palatino Linotype", Palatino, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse 120% 80% at 50% -10%, #2a1f18 0%, transparent 55%),
    radial-gradient(ellipse 80% 50% at 100% 100%, #1a2a2a 0%, transparent 45%),
    var(--bg0);
  color: var(--parchment);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

.app {
  min-height: 100dvh;
  max-width: 920px;
  margin: 0 auto;
  padding:
    calc(12px + var(--safe-top))
    calc(16px + var(--safe-right))
    calc(16px + var(--safe-bot))
    calc(16px + var(--safe-left));
  display: flex;
  flex-direction: column;
}

.view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  animation: rise 0.35s ease-out;
}

.view[hidden],
[hidden] {
  display: none !important;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Brand home */
.home-top {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  min-height: 40px;
  margin-bottom: 0.25rem;
}

.home-top-spacer {
  flex: 1;
}

.brand-hero {
  text-align: center;
  padding: 0.5rem 0 0.5rem;
}

.brand-mark {
  width: 96px;
  height: 96px;
  border-radius: 22%;
  object-fit: cover;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(201, 162, 39, 0.35);
}

.brand-title {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 9vw, 3.4rem);
  font-weight: 400;
  letter-spacing: 0.02em;
  margin: 0.65rem 0 0.15rem;
  color: var(--parchment);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.brand-tag {
  margin: 0;
  color: var(--parchment-dim);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

.home-actions {
  margin: 1.25rem 0 1rem;
}

.section-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--parchment-dim);
  margin: 0 0 0.65rem;
  font-weight: 600;
}

.game-list-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.home-empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--parchment-dim);
  border: 1px dashed rgba(232, 217, 192, 0.2);
  border-radius: var(--radius);
}

.game-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.game-card {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.9rem 1rem;
  border-radius: var(--radius);
  background: linear-gradient(145deg, var(--bg2), var(--bg1));
  border: 1px solid rgba(232, 217, 192, 0.12);
  transition: border-color 0.15s, transform 0.15s;
}

.game-card:active {
  transform: scale(0.99);
}

.game-card-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
}

.game-card-title {
  font-weight: 700;
}

.game-card-meta {
  margin-top: 0.25rem;
  font-size: 0.88rem;
  color: var(--parchment-dim);
}

.game-card-actions {
  margin-top: 0.45rem;
}

.pill {
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: rgba(126, 184, 168, 0.18);
  color: var(--foam);
  font-weight: 600;
}

.pill-done {
  background: rgba(201, 162, 39, 0.2);
  color: var(--gold);
}

.home-foot {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(232, 217, 192, 0.08);
}

.home-foot-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
}

.build-hash {
  font-size: 0.7rem;
  opacity: 0.45;
  font-variant-numeric: tabular-nums;
}

.muted-link {
  color: var(--parchment-dim);
  text-decoration: none;
  font-size: 0.78rem;
}

.muted-link:hover {
  color: var(--foam);
  text-decoration: underline;
}

.linkish {
  color: var(--foam);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-size: 0.9rem;
}

.linkish.danger {
  color: var(--coral);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.85rem 1.2rem;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.02em;
  transition: transform 0.12s, filter 0.12s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: linear-gradient(180deg, #d46848, var(--coral));
  color: #fff8f0;
  box-shadow: 0 6px 18px rgba(196, 92, 62, 0.35);
}

.btn-secondary {
  background: rgba(232, 217, 192, 0.1);
  border: 1px solid rgba(232, 217, 192, 0.22);
  color: var(--parchment);
}

/* Bar */
.bar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.bar-title {
  font-family: var(--font-display);
  font-size: 1.45rem;
  margin: 0;
  font-weight: 400;
}

.bar-center {
  flex: 1;
  text-align: center;
}

.bar-sub {
  font-size: 0.78rem;
  color: var(--parchment-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.bar-spacer {
  width: 40px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--parchment);
  background: rgba(232, 217, 192, 0.06);
}

.icon-btn.danger {
  color: var(--coral);
}

/* Setup */
.setup-body {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--parchment-dim);
}

.field input,
.field select {
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  border: 1px solid rgba(232, 217, 192, 0.2);
  background: var(--bg2);
  color: var(--parchment);
}

.player-row-inputs {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.player-row-inputs input {
  flex: 1;
}

/* Play */
.play-progress {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-bottom: 0.85rem;
}

.play-progress .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(232, 217, 192, 0.18);
}

.play-progress .dot.done {
  background: var(--gold);
}

.play-progress .dot.current {
  background: var(--coral);
  box-shadow: 0 0 0 3px rgba(196, 92, 62, 0.25);
}

.play-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-bottom: 0.5rem;
}

.play-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
  padding: 0.5rem;
  margin-top: 0.5rem;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 999px;
  border: 1px solid rgba(232, 217, 192, 0.1);
}

.play-tabs .tab {
  padding: 0.55rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--parchment-dim);
}

.play-tabs .tab.active {
  background: var(--parchment);
  color: var(--ink);
}

/* Turn card */
.turn-card {
  background:
    linear-gradient(165deg, rgba(232, 217, 192, 0.14), transparent 40%),
    var(--bg2);
  border: 1px solid rgba(232, 217, 192, 0.16);
  border-radius: calc(var(--radius) + 4px);
  padding: 1.25rem 1.1rem 1.1rem;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.turn-who {
  font-family: var(--font-display);
  font-size: 1.85rem;
  margin: 0 0 0.35rem;
  text-align: center;
}

.eyebrow {
  display: block;
  font-family: var(--font-body);
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--foam);
  margin-bottom: 0.2rem;
}

.hint {
  text-align: center;
  color: var(--parchment-dim);
  margin: 0 0 1rem;
  font-size: 0.92rem;
}

.stepper {
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.stepper-btn {
  height: 64px;
  border-radius: 16px;
  background: rgba(232, 217, 192, 0.1);
  border: 1px solid rgba(232, 217, 192, 0.18);
  font-size: 1.5rem;
  font-weight: 700;
}

.stepper-value {
  text-align: center;
  font-size: 3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.bid-type-toggle,
.quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  margin-bottom: 0.85rem;
}

.chip {
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(232, 217, 192, 0.22);
  background: rgba(0, 0, 0, 0.2);
  font-size: 0.85rem;
  font-weight: 600;
}

.chip.active {
  background: var(--parchment);
  color: var(--ink);
  border-color: transparent;
}

.turn-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.roster {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  margin-top: 1.1rem;
  padding-top: 0.9rem;
  border-top: 1px dashed rgba(232, 217, 192, 0.15);
}

.roster-chip {
  font-size: 0.78rem;
  padding: 0.3rem 0.55rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--parchment-dim);
}

.roster-chip em {
  font-style: normal;
  font-weight: 700;
  color: var(--parchment);
  margin-left: 0.25rem;
}

.roster-chip.active {
  outline: 2px solid var(--coral);
  color: var(--parchment);
}

.roster-chip.set {
  background: rgba(61, 122, 74, 0.25);
}

/* Review / standings */
.review-list,
.standings-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}

.review-row,
.standings-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.65rem 0.25rem;
  border-bottom: 1px solid rgba(232, 217, 192, 0.1);
}

.standings-row {
  grid-template-columns: 2rem 1fr auto;
}

.standings-row.leader .name {
  color: var(--gold);
  font-weight: 700;
}

.rank {
  opacity: 0.5;
  font-variant-numeric: tabular-nums;
}

.score,
.pts,
.run {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.crown {
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--gold);
}

/* Scorepad */
.scorepad-scroll {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid rgba(232, 217, 192, 0.18);
  background: linear-gradient(180deg, #d9c7a5, #cbb892);
  color: var(--ink);
  padding: 0.35rem;
}

.scorepad {
  border-collapse: separate;
  border-spacing: 3px;
  width: max-content;
  min-width: 100%;
  font-size: 0.72rem;
}

.scorepad th,
.scorepad td {
  vertical-align: top;
}

.scorepad thead th {
  background: rgba(42, 33, 24, 0.12);
  padding: 0.45rem 0.35rem;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 400;
  min-width: 72px;
}

.scorepad .corner {
  min-width: 36px;
  position: sticky;
  left: 0;
  z-index: 1;
  background: #d4c19a;
}

.round-label {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #d4c19a;
  padding: 0.25rem;
  text-align: center;
}

.round-label .rn {
  display: block;
  font-weight: 700;
  font-size: 0.9rem;
}

.round-label .cards {
  display: block;
  font-size: 0.65rem;
  opacity: 0.65;
}

.cell {
  background: rgba(255, 252, 245, 0.55);
  border: 1px solid rgba(42, 33, 24, 0.2);
  border-radius: 4px;
  min-width: 76px;
  padding: 3px;
  min-height: 58px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cell-current {
  outline: 2px solid var(--coral);
}

.cell-done {
  background: rgba(255, 252, 245, 0.85);
}

.cell-row {
  display: flex;
  justify-content: space-between;
  gap: 2px;
}

.cell-row span {
  flex: 1;
  text-align: center;
  border: 1px solid rgba(42, 33, 24, 0.12);
  border-radius: 2px;
  padding: 1px 2px;
  font-variant-numeric: tabular-nums;
  min-height: 1.15rem;
}

.bid-result {
  font-weight: 700;
}

.running {
  font-weight: 700;
  background: rgba(201, 162, 39, 0.2);
}

.cell-round {
  text-align: center;
  font-weight: 700;
  font-size: 0.78rem;
  border-top: 1px dashed rgba(42, 33, 24, 0.2);
  padding-top: 2px;
}

.bid-type {
  margin-left: 2px;
}

.total-cell {
  text-align: center;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.4rem;
  background: rgba(42, 33, 24, 0.1);
}

.legend {
  margin: 0.4rem 0.2rem 0.2rem;
  font-size: 0.7rem;
  color: var(--ink-soft);
}

.muted {
  color: var(--parchment-dim);
}

/* Settings */
.settings-scroll {
  flex: 1;
  overflow: auto;
  padding-bottom: 1.5rem;
}

.settings-section {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--gold);
  margin: 1.25rem 0.35rem 0.45rem;
  font-weight: 600;
}

.settings-section:first-child {
  margin-top: 0.25rem;
}

.settings-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  text-align: left;
  padding: 0.9rem 0.45rem;
  border-bottom: 1px solid rgba(232, 217, 192, 0.1);
  color: var(--parchment);
  text-decoration: none;
  background: transparent;
}

.settings-row.static {
  cursor: default;
}

.settings-row:not(.static):active {
  background: rgba(232, 217, 192, 0.05);
}

.settings-label {
  font-size: 1rem;
  font-weight: 600;
}

.settings-sub {
  color: var(--parchment-dim);
  font-size: 0.85rem;
  margin-top: 0.2rem;
}

.switch {
  position: relative;
  width: 46px;
  height: 28px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(232, 217, 192, 0.18);
  transition: background 0.15s;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--parchment);
  transition: transform 0.15s;
}

.switch input:checked + .switch-track {
  background: var(--coral);
}

.switch input:checked + .switch-track::after {
  transform: translateX(18px);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--foam);
  outline-offset: 2px;
}

/* Sheet */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet[hidden] {
  display: none !important;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.sheet-panel {
  position: relative;
  width: min(560px, 100%);
  max-height: min(85dvh, 720px);
  background: var(--bg1);
  border-radius: 20px 20px 0 0;
  border: 1px solid rgba(232, 217, 192, 0.15);
  border-bottom: none;
  display: flex;
  flex-direction: column;
  animation: sheetUp 0.28s ease-out;
  padding-bottom: var(--safe-bot);
}

@keyframes sheetUp {
  from {
    transform: translateY(24px);
    opacity: 0.6;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(232, 217, 192, 0.1);
}

.sheet-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.5rem;
}

.sheet-body {
  overflow: auto;
  padding: 1rem 1.1rem 1.5rem;
}

.prose h3 {
  font-size: 1rem;
  margin: 1rem 0 0.4rem;
  color: var(--gold);
}

.prose ul {
  margin: 0;
  padding-left: 1.15rem;
}

.prose li {
  margin: 0.25rem 0;
}

.ref-img {
  width: 100%;
  max-width: 280px;
  display: block;
  margin: 1rem auto 0;
  border-radius: 8px;
  opacity: 0.9;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bot));
  transform: translateX(-50%);
  z-index: 50;
  background: var(--parchment);
  color: var(--ink);
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast[hidden] {
  display: none !important;
}

/* Tablet+ */
@media (min-width: 720px) {
  .app {
    padding-top: calc(24px + var(--safe-top));
  }

  .brand-mark {
    width: 120px;
    height: 120px;
  }

  .view-play {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto;
  }

  .scorepad {
    font-size: 0.8rem;
  }

  .cell {
    min-width: 88px;
    min-height: 64px;
  }

  .turn-card {
    max-width: 480px;
    margin: 0 auto;
  }

  .sheet {
    align-items: center;
  }

  .sheet-panel {
    border-radius: 20px;
    border-bottom: 1px solid rgba(232, 217, 192, 0.15);
  }
}

@media (min-width: 900px) and (orientation: landscape) {
  .app[data-view="play"] {
    max-width: 1100px;
  }
}
