/* ---- reset ------------------------------------------------------------- */

/* `hidden` is only a UA stylesheet rule, so any author `display` beats it.
   Making it !important here keeps the attribute authoritative everywhere. */
[hidden] { display: none !important; }

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

html, body {
  height: 100%;
  margin: 0;
}

body {
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

:root {
  --bg: #0e1017;
  --felt-a: #1b2233;
  --felt-b: #12151f;
  --panel: rgba(23, 27, 40, 0.86);
  --panel-line: rgba(255, 255, 255, 0.10);
  --ink: #e8ecf6;
  --ink-dim: #9aa4bd;
  --accent: #6ea8fe;
  --accent-ink: #08111f;
  --good: #63d7a4;
  --radius: 10px;
}

/* ---- shell ------------------------------------------------------------- */

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  padding: 10px max(12px, env(safe-area-inset-left)) 10px max(12px, env(safe-area-inset-right));
  background: var(--panel);
  border-bottom: 1px solid var(--panel-line);
  backdrop-filter: blur(8px);
}

.brand {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.2px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-mark { font-size: 19px; }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-left: auto;
}

.field { display: flex; align-items: center; gap: 6px; }
.field-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
}

select, .btn, .tool {
  font: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  padding: 6px 10px;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, transform 60ms;
}
select { padding-right: 6px; }
select option { color: #101320; background: #eef1f8; }

.btn:hover, .tool:hover, select:hover { background: rgba(255, 255, 255, 0.12); }
.btn:active, .tool:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-primary:hover { background: #8bbcff; }

:where(select, .btn, .tool, input):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.check {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-dim);
  cursor: pointer;
  user-select: none;
}
.check input { accent-color: var(--accent); width: 15px; height: 15px; }
.check:hover { color: var(--ink); }

/* ---- stage ------------------------------------------------------------- */

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 0%, var(--felt-a), var(--felt-b) 70%);
  /* The HUD sizes itself against the table, not the viewport, so it keeps its
     proportions when the stage is a short landscape strip on a phone. */
  container-type: size;
  touch-action: none;
}

#table {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}
#table.dragging { cursor: grabbing; }

.hud {
  position: absolute;
  top: clamp(8px, 2.5cqh, 16px);
  display: flex;
  gap: 8px;
  pointer-events: none;
}
.hud-left {
  left: clamp(8px, 2.5cqw, 16px);
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  min-width: clamp(120px, 20cqw, 168px);
}
.hud-right {
  right: clamp(8px, 2.5cqw, 16px);
  flex-direction: column;
  align-items: stretch;
  pointer-events: auto;
}

.stat { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.stat-key {
  font-size: clamp(9px, 2.6cqh, 11px);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
}
.stat-val {
  font-size: clamp(12px, 3.4cqh, 15px);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.progress {
  margin-top: 7px;
  height: 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.progress i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), var(--good));
  transition: width 220ms ease-out;
}

.tool {
  font-size: clamp(11px, 3cqh, 13px);
  padding: 6px 12px;
  margin-bottom: 6px;
  background: var(--panel);
  text-align: center;
}
.tool[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 600;
}

.peek {
  position: absolute;
  right: clamp(8px, 2.5cqw, 16px);
  bottom: clamp(8px, 2.5cqh, 16px);
  margin: 0;
  padding: 5px;
  width: clamp(140px, 26cqw, 260px);
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.peek img { display: block; width: 100%; border-radius: 7px; }

/* ---- win overlay ------------------------------------------------------- */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(8, 10, 16, 0.62);
  backdrop-filter: blur(3px);
  animation: fade 260ms ease-out;
}
@keyframes fade { from { opacity: 0; } }

.card {
  width: min(380px, 100%);
  padding: 22px 24px;
  border-radius: 16px;
  background: #171b28;
  border: 1px solid var(--panel-line);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  text-align: center;
}
.card-kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--good);
}
.card-title { margin: 6px 0 18px; font-size: 22px; }

.card-stats {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin: 0 0 20px;
}
.card-stats div { display: flex; flex-direction: column; gap: 2px; }
.card-stats dt {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
}
.card-stats dd {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.card-actions { display: flex; gap: 10px; justify-content: center; }

/* ---- toast ------------------------------------------------------------- */

.toast {
  position: absolute;
  left: 50%;
  bottom: clamp(10px, 4cqh, 26px);
  transform: translateX(-50%);
  margin: 0;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  font-size: 13px;
  pointer-events: none;
  animation: rise 200ms ease-out;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---- footer ------------------------------------------------------------ */

.footbar {
  padding: 7px 14px calc(7px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--panel-line);
}
.hint-text {
  margin: 0;
  font-size: 12px;
  color: var(--ink-dim);
  text-align: center;
}
kbd {
  font: inherit;
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid var(--panel-line);
  background: rgba(255, 255, 255, 0.07);
}

@media (max-width: 620px) {
  .brand-name { display: none; }
  .field-label { display: none; }
  .footbar { display: none; }
  .peek { width: clamp(110px, 34cqw, 180px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
