/* Clock Out — the whole look.
 *
 * Motion rules, same as the desktop games: transforms and opacity only, nothing loops, every
 * animation bounded. --t is the one duration; the motion setting scales it, and
 * prefers-reduced-motion zeroes it. */

:root {
  --t: 180ms;

  --ground: #14110f;
  --panel: #1d1917;
  --panel-deep: #171412;
  --edge: #2e2926;
  --text: #f0eae0;
  --dim: #a2968a;
  --faint: #6b6058;

  --accent: #e0a33e;
  --accent-soft: #4a3820;
  --good: #7fbf6a;
  --good-soft: #223a20;
  --danger: #d4553f;
  --danger-soft: #3e1f19;
  --ghost: #8fb6e8;

  --card-face: #ede3d0;
  --card-face-2: #e3d8c2;
  --card-edge: #c9b99a;
  --card-ink: #1c1917;

  --colleague: #2f5a78;   /* clubs: a slate blue */
  --deadline: #7a2f2a;    /* spades: dried red */
  --coffee: #7a4a1e;      /* hearts: roast */
  --excuse: #3f6b3a;      /* diamonds: a plausible green */

  --card-w: clamp(118px, 20vw, 170px);
  --radius: 12px;
}

html[data-motion="fast"] { --t: 90ms; }
html[data-motion="instant"] { --t: 0ms; }
/* This has to out-specify the tier rules above and still let an explicit Full through.
   `:root` alone is (0,1,0) and loses to `html[data-motion="fast"]` at (0,1,1), so a
   reduced-motion player who chose Fast kept their animation - while one who deliberately
   chose Full was forced to zero, since nothing outranked the media query in that direction.
   Both were backwards. `html:not([data-motion="full"])` ties the tiers, comes later, and
   wins - except where the player has said Full, which is the one case it should lose. */
@media (prefers-reduced-motion: reduce) {
  html:not([data-motion="full"]) { --t: 0ms; }
}

* { box-sizing: border-box; }

/* The hidden attribute must beat any display rule below, or a "hidden" slot keeps showing. */
[hidden] { display: none !important; }

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

body {
  background: var(--ground);
  color: var(--text);
  font: 14px/1.4 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: var(--text);
  background: #262220;
  border: 1px solid var(--edge);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: border-color var(--t), background-color var(--t), transform var(--t), opacity var(--t);
}
button:hover { border-color: var(--accent); background: #332d29; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.35; cursor: default; }
button:disabled:hover { border-color: var(--edge); background: #262220; }
button.primary { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
button.primary:hover { background: #6b5028; }

.caption { font-size: 10px; font-weight: 600; letter-spacing: 0.08em; color: var(--faint); }
.dim { color: var(--faint); }

/* ---------------------------------------------------------------- Layout */

.app {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: start;
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px;
  gap: 12px;
}

.top {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 24px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 12px 18px;
}

.wordmark { font-family: Georgia, "Times New Roman", serif; font-weight: 700; font-size: 15px; color: var(--accent); letter-spacing: 0.04em; }
.day { font-family: Consolas, "Cascadia Mono", monospace; font-size: 18px; margin-top: 2px; }
.day .daily { color: var(--good); font-size: 11px; margin-left: 6px; letter-spacing: 0.06em; }

.clock { text-align: center; min-width: 120px; }
.clock .time { font-family: Consolas, "Cascadia Mono", monospace; font-size: 28px; line-height: 1; transition: color var(--t); }
.clock .hour { font-size: 11px; color: var(--faint); margin-top: 4px; min-height: 14px; }
.clock.last .time { color: var(--accent); }
.clock.last .hour { color: var(--accent); }

.patience { min-width: 240px; }
.patience-head { display: flex; justify-content: space-between; align-items: baseline; }
.patience-number { font-family: Consolas, "Cascadia Mono", monospace; font-size: 22px; }
.patience-number b { font-weight: 700; transition: color var(--t); display: inline-block; }
.patience-number b.bump { animation: bump calc(var(--t) * 2) ease-out 1; }
.patience.low .patience-number b { color: var(--danger); }
.patience.gain .patience-number b { color: var(--good); }
@keyframes bump { 0% { transform: scale(1.35); } 100% { transform: scale(1); } }

.bar { position: relative; height: 10px; border-radius: 5px; background: var(--panel-deep); border: 1px solid var(--edge); overflow: hidden; margin-top: 6px; }
.bar-fill { position: absolute; inset: 0; background: var(--accent); transform-origin: left center; transform: scaleX(1); transition: transform calc(var(--t) * 2) ease-out, background-color var(--t); }
.patience.low .bar-fill { background: var(--danger); }
.bar-ghost { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ghost); transform-origin: left center; transition: transform calc(var(--t) * 2) ease-out; }

.par-line { margin-top: 6px; font-size: 12px; color: var(--dim); }
.par-line b { font-family: Consolas, "Cascadia Mono", monospace; font-size: 15px; color: var(--accent); }
.ghost-note { margin-left: 10px; color: var(--ghost); font-size: 11px; }

.meta { display: flex; gap: 20px; }
.stat { display: flex; flex-direction: column; }
.stat b { font-family: Consolas, "Cascadia Mono", monospace; font-size: 20px; font-weight: 700; }

/* ---------------------------------------------------------------- Desk */

.desk {
  display: grid;
  grid-template-columns: var(--card-w) 1fr 200px;
  gap: 16px;
  align-items: start;
  background: radial-gradient(ellipse at 50% 0%, #2a2320 0%, #1a1614 55%, var(--ground) 100%);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 18px;
  transition: background-color calc(var(--t) * 3), box-shadow calc(var(--t) * 3);
}
.desk.low { box-shadow: inset 0 0 0 2px var(--danger-soft), inset 0 0 60px rgba(212, 85, 63, 0.18); }

.slot-caption { font-size: 10px; letter-spacing: 0.08em; color: var(--faint); font-weight: 600; margin-bottom: 8px; }

.excuse-slot { display: flex; flex-direction: column; }
.excuse-empty {
  width: var(--card-w); aspect-ratio: 5 / 7; border-radius: 10px;
  border: 1.5px dashed var(--edge); color: var(--faint);
  display: grid; place-items: center; font-size: 12px;
}

.room {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  min-height: calc(var(--card-w) * 1.4 + 70px);
}

/* ---------------------------------------------------------------- Cards */

.card {
  position: relative;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--card-face), var(--card-face-2));
  border: 1.5px solid var(--card-edge);
  color: var(--card-ink);
  aspect-ratio: 5 / 7;
  width: 100%;
  max-width: var(--card-w);
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 10px 12px;
  transition: transform var(--t) ease-out, opacity var(--t) ease-out, box-shadow var(--t);
  transform-origin: center;
}
.card .role { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; display: flex; justify-content: space-between; align-items: center; }
.card .role .glyph { font-family: "Segoe UI Symbol", "Segoe UI", sans-serif; font-size: 16px; }
.card .value { font-family: Georgia, "Times New Roman", serif; font-size: clamp(42px, 6vw, 64px); font-weight: 700; line-height: 1; display: flex; align-items: center; justify-content: center; gap: 6px; }
.card .value small { font-size: 0.42em; font-weight: 600; opacity: 0.7; align-self: flex-start; margin-top: 4px; }
.card .stripe { position: absolute; left: 0; top: 0; bottom: 0; width: 6px; border-radius: 10px 0 0 10px; }

.card.colleague .role, .card.colleague .value { color: var(--colleague); }
.card.deadline .role, .card.deadline .value { color: var(--deadline); }
.card.coffee .role, .card.coffee .value { color: var(--coffee); }
.card.excuse .role, .card.excuse .value { color: var(--excuse); }
.card.colleague .stripe { background: var(--colleague); }
.card.deadline .stripe { background: var(--deadline); }
.card.coffee .stripe { background: var(--coffee); }
.card.excuse .stripe { background: var(--excuse); }

/* States. Selection lifts; a card on its way out fades and drops; a card arriving rises in. */
.card.selected { transform: translateY(-8px); box-shadow: 0 0 0 3px var(--accent); }
.card.dealt { animation: deal-in calc(var(--t) * 2) ease-out 1 both; }
.card.leaving { transform: translateY(24px) scale(0.92); opacity: 0; pointer-events: none; }
.card.wasted { opacity: 0.5; }
@keyframes deal-in { from { transform: translateY(-18px); opacity: 0; } to { transform: none; opacity: 1; } }

/* A card slot: the card plus its choices under it. */
.slot { display: flex; flex-direction: column; gap: 8px; }
.slot .choices { display: flex; flex-direction: column; gap: 6px; }
.slot .choices button { padding: 7px 8px; font-size: 12px; text-align: left; line-height: 1.25; }
.slot .choices button b { display: block; font-size: 12px; }
.slot .choices button span { display: block; font-size: 11px; color: var(--dim); }
.slot .choices button:disabled span { color: var(--faint); }
.slot .choices button.bare:hover:not(:disabled) { border-color: var(--danger); }
.slot .choices button.excuse:hover:not(:disabled) { border-color: var(--good); }
.slot .choices button.drink:hover:not(:disabled) { border-color: var(--accent); }
.slot .key { font-family: Consolas, monospace; font-size: 11px; color: var(--faint); text-align: center; }

/* The equipped excuse, with what it has handled stacked beneath it - in normal flow, so it takes
 * the room it needs at every width. */
.excuse-card { width: var(--card-w); display: flex; flex-direction: column; }
.excuse-card .stack { display: flex; flex-direction: column; gap: 3px; margin: 6px 6px 0; }
.excuse-card .stack .mini {
  height: 22px; border-radius: 5px; line-height: 20px;
  background: #d9cfba; border: 1px solid var(--card-edge); color: var(--card-ink);
  font-family: Georgia, serif; font-weight: 700; font-size: 12px; padding: 0 8px;
  animation: deal-in calc(var(--t) * 2) ease-out 1 both;
}
.excuse-card .covers {
  margin-top: 8px; font-size: 12px; color: var(--dim); text-align: center;
  padding: 4px 8px; border-radius: 6px; background: var(--panel-deep); border: 1px solid var(--edge);
}
.excuse-card .covers.worn { color: var(--accent); border-color: var(--accent-soft); }

/* ---------------------------------------------------------------- Side */

.side { display: flex; flex-direction: column; gap: 12px; }
.break { text-align: left; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.break-title { font-weight: 600; }
.break-sub { font-size: 11px; color: var(--dim); }
.narration {
  font-size: 13px; color: var(--dim); line-height: 1.5;
  background: var(--panel-deep); border: 1px solid var(--edge); border-radius: 8px; padding: 10px 12px;
  min-height: 84px;
  transition: color var(--t);
}
.narration.hit { color: var(--danger); }
.narration.gain { color: var(--good); }
.narration.note { color: var(--text); }

/* ---------------------------------------------------------------- Bottom */

.bottom { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions button { font-size: 12px; padding: 7px 11px; }

/* ---------------------------------------------------------------- Overlays */

.overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(11, 9, 8, 0.86);
  display: grid; place-items: center; padding: 16px;
  opacity: 1; transition: opacity var(--t);
  /* A panel taller than the window scrolls, or its Close button is somewhere nobody can reach. */
  overflow-y: auto;
}
.overlay[hidden] { display: none; }
.panel {
  background: var(--panel); border: 1px solid var(--accent-soft); border-radius: 14px;
  padding: 24px 28px; max-width: 560px; width: 100%;
  animation: rise calc(var(--t) * 2) ease-out 1 both;
}
@keyframes rise { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.panel h2 { font-family: Georgia, serif; font-size: 26px; margin: 0 0 10px; }
.panel h3 { font-size: 11px; letter-spacing: 0.08em; color: var(--faint); margin: 18px 0 8px; }
.panel p { color: var(--dim); margin: 0 0 12px; }
.panel .fine { font-size: 12px; color: var(--faint); }
.panel .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 16px; }
.outcome h2 { font-size: 30px; color: var(--accent); }
.outcome.perfect h2 { color: var(--good); }
.outcome.lost h2 { color: var(--danger); }
.lines div { color: var(--dim); margin-bottom: 6px; font-size: 14px; }
.lines div:first-child { color: var(--text); font-size: 15px; }
/* The rules run longer than a phone; Close stays in reach at the bottom while they scroll. */
.help > .row:last-child { position: sticky; bottom: -24px; background: var(--panel); padding: 10px 0 24px; margin: 8px 0 -24px; border-top: 1px solid var(--edge); }
/* On a desk-sized screen the rules and the keys sit in two columns, so all of it fits at once. */
@media (min-width: 900px) {
  .panel.help { max-width: 900px; column-count: 2; column-gap: 32px; }
  .help h2, .help > .row:last-child { column-span: all; }
  .help p, .help .keys { break-inside: avoid; }
  .help h3 { break-after: avoid; }
}
.share-done { color: var(--good); font-size: 12px; margin-top: 8px; }
.share-text { display: block; width: 100%; margin-top: 6px; padding: 6px 8px; resize: none; font: inherit; font-size: 12px; background: var(--ground); color: var(--text); border: 1px solid var(--edge); border-radius: 6px; }
.share-text[hidden] { display: none; }
.keys { width: 100%; border-collapse: collapse; font-size: 13px; }
.keys td { padding: 4px 8px 4px 0; color: var(--dim); }
.keys td:nth-child(odd) { font-family: Consolas, monospace; color: var(--accent); width: 60px; }
.grid { display: grid; grid-template-columns: 1fr auto; gap: 4px 20px; margin: 0; }
.grid dt { color: var(--dim); }
.grid dd { margin: 0; text-align: right; font-family: Consolas, monospace; }
.recent { max-height: 200px; overflow: auto; font-family: Consolas, monospace; font-size: 12px; }
.recent div { display: grid; grid-template-columns: 70px 60px 1fr auto; gap: 8px; padding: 2px 0; color: var(--dim); }
.recent .won { color: var(--good); }
.recent .lost { color: var(--danger); }
.pick input { font: inherit; font-family: Consolas, monospace; font-size: 20px; width: 120px; padding: 6px 10px; background: var(--ground); color: var(--text); border: 1.5px solid var(--accent); border-radius: 8px; }
.pick .hash { font-family: Consolas, monospace; color: var(--accent); font-size: 18px; }

/* ---------------------------------------------------------------- Responsive */

@media (max-width: 900px) {
  /* Two rows: who and when on the first, the bar and the numbers on the second. */
  .top { grid-template-columns: 1fr auto; gap: 10px 14px; }
  .clock { text-align: right; min-width: 0; }
  .patience { grid-column: 1 / -1; min-width: 0; }
  .meta { grid-column: 1 / -1; justify-content: space-between; }
  .desk { grid-template-columns: 1fr; gap: 12px; }
  .excuse-slot { flex-direction: row; align-items: center; gap: 14px; }
  .excuse-empty { width: auto; aspect-ratio: auto; height: 36px; padding: 0 16px; }
  .excuse-card { width: min(var(--card-w), 130px); }
  .room { grid-template-columns: repeat(2, minmax(0, 1fr)); min-height: 0; }
  .side { flex-direction: row; }
  .side .break { flex: 0 0 auto; }
  .side .narration { flex: 1; min-height: 0; }
}

@media (max-width: 480px) {
  :root { --card-w: 150px; }
  .app { padding: 8px; gap: 8px; }
  .top { padding: 10px 12px; }
  .clock .time { font-size: 24px; }
  .meta { gap: 12px; }
  .desk { padding: 12px; }
  .room { gap: 10px; }
  .side { flex-direction: column; }
  .bottom { justify-content: center; }
}

/* A phone held upright. The whole hand has to be on screen at once - four cards, what each will
 * cost, the excuse and the break - because every decision is a comparison between them, and a
 * comparison you have to scroll for is one you make from memory. Full-size cards stacked two by
 * two ran to more than two screens. So here a card is a tile with its choices beside it rather
 * than under it, and the day reads as a list: one row per card, nothing below the fold. The same
 * goes for a phone on its side, which is short rather than narrow. */
@media (max-width: 620px), (max-height: 520px) {
  :root { --tile: 72px; }
  /* One screen, between the notch and the home bar. */
  .app {
    min-height: 100vh; min-height: 100dvh; gap: 6px;
    padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }
  /* The header in two rows: the day and the clock, then the bar beside the rating. The wordmark
   * is on the itch page already. */
  .top { grid-template-columns: 1fr auto; padding: 6px 12px; gap: 2px 14px; }
  .wordmark { display: none; }
  .day { font-size: 16px; margin: 0; }
  .clock { display: flex; align-items: baseline; justify-content: flex-end; gap: 8px; }
  .clock .time { font-size: 20px; }
  .clock .hour { margin: 0; min-height: 0; }
  .patience { grid-column: 1; min-width: 0; }
  .patience-number { font-size: 16px; }
  .bar { margin-top: 2px; height: 8px; }
  .par-line { margin-top: 2px; }
  .meta { grid-column: 2; flex-direction: column; justify-content: center; gap: 2px; }
  .stat { flex-direction: row; align-items: baseline; justify-content: space-between; gap: 6px; }
  .stat b { font-size: 14px; }

  .desk { padding: 8px; gap: 8px; }
  .slot-caption { margin: 0; }

  .card, .excuse-card .card {
    flex: none; width: var(--tile); max-width: var(--tile); height: var(--tile); aspect-ratio: auto;
    margin: 0; padding: 5px 6px 5px 11px; border-radius: 8px;
  }
  .card .role { font-size: 7.5px; letter-spacing: 0; }
  .card .role .glyph { font-size: 11px; }
  .card .role:last-child { display: none; }
  .card .value { font-size: calc(var(--tile) * 0.42); }
  .card .stripe { width: 5px; border-radius: 8px 0 0 8px; }
  /* Lifting a tile eight pixels would push it into the row above. */
  .card.selected { transform: none; }

  .excuse-slot { gap: 10px; }
  .excuse-empty { height: var(--tile); }
  .excuse-card { width: auto; flex: 1; min-width: 0; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
  /* What the excuse has handled, on one line however long it gets: the newest at the right, the
   * oldest falling off the left. Only the newest sets what it still covers. */
  .excuse-card .stack { flex: 1; min-width: 0; margin: 0; flex-direction: row; flex-wrap: nowrap; justify-content: flex-end; overflow: hidden; }
  .excuse-card .stack .mini { flex: none; font-size: 11px; padding: 0 6px; }
  .excuse-card .stack .mini .who { display: none; }
  .excuse-card .covers { margin: 0; }

  .room { grid-template-columns: 1fr; gap: 6px; }
  .slot { flex-direction: row; align-items: stretch; gap: 8px; }
  .slot .choices { flex: 1; min-width: 0; flex-direction: row; gap: 6px; }
  .slot .choices button { flex: 1 1 0; min-width: 0; padding: 5px 8px; }
  /* Number keys, on a device with no keyboard. */
  .slot .key { display: none; }

  .side { flex-direction: row; gap: 8px; }
  .side .break { flex: 0 0 auto; max-width: 42%; padding: 8px 10px; }
  .side .narration { flex: 1; min-height: 0; padding: 8px 10px; font-size: 12px; line-height: 1.4; }

  .bottom { gap: 6px; }
  .actions button { padding: 6px 9px; }

  .overlay { padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom)); }
  .panel { padding: 16px 18px; }
  .panel h2 { font-size: 22px; }
  .panel p { margin-bottom: 9px; font-size: 13px; }
  /* A table of keys, on a device with no keyboard. */
  .help h3, .help .keys { display: none; }
}

/* A short phone upright - an SE, or an iPhone with the browser's bars showing - still gets the
 * whole hand, the break and the buttons: the tiles shrink instead. */
@media (max-width: 620px) and (max-height: 660px) {
  :root { --tile: 60px; }
  /* No room for the word on a tile this size; the colour, the suit and the choices say it. */
  .card .role > span:not(.glyph) { display: none; }
  .card .role { justify-content: flex-end; }
  .room { gap: 5px; }
  .side .break { padding: 6px 10px; }
  .actions button { font-size: 11px; padding: 5px 8px; }
}
@media (max-width: 620px) and (max-height: 600px) {
  :root { --tile: 52px; }
  .desk { gap: 6px; }
  .slot .choices button { padding: 3px 8px; }
  .side .narration { padding: 6px 10px; }
}

/* A phone on its side has height for two rows of cards, not four. The header goes back to one
 * line, and the excuse and the break move to a column on the left of a two-by-two hand. */
@media (min-width: 621px) and (max-height: 520px) {
  .top { grid-template-columns: auto auto 1fr auto; gap: 4px 20px; }
  .patience { grid-column: auto; }
  .meta { grid-column: auto; }
  .desk { grid-template-columns: minmax(0, 230px) 1fr; grid-template-rows: auto 1fr; }
  .excuse-slot { grid-column: 1; grid-row: 1; }
  .side { grid-column: 1; grid-row: 2; flex-direction: column; }
  .side .break { max-width: none; }
  .room { grid-column: 2; grid-row: 1 / span 2; grid-template-columns: 1fr 1fr; }
}
