:root {
  --bg: #1c1c1c;
  --ink: #0a0a0a;
  --paper: #ffffff;
  --orange: #f46d36;
  --muted: #4d4d4d;
  --safe-top: env(safe-area-inset-top, 12px);
  --safe-bot: env(safe-area-inset-bottom, 16px);
  --display: "Space Grotesk", sans-serif;
  --ui: Inter, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { background: #000; }

body {
  margin: 0;
  background: #000;
  color: var(--paper);
  font-family: var(--ui);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button, input { font: inherit; color: inherit; border: 0; background: none; }
button { cursor: pointer; }
input { width: 100%; outline: none; }
input::placeholder { color: inherit; opacity: 0.38; }

.app {
  height: 100%;
  max-width: 430px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

.screen {
  display: none;
  width: 100%;
  height: 100%;
}
.screen.is-on {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* —— Home —— */
.home {
  padding: calc(var(--safe-top) + 8px) 0 calc(var(--safe-bot) + 48px);
  overflow-y: auto;
}

.home-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 8px 16px 22px;
  animation: fade-down 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.home-head h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 50px;
  line-height: 1.02;
  text-transform: uppercase;
  color: var(--orange);
}
.home-head img { width: 21px; height: 21px; margin-top: 14px; }

.stack { display: flex; flex-direction: column; }
.tile {
  position: relative;
  min-height: 205px;
  padding: 16px;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 20px;
  text-align: left;
  margin-top: -48px;
  animation: deal 0.85s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.stack .tile:first-child { margin-top: 0; }
.stack .tile:nth-child(1) { animation-delay: 0.08s; }
.stack .tile:nth-child(2) { animation-delay: 0.18s; }
.stack .tile:nth-child(3) { animation-delay: 0.28s; }
.stack .tile:nth-child(4) { animation-delay: 0.36s; }
.stack .tile:nth-child(5) { animation-delay: 0.44s; }
.stack .tile:nth-child(n + 6) { animation-delay: 0.5s; }

.ended-label {
  margin: 48px 16px 16px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 30px;
  line-height: 1.02;
  text-transform: uppercase;
  color: var(--muted);
  animation: fade-down 0.6s 0.32s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.status {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 11px;
  text-transform: uppercase;
}
.status strong { font-weight: 800; }
.status span { font-weight: 500; opacity: 0.68; }
.status .win { margin-left: auto; text-align: right; }

.tile-title {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 50px;
  line-height: 1.02;
  text-transform: uppercase;
}
.tile-sub {
  margin: 8px 0 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: 12px;
  line-height: 1.02;
  text-transform: uppercase;
}
.tile-players {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  opacity: 0.76;
}

.empty {
  margin: 48px 16px 0;
  opacity: 0.4;
  font-size: 13px;
  line-height: 1.4;
}

/* —— Form —— */
.form {
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bot) + 28px);
  overflow-y: auto;
}
.back {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  opacity: 0.55;
  margin-bottom: 28px;
  text-align: left;
}
.form h2 {
  margin: 0 0 36px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 50px;
  line-height: 1.02;
  text-transform: uppercase;
  color: var(--orange);
}
.field { margin-bottom: 22px; }
.field input {
  font-family: var(--display);
  font-weight: 700;
  font-size: 22px;
  text-transform: uppercase;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.18);
}
.palette {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 12px 0 40px;
}
.palette[hidden] { display: none; }
.swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  outline: 2px solid transparent;
  outline-offset: 3px;
}
.swatch.is-on { outline-color: currentColor; }
.add-player {
  margin: 4px 0 28px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  opacity: 0.55;
  text-align: left;
}
.go {
  margin-top: 8px;
  width: 100%;
  min-height: 56px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 28px;
  text-transform: uppercase;
  color: var(--orange);
  text-align: left;
}

/* —— Play —— */
.play {
  padding: calc(var(--safe-top) + 8px) 0 calc(var(--safe-bot) + 28px);
  color: var(--ink);
}
.play.is-light { color: #fff; }
.play.is-dark { color: var(--ink); }

.play-pad { padding: 0 16px; }

.play-back {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  text-transform: uppercase;
  margin: 4px 0 22px;
  text-align: left;
}
.play-back svg { width: 14px; height: 14px; }

.play-title {
  margin: 18px 0 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 50px;
  line-height: 1.02;
  text-transform: uppercase;
}
.play-sub {
  margin: 10px 0 0;
  font-family: var(--display);
  font-size: 12px;
  text-transform: uppercase;
}

.hint-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 28px 16px 10px;
}
.hint {
  width: 21px;
  height: 21px;
  position: relative;
  opacity: 0.12;
}
.hint::before,
.hint::after {
  content: "";
  position: absolute;
  background: currentColor;
}
.hint-plus::before,
.hint-minus::before {
  left: 0;
  right: 0;
  height: 5.7px;
  top: 50%;
  transform: translateY(-50%);
}
.hint-plus::after {
  top: 0;
  bottom: 0;
  width: 5.7px;
  left: 50%;
  transform: translateX(-50%);
}

.board {
  width: 100%;
  display: flex;
  flex-direction: column;
  background: inherit;
}

.row {
  position: relative;
  overflow: hidden;
  touch-action: pan-y;
  min-height: 168px;
  border-top: 1px solid currentColor;
  background: inherit;
}
.row:last-child { border-bottom: 1px solid currentColor; }

.swipe-track {
  position: absolute;
  inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  pointer-events: none;
}
.swipe-mark {
  font-family: var(--display);
  font-weight: 700;
  font-size: 56px;
  line-height: 1;
  color: #fff;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.row.is-plus .swipe-mark.plus,
.row.is-minus .swipe-mark.minus {
  opacity: 1;
  transform: scale(1);
}
.row.is-ready .swipe-mark {
  transform: scale(1.12);
}

.row-inner {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 168px;
  padding: 10px 16px 14px;
  display: flex;
  flex-direction: column;
  background: inherit;
  will-change: transform;
}
.row .score {
  font-family: var(--display);
  font-weight: 700;
  font-size: 100px;
  line-height: 1.02;
  text-align: right;
  text-transform: uppercase;
}
.row .who {
  margin-top: auto;
  font-family: var(--display);
  font-weight: 700;
  font-size: 50px;
  line-height: 1.02;
  text-transform: uppercase;
}

.details-btn {
  margin: 56px 16px 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 20px;
  text-transform: uppercase;
  opacity: 0.25;
  text-align: left;
}
.details-btn.is-open { opacity: 1; }

.history {
  display: none;
  margin: 28px 16px 0;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.7;
  opacity: 0.88;
}
.history.is-open { display: block; }
.history p { margin: 0 0 10px; }
.history b { font-weight: 800; text-transform: uppercase; }

.play .palette {
  margin: 160px 16px 0;
}

.play-spacer { height: 300px; flex-shrink: 0; }

.play-foot {
  display: flex;
  justify-content: space-between;
  padding: 0 16px;
}
.play-foot button {
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  text-transform: uppercase;
}

/* —— Sheets —— */
.overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.46);
  z-index: 20;
  align-items: flex-end;
}
.overlay.is-on { display: flex; }
.sheet {
  width: 100%;
  padding: 28px 16px calc(var(--safe-bot) + 22px);
  background: var(--bg);
  animation: sheet-up 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}
.sheet h3 {
  margin: 0 0 8px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 28px;
  text-transform: uppercase;
  color: var(--orange);
}
.sheet p {
  margin: 0 0 18px;
  opacity: 0.55;
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 700;
}
.sheet input {
  font-family: var(--display);
  font-weight: 700;
  font-size: 22px;
  text-transform: uppercase;
  padding: 10px 0 14px;
  border-bottom: 1px solid rgba(255,255,255,0.2);
  margin-bottom: 28px;
}
.sheet-actions { display: flex; justify-content: space-between; }
.sheet-actions button {
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  text-transform: uppercase;
}
.sheet-actions .ok { color: var(--orange); }
.sheet-actions .no { opacity: 0.5; }

.boot-error {
  padding: 48px 20px;
  color: #fff;
  line-height: 1.45;
}

@keyframes deal {
  from {
    opacity: 0;
    transform: translateY(64px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
@keyframes fade-down {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: none; }
}
@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}

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