/* Portrait phone only. Everything scales from the width of one tableau column. */

:root {
  --bg: #12161a;
  --felt: #171c22;
  --slot-line: #2a323b;
  --card-face: #262d35;
  --card-edge: #333c46;
  --ink: #c3ccd5;
  --ink-red: #d98a80;
  --accent: #6f9dc4;
  --muted: #6d7883;

  --gap: 4px;
  --pad: 6px;
  --card-h: 60px; /* set from JS once the grid width is known */
  --fan: 20px;
  --radius: 5px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 500 15px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding:
    calc(var(--pad) + env(safe-area-inset-top, 0px))
    calc(var(--pad) + env(safe-area-inset-right, 0px))
    calc(var(--pad) + env(safe-area-inset-bottom, 0px))
    calc(var(--pad) + env(safe-area-inset-left, 0px));
  gap: var(--pad);
}

/* --- heads-up display --- */

.hud {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  flex: 0 0 auto;
}

.hud b {
  color: var(--ink);
  font-weight: 600;
}

.hud-stats {
  margin-left: auto;
}

.hud-button {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 18px;
  padding: 4px 8px;
  min-height: 32px;
  cursor: pointer;
}

/* --- board --- */

#board {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--pad);
}

.top-row,
.tableau {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: var(--gap);
}

.top-row {
  flex: 0 0 auto;
}

.tableau {
  flex: 1 1 auto;
  min-height: 0;
  align-content: start;
}

.slot {
  height: var(--card-h);
  border: 1px dashed var(--slot-line);
  border-radius: var(--radius);
  position: relative;
  background: var(--felt);
}

/* The sprite holding the suit shapes: present, but never seen. */
.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* Every suit shape takes the colour of whatever it sits on. */
.pip,
.mark,
.ghost {
  display: block;
  fill: currentColor;
  pointer-events: none;
}

/* A faint suit behind each foundation, so the target is obvious. */
.ghost {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: calc(var(--card-h) * 0.34);
  height: calc(var(--card-h) * 0.34);
  /* Barely there: it marks the target without reading as a card. */
  color: #222932;
}

.slot-foundation.red .ghost {
  color: #2c242a;
}

.slot > .card {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.column {
  position: relative;
  min-height: var(--card-h);
  border-radius: var(--radius);
}

.column.empty {
  border: 1px dashed var(--slot-line);
  background: var(--felt);
  height: var(--card-h) !important;
}

/* --- cards --- */

.card {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--card-h);
  /* A shallow gradient and a lit top edge, so a fanned pile reads as separate
     cards without raising the contrast. */
  background: linear-gradient(180deg, #2c333c, #222931);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  overflow: hidden;
  display: block;
  color: var(--ink);
}

.card.red {
  color: var(--ink-red);
}

/* Rank and suit sit in the top strip: the part still visible when the card
   is covered by the one in front of it. */
.corner {
  position: absolute;
  top: 0;
  left: 3px;
  font-size: calc(var(--card-h) * 0.32);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.pip {
  position: absolute;
  top: calc(var(--card-h) * 0.07);
  right: 3px;
  width: calc(var(--card-h) * 0.20);
  height: calc(var(--card-h) * 0.20);
}

/* A hairline panel marks the picture cards apart from the numbers. Only on
   cards nothing covers — `.mark` is present exactly on those — because a
   partly hidden frame reads as a glitch, and it must clear the rank strip. */
.court:has(.mark)::before {
  content: '';
  position: absolute;
  inset: 34% 4px 4px;
  border: 1px solid currentColor;
  border-radius: 2px;
  opacity: 0.16;
  pointer-events: none;
}

/* Only on cards nothing covers, where there is room for it. */
.mark {
  position: absolute;
  left: 50%;
  top: 60%;
  transform: translate(-50%, -50%);
  width: calc(var(--card-h) * 0.38);
  height: calc(var(--card-h) * 0.38);
  /* Decoration, so it must sit well below the rank in the reading order. */
  opacity: 0.13;
}

.card.selected {
  transform: translateY(-5px);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 4px 10px rgba(0, 0, 0, 0.55);
  z-index: 5;
}

/* --- dragging --- */

/* A press that travels picks the cards up; a press that stays put is a tap.
   The board never scrolls, so no gesture is being taken away. */
.card {
  touch-action: none;
  -webkit-touch-callout: none;
}

.card.dragging {
  /* Out of the way of elementFromPoint, so the board underneath can be read. */
  pointer-events: none;
  z-index: 60;
  border-color: var(--accent);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.6);
}

/* Where the cards in hand may be put down. */
.droppable::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  opacity: 0.35;
  pointer-events: none;
}

.column.droppable::after {
  /* A column is as tall as its pile; mark only the landing area. */
  top: auto;
  height: var(--card-h);
}

.drop-over::after {
  opacity: 1;
  background: rgba(111, 157, 196, 0.12);
}

/* --- feedback --- */

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.reject {
  animation: shake 0.18s ease-in-out 1;
}

@media (prefers-reduced-motion: reduce) {
  .reject { animation: none; }
  .card.selected { transform: none; }
}

/* --- starting up --- */

/* While booting, hide the controls: a button that cannot work should not look
   as though it can. `main.js` drops the attribute as soon as it has drawn. */
#app[data-booting] .controls,
#app[data-booting] .hud-button,
#app[data-booting] .hud-moves,
#app[data-booting] .hud-deal {
  visibility: hidden;
}

.boot-note {
  display: none;
  padding: 24px 8px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

/* Both messages share one grid cell, so one can replace the other without the
   layout shifting as it swaps. */
#app[data-booting] .boot-note {
  display: grid;
  place-items: center;
}

.boot-note > span {
  grid-area: 1 / 1;
  max-width: 30ch;
}

/* The failure text appears only once booting has clearly stalled. A CSS
   animation is used precisely because it still runs when scripts do not. */
#app[data-booting] .boot-starting {
  animation: boot-fade-out 0.4s ease 5s forwards;
}

#app[data-booting] .boot-failed {
  opacity: 0;
  animation: boot-fade-in 0.4s ease 5s forwards;
}

@keyframes boot-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes boot-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* --- controls --- */

.controls {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
}

.control {
  min-height: 46px;
  padding: 0 12px;
  background: #1e242b;
  color: var(--ink);
  border: 1px solid var(--card-edge);
  border-radius: 8px;
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}

.control:disabled {
  color: #4c555e;
  border-color: #232a31;
}

.control:active {
  background: #262e36;
}

.control-primary {
  border-color: var(--accent);
  color: var(--accent);
}

/* --- win banner --- */

.banner {
  position: fixed;
  inset: auto 0 0 0;
  margin: 0 auto;
  max-width: 380px;
  background: #1b2229;
  border: 1px solid var(--card-edge);
  border-radius: 12px 12px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  text-align: center;
  display: grid;
  gap: 10px;
  z-index: 20;
}

.banner[hidden] {
  display: none;
}

.banner-title {
  font-size: 20px;
  font-weight: 600;
}

.banner-detail {
  color: var(--muted);
  font-size: 14px;
}

/* --- menu sheet --- */

.sheet {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 100vw;
  max-height: 100dvh;
}

.sheet::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.sheet-body {
  width: min(92vw, 380px);
  background: #1b2229;
  color: var(--ink);
  border: 1px solid var(--card-edge);
  border-radius: 12px;
  padding: 18px 16px;
  display: grid;
  gap: 14px;
}

.sheet h2 {
  font-size: 17px;
  font-weight: 600;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}

.field input {
  min-height: 46px;
  padding: 0 10px;
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: #12171c;
  border: 1px solid var(--card-edge);
  border-radius: 8px;
}

.field-error {
  color: var(--ink-red);
  font-size: 13px;
}

.field-error[hidden] {
  display: none;
}

.choice {
  border: 0;
  display: grid;
  gap: 2px;
}

.choice legend {
  font-size: 14px;
  color: var(--muted);
  padding: 0 0 4px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
  min-height: 44px;
}

/* The chosen option is the one you are reading, so let it read clearly. */
.toggle:has(input:checked) {
  color: var(--ink);
}

.toggle input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

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

.sheet-stats {
  color: var(--muted);
  font-size: 13px;
}
