/* Klondike — 3D solitaire on a felt table. HUD styling. */

:root {
  --ink: #f6efe2;
  --ink-dim: rgba(246, 239, 226, 0.62);
  --ink-faint: rgba(246, 239, 226, 0.38);
  --gold: #e3c37c;
  --gold-deep: #b8924c;
  --panel: rgba(16, 18, 22, 0.52);
  --panel-solid: rgba(18, 20, 25, 0.94);
  --line: rgba(246, 239, 226, 0.14);
  --good: #7fd0a2;
  --warn: #f0b76a;
  --radius: 14px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --sans: "Avenir Next", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #08090b;
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  /* warm lamp overhead, cool falloff at the edges */
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(255, 226, 176, 0.16) 0%, rgba(255, 226, 176, 0) 55%),
    radial-gradient(90% 70% at 50% 42%, #1a1e24 0%, #101319 45%, #06070a 100%);
}

#app { position: fixed; inset: 0; }

#table {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: default;
}

/* ------------------------------------------------------------------- hud */

.hud { position: absolute; inset: 0; pointer-events: none; }
.hud > * { pointer-events: auto; }
/* the top scrim spans the full width — only its panels may take clicks, so a
   card that slides underneath stays grabbable */
.topbar { pointer-events: none; }
.topbar > * { pointer-events: auto; }

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  gap: 18px;
  padding: 14px 18px 10px;
  background: linear-gradient(180deg, rgba(6, 7, 9, 0.82) 0%, rgba(6, 7, 9, 0.42) 62%, rgba(6, 7, 9, 0) 100%);
}

.brand { display: flex; gap: 11px; align-items: center; min-width: 150px; }

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  position: relative;
  background: linear-gradient(160deg, #22272f, #12151a);
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 6px 16px rgba(0, 0, 0, 0.5);
  font-size: 17px;
  line-height: 1;
}
.brand-mark .s { position: absolute; top: 7px; left: 9px; color: #eef2f7; }
.brand-mark .h { position: absolute; bottom: 7px; right: 9px; color: #e0596b; }

.brand-text h1 {
  margin: 0;
  font: 500 20px/1.05 var(--serif);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.brand-text p {
  margin: 3px 0 0;
  font-size: 11.5px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  text-transform: uppercase;
}

.stats {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  padding: 7px 10px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: var(--shadow);
}

.stat { display: flex; flex-direction: column; gap: 1px; padding: 2px 9px; min-width: 58px; }
.stat .k {
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: flex;
  gap: 6px;
  align-items: center;
}
.stat .k b { color: var(--ink-dim); font-weight: 600; letter-spacing: 0.02em; }
.stat b { font: 500 19px/1.15 var(--serif); font-variant-numeric: tabular-nums; }
.stat.grow { flex: 1; min-width: 120px; }

.progress {
  height: 5px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  margin-top: 5px;
}
.progress i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold));
  transition: width 0.35s cubic-bezier(0.22, 0.7, 0.2, 1);
  box-shadow: 0 0 12px rgba(227, 195, 124, 0.5);
}

.pips { display: flex; gap: 8px; margin-top: 4px; font-size: 11px; color: var(--ink-faint); }
.pip { position: relative; }
.pip::after { content: ""; }
.pip[data-suit="H"], .pip[data-suit="D"] { color: #e0596b; }
.pip[data-suit="H"]::after { content: "♥"; margin-left: 3px; }
.pip[data-suit="D"]::after { content: "♦"; margin-left: 3px; }
.pip[data-suit="S"]::after { content: "♠"; margin-left: 3px; }
.pip[data-suit="C"]::after { content: "♣"; margin-left: 3px; }

.actions { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(43, 48, 57, 0.9), rgba(24, 27, 33, 0.9));
  color: var(--ink);
  font: 500 12.5px/1 var(--sans);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.14s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); border-color: rgba(227, 195, 124, 0.5); background: linear-gradient(180deg, rgba(56, 62, 74, 0.95), rgba(30, 34, 41, 0.95)); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn[disabled] { opacity: 0.36; cursor: default; transform: none; }
.btn.primary {
  background: linear-gradient(180deg, #e6c884, #bb9148);
  color: #1b1509;
  border-color: rgba(255, 235, 190, 0.5);
  font-weight: 700;
}
.btn.primary:hover { background: linear-gradient(180deg, #f0d69a, #c69b52); }
.btn.ghost { background: rgba(255, 255, 255, 0.04); }
.btn.icon { padding: 10px 11px; font-size: 14px; line-height: 1; }

/* ------------------------------------------------------------------ dock */

.dock {
  position: absolute;
  left: 18px;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 9px 14px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: var(--shadow);
  max-width: calc(100vw - 36px);
  overflow-x: auto;
  scrollbar-width: none;
}
.dock::-webkit-scrollbar { display: none; }
.dock-group { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.dock-label {
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.dock .check { cursor: pointer; color: var(--ink-dim); font-size: 12.5px; }
.dock .check input { accent-color: var(--gold); width: 15px; height: 15px; cursor: pointer; }

.segmented {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
}
.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  font: 600 12px/1 var(--sans);
  padding: 7px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}
.segmented button:hover { color: var(--ink); }
.segmented button.active { background: linear-gradient(180deg, #e6c884, #bb9148); color: #1b1509; }
.segmented button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

.swatches { display: flex; gap: 6px; }
.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.3), rgba(0, 0, 0, 0.25) 72%), var(--sw);
  transition: transform 0.16s ease, box-shadow 0.2s ease;
}
.swatch:hover { transform: translateY(-2px) scale(1.06); }
.swatch.active { box-shadow: 0 0 0 2px #0b0d10, 0 0 0 4px var(--gold); }
.swatch:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

/* ---------------------------------------------------------------- toasts */

.toasts {
  position: absolute;
  left: 50%;
  bottom: 78px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  padding: 9px 16px;
  border-radius: 99px;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px) scale(0.96);
  transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.toast.show { opacity: 1; transform: translateY(0) scale(1); }
.toast.warn { border-color: rgba(240, 183, 106, 0.5); color: #ffe3bd; }
.toast.ok { border-color: rgba(127, 208, 162, 0.42); color: #dff5e6; }

/* ----------------------------------------------------------------- modal */

.modal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 5, 7, 0.62);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 20;
  animation: fade 0.22s ease;
}
.modal.hidden { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: min(560px, calc(100vw - 40px));
  max-height: min(82vh, 720px);
  overflow: auto;
  background: linear-gradient(180deg, rgba(26, 29, 35, 0.98), rgba(15, 17, 21, 0.98));
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 40px 80px rgba(0, 0, 0, 0.6);
  padding: 20px 24px 24px;
  animation: rise 0.28s cubic-bezier(0.2, 0.9, 0.25, 1);
}
.sheet.small { width: min(420px, calc(100vw - 40px)); }
@keyframes rise { from { transform: translateY(14px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }

.sheet header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.sheet h3 { margin: 0; font: 500 24px/1.1 var(--serif); letter-spacing: 0.02em; }
.sheet h4 { margin: 18px 0 6px; font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold); }
.sheet p, .sheet li { color: var(--ink-dim); font-size: 14px; line-height: 1.6; }
.sheet ul { margin: 8px 0 0; padding-left: 18px; display: grid; gap: 5px; }
.sheet b { color: var(--ink); font-weight: 600; }
.sheet .row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.score-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.score-table td { padding: 6px 0; border-bottom: 1px dashed rgba(246, 239, 226, 0.1); color: var(--ink-dim); }
.score-table td:last-child { text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }

.keys { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 12.5px; color: var(--ink-faint); }
kbd {
  font: 600 11px/1 var(--sans);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 4px 6px;
  color: var(--ink);
  margin-right: 4px;
}

/* win sheet */
.sheet.win { text-align: center; width: min(460px, calc(100vw - 40px)); }
.win-mark { font-size: 22px; letter-spacing: 0.36em; color: var(--gold); opacity: 0.85; }
.sheet.win h3 { margin: 10px 0 2px; font-size: 34px; }
.win-sub { margin: 0 0 16px; color: var(--ink-faint); }
.win-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.win-stats > div {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 6px;
}
.win-stats span { display: block; font-size: 9.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint); }
.win-stats b { display: block; margin-top: 4px; font: 500 21px/1 var(--serif); font-variant-numeric: tabular-nums; }
.win-stats .muted { opacity: 0.65; }
.sheet.win .row { justify-content: center; }

/* --------------------------------------------------------------- loader */

.loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 40;
  background:
    radial-gradient(70% 55% at 50% 40%, rgba(255, 226, 176, 0.09), rgba(0, 0, 0, 0) 70%),
    #08090b;
  transition: opacity 0.5s ease, visibility 0.5s;
}
.loader.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-card { text-align: center; width: min(320px, 80vw); }
.loader-suits { font-size: 20px; letter-spacing: 0.4em; color: var(--ink-dim); }
.loader-suits .red { color: #e0596b; }
.loader-card h2 { margin: 8px 0 2px; font: 500 30px/1 var(--serif); letter-spacing: 0.22em; text-transform: uppercase; }
.bar-label { margin: 14px 0 8px; font-size: 11.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint); }
.bar { height: 3px; border-radius: 99px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.bar i { display: block; height: 100%; width: 8%; background: linear-gradient(90deg, var(--gold-deep), var(--gold)); transition: width 0.18s ease; }

/* ----------------------------------------------------------- responsive */

.short { display: none; }

@media (max-width: 1100px) {
  .stat.hide-sm { display: none; }
}
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 9px 10px 7px; }
  .brand-text p { display: none; }
  .stats { order: 3; width: 100%; padding: 5px 8px; gap: 2px; }
  .actions { order: 2; margin-left: auto; }
  .btn { padding: 9px 11px; font-size: 11.5px; }
  .dock { left: 10px; right: 10px; bottom: 10px; gap: 12px; }
  .toasts { bottom: 88px; }
}
@media (max-width: 620px) {
  .topbar { padding: 7px 8px 6px; }
  .brand { display: none; }
  .stat { min-width: 42px; padding: 1px 6px; }
  .stat b { font-size: 15px; }
  .stat .k { font-size: 8.5px; }
  .stat.grow { min-width: 90px; }
  .btn { padding: 8px 9px; font-size: 10.5px; border-radius: 9px; }
  .dock { padding: 6px 9px; gap: 10px; bottom: 8px; }
  .dock-label { font-size: 8.5px; }
  .segmented button { padding: 6px 10px; font-size: 11px; }
  .swatch { width: 18px; height: 18px; }
  .dock .check { font-size: 11px; }
  .long { display: none; }
  .short { display: inline; }
  .toasts { bottom: 74px; }
}

/* short viewports — phones in landscape, small windows: collapse to one row */
@media (max-height: 520px) {
  .topbar {
    flex-wrap: nowrap;
    gap: 10px;
    padding: 6px 10px 5px;
    background: linear-gradient(180deg, rgba(6, 7, 9, 0.86) 0%, rgba(6, 7, 9, 0.45) 70%, rgba(6, 7, 9, 0) 100%);
  }
  .brand { min-width: 0; }
  .brand-mark { width: 30px; height: 30px; border-radius: 9px; font-size: 13px; }
  .brand-text { display: none; }
  .stats { order: 0; width: auto; flex: 1 1 auto; min-width: 0; padding: 4px 6px; gap: 0; }
  .stat { min-width: 34px; padding: 1px 6px; white-space: nowrap; }
  .stat b { font-size: 13px; }
  .stat .k { font-size: 8px; }
  .stat.hide-sm { display: none; }
  .stat.grow { min-width: 60px; gap: 0; }
  .stat.grow .progress,
  .stat.grow .pips { display: none; }
  .actions { margin-left: 0; gap: 6px; flex-wrap: nowrap; }
  .btn { padding: 7px 9px; font-size: 10.5px; border-radius: 9px; white-space: nowrap; }
  .dock { bottom: 6px; left: 10px; right: 10px; padding: 5px 10px; gap: 11px; }
  .dock-label { display: none; }
  .dock .check { font-size: 11px; }
  .dock .check .long { display: none; }
  .dock .check .short { display: inline; }
  .segmented button { padding: 5px 10px; font-size: 11px; }
  .swatch { width: 16px; height: 16px; }
  .toasts { bottom: 54px; }
}
@media (max-height: 520px) and (max-width: 640px) {
  .stat.grow { display: none; }
  .brand-mark { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.05ms !important; }
}

/* ---------------------------------------------------------- touch / iOS */
/* In a native shell (and on phones generally) three things have to change:
   the chrome must dodge the notch and the home indicator, hit targets must be
   big enough for a thumb, and the shell's own gestures — text selection,
   long-press callouts, rubber-band scrolling — must not compete with the
   cards. This block comes last so it outranks the compact-viewport rules,
   which would otherwise shrink the cloth swatches to 16px on a phone. */

html, body {
  position: fixed;
  inset: 0;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* the rules sheet is prose; it stays selectable for copy and screen readers */
.sheet, .sheet * { -webkit-user-select: text; user-select: text; }

.topbar {
  padding-top: calc(14px + env(safe-area-inset-top));
  padding-right: calc(18px + env(safe-area-inset-right));
  padding-left: calc(18px + env(safe-area-inset-left));
}

.dock {
  left: calc(18px + env(safe-area-inset-left));
  bottom: calc(16px + env(safe-area-inset-bottom));
}

.toasts { bottom: calc(78px + env(safe-area-inset-bottom)); }

.sheet {
  width: min(560px, calc(100vw - 32px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  max-height: calc(100vh - 40px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  padding-left: calc(24px + env(safe-area-inset-left) * 0.6);
  padding-right: calc(24px + env(safe-area-inset-right) * 0.6);
}

@media (pointer: coarse) {
  .btn {
    padding: 12px 15px;
    min-height: 44px;
    font-size: 12px;
    border-radius: 11px;
  }
  .btn.icon { min-width: 44px; padding: 12px 0; }
  .segmented { padding: 3px; }
  .segmented button { padding: 10px 16px; min-height: 38px; font-size: 12px; }
  .swatches { gap: 9px; }
  .swatch, .dock .swatch { width: 28px; height: 28px; }
  .dock .check input[type="checkbox"] { width: 20px; height: 20px; }
  .dock {
    gap: 14px;
    left: calc(14px + env(safe-area-inset-left));
    right: calc(14px + env(safe-area-inset-right));
    bottom: calc(14px + env(safe-area-inset-bottom));
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .stat { min-width: 54px; }
  .stat.grow { display: flex; }
  .brand-mark { display: grid; }
  /* fingers are not hover devices: make the pressed state the only state */
  .swatch:hover, .btn:hover { transform: none; }
  .btn:active { transform: translateY(1px); filter: brightness(1.16); }
}
