/* Deck Workout
   Type: one family, two weights (500/800), four sizes (14/18/28/display).
   Space: 4/8-point grid. Colour: 60% tinted-dark base, 30% off-white, 10% lime accent.
   Red appears only on red suits. */

:root {
  --bg: #0e1613;
  --surface: #17221d;
  --line: #2a3a32;
  --text: #eef4ec;
  --text-2: rgba(238, 244, 236, 0.8);
  --text-3: rgba(238, 244, 236, 0.62);
  --accent: #c8f53a;
  --accent-ink: #151d06;
  --accent-soft: rgba(200, 245, 58, 0.08);
  --card: #f6f4ec;
  --ink: #17201c;
  --red: #d42b42;

  --fs-s: 0.875rem;
  --fs-m: 1.125rem;
  --fs-l: 1.75rem;
  --font: "Bricolage Grotesque", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 500 var(--fs-m)/1.35 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

.sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

h1, h2, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }

h1 { font-size: clamp(2.5rem, 12vw, 3.5rem); font-weight: 800; line-height: 1; letter-spacing: -0.02em; }

h2 {
  font-size: var(--fs-s); font-weight: 500; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Screens ---------- */

.screen {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(var(--safe-t) + 24px) 16px 0;
}

.masthead { padding: 24px 0 32px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { flex: none; width: clamp(2.5rem, 12vw, 3.5rem); height: auto; border-radius: 22.5%; }
.brand h1 { font-size: clamp(2rem, 10.5vw, 3.5rem); white-space: nowrap; }
.eyebrow { font-size: var(--fs-s); color: var(--accent); letter-spacing: 0.02em; margin-bottom: 8px; }
.tagline { font-size: var(--fs-s); color: var(--accent); letter-spacing: 0.02em; margin-top: 12px; }

section { margin-bottom: 32px; }

/* Sticky action bar: primary actions live in the thumb zone. */
.actions {
  position: sticky; bottom: 0;
  display: grid; grid-template-columns: 1fr 2fr; gap: 8px;
  padding: 16px 0 calc(var(--safe-b) + 16px);
  background: linear-gradient(to bottom, transparent, var(--bg) 24%);
}

/* ---------- Buttons ---------- */

.btn {
  min-height: 56px; padding: 0 20px;
  border: 0; border-radius: 16px;
  font-weight: 800; font-size: var(--fs-m);
  transition: transform 120ms var(--ease), background-color 120ms var(--ease);
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent); color: var(--accent-ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), 0 8px 24px -8px rgba(200, 245, 58, 0.35);
}
.btn-secondary { background: var(--surface); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.btn-quiet { background: transparent; color: var(--text-2); font-weight: 500; }
.btn-small { min-height: 44px; border-radius: 12px; background: var(--accent); color: var(--accent-ink); }

.icon-btn {
  width: 48px; height: 48px; margin-left: -12px;
  display: grid; place-items: center;
  background: transparent; border: 0; border-radius: 12px;
  fill: var(--text);
}
.icon-btn:active { background: var(--surface); }

/* ---------- Setup ---------- */

.resume {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px; margin-bottom: 32px;
  background: var(--accent-soft); border-radius: 16px;
  box-shadow: inset 0 0 0 1px rgba(200, 245, 58, 0.25);
}
.resume p { display: grid; gap: 4px; }
.resume span { font-size: var(--fs-s); color: var(--text-2); }
.resume-actions { display: flex; align-items: center; gap: 4px; }
.resume .btn-quiet { min-height: 44px; padding: 0 12px; font-size: var(--fs-s); }

.suit-row {
  display: grid; grid-template-columns: 40px 1fr; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--line);
}
.suit-row:focus-within { border-color: var(--accent); }

.glyph { font-size: var(--fs-l); line-height: 1; text-align: center; color: var(--text); }
.glyph.red { color: var(--red); }
.glyph.accent { color: var(--accent); }

/* The joker glyph doubles as the on/off switch for jokers. */
.glyph-btn {
  position: relative; display: grid; place-items: center;
  width: 40px; height: 56px; padding: 0; border: 0; border-radius: 12px; background: transparent;
  transition: color 160ms var(--ease), transform 120ms var(--ease);
}
.glyph-btn svg { width: 36px; height: 33px; }
.glyph-btn:active { transform: scale(0.9); }
.glyph-btn[aria-pressed="false"] { color: var(--text-3); }
.glyph-btn[aria-pressed="false"]::after {
  content: ""; position: absolute; width: 34px; height: 2px; border-radius: 2px;
  background: currentColor; box-shadow: 0 0 0 2px var(--bg); transform: rotate(-45deg);
}
h2 small { font: inherit; text-transform: none; letter-spacing: 0.02em; margin-left: 6px; }
h2 small::before { content: "· "; }
.jokers-off input[type="text"], .jokers-off .row { opacity: 0.4; }
.jokers-off .suit-row { border-color: var(--line); }

input[type="text"] {
  width: 100%; min-height: 56px; padding: 0;
  background: transparent; border: 0; outline: 0; border-radius: 0;
  font-size: var(--fs-l); font-weight: 800; letter-spacing: -0.01em;
}
input[type="text"]::placeholder { color: var(--text-3); font-weight: 500; }
.suit-row.invalid { border-color: var(--red); }

.row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 64px; padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.row-label small {
  display: block; margin-top: 4px; max-width: 32ch;
  font-size: var(--fs-s); color: var(--text-3); line-height: 1.4;
}

.tag {
  display: inline-block; margin-left: 4px; padding: 2px 8px; vertical-align: 2px;
  border-radius: 8px; background: var(--accent-soft); color: var(--accent);
  font-size: 0.6875rem; font-style: normal; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
}

.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 48px; height: 48px;
  background: var(--surface); border: 0; border-radius: 12px;
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: var(--fs-l); line-height: 1;
}
.stepper button:active { background: var(--line); }
.stepper output {
  min-width: 56px; text-align: center;
  font-size: var(--fs-l); font-weight: 800; font-variant-numeric: tabular-nums;
}

.segmented {
  display: flex; padding: 4px; gap: 4px;
  background: var(--surface); border-radius: 12px;
  box-shadow: inset 0 0 0 1px var(--line);
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: grid; place-items: center;
  min-height: 40px; min-width: 56px; padding: 0 12px;
  border-radius: 8px; font-size: var(--fs-s); color: var(--text-2); white-space: nowrap;
  transition: background-color 120ms var(--ease), color 120ms var(--ease);
}
.segmented input:checked + span { background: var(--text); color: var(--bg); font-weight: 800; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.switch {
  appearance: none; -webkit-appearance: none;
  flex: none; position: relative;
  width: 56px; height: 32px; margin: 0;
  background: var(--line); border-radius: 16px;
  transition: background-color 160ms var(--ease);
  cursor: pointer;
}
.switch::after {
  content: ""; position: absolute; top: 4px; left: 4px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--text);
  transition: transform 160ms var(--ease), background-color 160ms var(--ease);
}
.switch:checked { background: var(--accent); }
.switch:disabled { opacity: 0.4; cursor: not-allowed; }
.row.unavailable .row-label { color: var(--text-2); }
.switch:checked::after { transform: translateX(24px); background: var(--accent-ink); }

/* ---------- Workout ---------- */

#workout {
  height: 100dvh; min-height: 0;
  display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  padding-top: calc(var(--safe-t) + 8px);
}

.topbar { display: flex; align-items: center; gap: 8px; min-height: 48px; }

.mic {
  min-height: 36px; padding: 0 12px 0 8px; border: 0; border-radius: 18px; font: inherit;
  display: flex; align-items: center; gap: 4px;
  font-size: var(--fs-s); fill: currentColor;
  background: var(--surface); color: var(--text-3); box-shadow: inset 0 0 0 1px var(--line);
  transition: background-color 200ms var(--ease), color 200ms var(--ease);
}
.mic .slash { stroke: currentColor; }
.mic[data-status="listening"] { background: var(--accent); color: var(--accent-ink); box-shadow: none; font-weight: 800; }
.mic[data-status="listening"] .slash { display: none; }
.mic[data-status="denied"] { color: var(--red); box-shadow: inset 0 0 0 1px var(--red); }
.mic[data-status="tap"] { color: var(--text); box-shadow: inset 0 0 0 1px var(--text-3); }
.mic-log {
  position: fixed; top: calc(var(--safe-t) + 64px); left: 16px; right: 16px; z-index: 5;
  margin: 0; padding: 12px 16px; max-height: 40vh; overflow: auto;
  background: var(--surface); color: var(--text-2); border-radius: 12px;
  box-shadow: inset 0 0 0 1px var(--line), 0 16px 32px -8px rgba(3, 10, 7, 0.8);
  font: 500 12px/1.5 ui-monospace, Menlo, monospace; white-space: pre-wrap;
}

.meta {
  margin-left: auto; display: flex; align-items: baseline; gap: 16px;
  font-variant-numeric: tabular-nums;
}
#count { font-size: var(--fs-s); color: var(--text-2); }
.clock { font-size: var(--fs-l); font-weight: 800; }

.progress { height: 4px; border-radius: 2px; background: var(--surface); overflow: hidden; }
#progress-fill {
  height: 100%; width: 100%; background: var(--accent); border-radius: 2px;
  transform-origin: left; transform: scaleX(0);
  transition: transform 240ms var(--ease);
}

.stage {
  display: grid; place-items: center;
  width: 100%; min-height: 0; padding: 24px 0 16px;
  background: transparent; border: 0; container-type: size;
}

.card {
  --suit: var(--ink);
  position: relative; display: grid; place-items: center;
  /* Largest 5:7 card that fits the stage. */
  height: min(100cqh, 140cqw); aspect-ratio: 5 / 7;
  background: var(--card); color: var(--suit);
  border-radius: 7% / 5%; overflow: hidden;
  box-shadow: 0 24px 48px -16px rgba(3, 10, 7, 0.8), inset 0 0 0 1px rgba(23, 32, 28, 0.08);
  user-select: none; -webkit-user-select: none;
}
.card[data-suit="hearts"], .card[data-suit="diamonds"] { --suit: var(--red); }

.card svg { display: block; width: 100%; height: 100%; }

.card[data-suit="joker"] {
  background: var(--ink); --suit: var(--accent);
  box-shadow: 0 24px 48px -16px rgba(3, 10, 7, 0.8), inset 0 0 0 2px var(--accent), 0 0 64px -16px rgba(200, 245, 58, 0.4);
}

.card[data-suit="back"] {
  background:
    repeating-linear-gradient(45deg, transparent 0 10px, rgba(200, 245, 58, 0.14) 10px 12px),
    repeating-linear-gradient(-45deg, transparent 0 10px, rgba(200, 245, 58, 0.14) 10px 12px),
    var(--surface);
  box-shadow: 0 24px 48px -16px rgba(3, 10, 7, 0.8), inset 0 0 0 1px var(--line), inset 0 0 0 10px var(--surface), inset 0 0 0 11px var(--line);
}

.card.resting { opacity: 0.35; transition: opacity 240ms var(--ease); }

.card.enter { animation: deal 240ms var(--ease) both; }
.card.enter-back { animation: undeal 240ms var(--ease) both; }
@keyframes deal { from { opacity: 0; transform: translateY(16px) scale(0.96) rotate(-2deg); } }
@keyframes undeal { from { opacity: 0; transform: translateY(-16px) scale(0.96) rotate(2deg); } }

.callout { text-align: center; padding: 0 0 8px; min-height: 104px; }
.instruction {
  font-size: clamp(2.25rem, 11vw, 3.5rem); font-weight: 800; line-height: 1.05; letter-spacing: -0.02em;
  text-wrap: balance; overflow-wrap: anywhere;
}
.instruction.countdown { font-variant-numeric: tabular-nums; color: var(--accent); }
.sub { margin-top: 8px; font-size: var(--fs-s); color: var(--text-3); }

/* ---------- Summary ---------- */

.finish { padding-top: 48px; }
.final-time {
  font-size: clamp(4.5rem, 24vw, 7rem); font-variant-numeric: tabular-nums; color: var(--accent);
  text-shadow: 0 0 64px rgba(200, 245, 58, 0.35);
  animation: deal 480ms var(--ease) both;
}
.final-reps { margin-top: 16px; color: var(--text-2); }

.totals li {
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  padding: 16px 0; border-bottom: 1px solid var(--line);
  font-size: var(--fs-l); font-weight: 800;
}
.totals li span:last-child { font-variant-numeric: tabular-nums; }
#summary { display: grid; grid-template-rows: auto 1fr auto; }

/* ---------- Pause menu ---------- */

.menu {
  width: min(100% - 32px, 420px); padding: 24px;
  background: var(--surface); color: var(--text);
  border: 0; border-radius: 24px;
  box-shadow: inset 0 0 0 1px var(--line), 0 32px 64px -16px rgba(3, 10, 7, 0.9);
}
.menu::backdrop { background: rgba(8, 14, 11, 0.72); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.menu[open] { animation: deal 200ms var(--ease) both; }
.menu h2 { font-size: var(--fs-l); font-weight: 800; color: var(--text); text-transform: none; letter-spacing: -0.01em; margin-bottom: 8px; }
.menu-actions { display: grid; gap: 8px; margin-top: 24px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 104px); transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 32px); padding: 12px 20px;
  background: var(--text); color: var(--bg);
  border-radius: 24px; font-size: var(--fs-s); text-align: center;
  animation: deal 200ms var(--ease) both; z-index: 10;
}

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

/* Landscape phones: card left, callout right. */
@media (orientation: landscape) and (max-height: 520px) {
  #workout {
    max-width: none;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-columns: 1fr 1fr; column-gap: 24px;
  }
  .topbar, .progress { grid-column: 1 / -1; }
  .stage { grid-row: 3 / 5; padding: 12px 0; }
  .callout { align-self: end; }
  .actions { position: static; }
}
