/* TAO: main stylesheet (warm, cosy evening garden; see ART.md).
   Animations only use transform and opacity, which phones can do cheaply. */

:root {
  --ink: #15151a;
  --paper: #fbf6ec;
  --coral: #e24a3b;
  --gold: #f2c230;
  --green: #5bae4b;
  --teal: #2a8fd0;
  --muted: #d9cab6;
  --dusk: #2a1d24;
  --panel: rgba(46, 31, 34, 0.92);
  --panel-edge: rgba(242, 194, 48, 0.28);
  --glow: #ffd86b;
  --radius: 18px;
  --font: ui-rounded, 'SF Pro Rounded', 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  --display: 'Arial Rounded MT Bold', 'Segoe UI Black', 'Arial Black', system-ui, sans-serif;
  /* Space kept free for phone notches and rounded screen corners. */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100dvh;
  color: var(--paper);
  font-family: var(--font);
  line-height: 1.4;
  /* Golden-hour sky fading into the evening. */
  background:
    radial-gradient(ellipse 120% 70% at 50% -10%, rgba(255, 170, 90, 0.35), transparent 65%),
    radial-gradient(ellipse 80% 50% at 85% 10%, rgba(242, 194, 48, 0.18), transparent 60%),
    linear-gradient(180deg, #4a2a33 0%, #2a1d24 45%, #160f14 100%);
  background-color: #160f14;
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}

body.in-game {
  overflow: hidden;
  overscroll-behavior: none;
}

[hidden] {
  display: none !important;
}

a {
  color: var(--gold);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

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

.wordmark {
  font-family: var(--display);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--gold);
  margin: 0;
  /* Outlined, rounded lettering like on the card back. */
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 3px 0 var(--ink), 0 6px 14px rgba(0, 0, 0, 0.45);
}

.connection {
  position: fixed;
  z-index: 50;
  top: calc(8px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: #6a3d00;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

/* ---------------------------------------------------------------------------
   Buttons and form fields
   --------------------------------------------------------------------------- */

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 2px solid rgba(251, 246, 236, 0.25);
  background: rgba(251, 246, 236, 0.08);
  color: var(--paper);
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.pill:active:not(:disabled) {
  transform: scale(0.96);
}

.pill.primary {
  background: linear-gradient(180deg, #ffd35a, var(--gold));
  border-color: var(--ink);
  color: var(--ink);
  box-shadow: 0 3px 0 var(--ink);
}

.pill.big {
  min-height: 52px;
  font-size: 1.1rem;
  width: 100%;
}

.pill:disabled {
  opacity: 0.45;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(251, 246, 236, 0.25);
  background: rgba(21, 21, 26, 0.45);
  font-size: 1.25rem;
  line-height: 1;
}

.icon-button.is-on {
  border-color: var(--gold);
}

/* The speaker button (sound on / off). */
.speaker-button {
  display: inline-grid;
  place-items: center;
  color: var(--paper, #fbf6ec);
}

.speaker-button.is-off {
  opacity: 0.7;
}

.lobby-pages {
  position: relative;
}

.lobby-sound {
  position: absolute;
  top: calc(10px + var(--safe-top));
  right: calc(10px + var(--safe-right));
  z-index: 5;
}

.sound-options {
  border: 0;
  margin: 0;
  padding: 0;
  text-align: left;
  display: grid;
  gap: 2px;
}

.sound-options legend {
  font-weight: 800;
  margin-bottom: 4px;
}

.sound-row {
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr;
  align-items: center;
  gap: 10px;
}

.sound-row input[type='range'] {
  width: 100%;
  accent-color: var(--gold);
}

label {
  display: block;
  margin: 12px 0 6px;
  font-weight: 700;
}

.optional {
  font-weight: 400;
  color: var(--muted);
}

input[type='text'],
input[type='password'],
select {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  font: inherit;
  font-size: 1.05rem;
  border-radius: 12px;
  border: 2px solid rgba(251, 246, 236, 0.18);
  background: rgba(21, 21, 26, 0.55);
  color: var(--paper);
}

input:focus,
select:focus {
  border-color: var(--gold);
  outline: none;
}

.error {
  color: #ffab9f;
  min-height: 1.3em;
  margin: 8px 0 0;
}

/* Open mode (M4): the "are you a human?" check (Cloudflare Turnstile) under the Create button. */
.human-check {
  display: flex;
  justify-content: center;
  margin-top: 12px;
  min-height: 65px;
}

.hint {
  color: var(--muted);
}

.hint.small {
  font-size: 0.85rem;
  margin: 4px 0 0;
}

/* ---------------------------------------------------------------------------
   Lobby pages (home, join, waiting room, errors)
   --------------------------------------------------------------------------- */

.lobby-pages {
  max-width: 920px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(24px + var(--safe-bottom))
    calc(16px + var(--safe-left));
}

/* The forms and messages stay a comfortable width; only the logo row is wide. */
.lobby-pages > .screen,
.lobby-pages > .footer-links {
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

/* Text for screen readers only (the logo is a picture, its words are here). */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------------------------------------------------------------------------
   The brand block: the TAO logo with a black cat on the left and a cream cat on the right, both presenting it
   (drawn in code by js/logo-art.js, put on the page by js/brand.js; sizes depend on the screen: data-screen).
   --------------------------------------------------------------------------- */

.brand {
  --logo-width: 440px;
  --cat-width: 200px;
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, var(--logo-width)) minmax(0, 1fr);
  grid-template-areas:
    'cat-left logo cat-right'
    '. tagline .';
  align-items: end;
  column-gap: 6px;
  text-align: center;
  padding-top: 8px;
}

/* A warm glow behind the three of them, like the lamp light of the garden. */
.brand::before {
  content: '';
  position: absolute;
  inset: 0 4% 12%;
  z-index: -1;
  background: radial-gradient(ellipse 60% 62% at 50% 55%, rgba(255, 186, 110, 0.26), transparent 70%);
  pointer-events: none;
}

.brand-logo {
  grid-area: logo;
  margin: 0;
  line-height: 0;
}

.brand-logo-img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
}

.brand-cat {
  width: min(100%, var(--cat-width));
  line-height: 0;
}

.brand-cat--left {
  grid-area: cat-left;
  justify-self: end;
}

.brand-cat--right {
  grid-area: cat-right;
  justify-self: start;
}

.brand-cat svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.tagline {
  grid-area: tagline;
  margin: 6px 0 18px;
  color: var(--muted);
  text-wrap: balance; /* when it wraps (phones), two even lines instead of one word alone */
}

/* The cats are quiet: breathing, a blink now and then, a lazy tail. Transform only; nothing moves with reduced motion. */
.cat-breath,
.cat-tail,
.cat-eyes {
  transform-box: fill-box;
}

.cat-breath {
  transform-origin: 50% 100%;
  animation: cat-breathe 4.6s ease-in-out infinite;
}

.cat-tail {
  transform-origin: 100% 100%;
  animation: cat-sway 5.8s ease-in-out infinite;
}

.cat-eyes {
  transform-origin: 50% 50%;
  animation: cat-blink 5.4s ease-in-out infinite;
}

/* The loaf's tail lies on the ground; only its tip flicks, turning where it starts. */
.cat-tail--tip {
  transform-origin: 0% 100%;
  animation-name: cat-tip;
}

.brand-cat--right .cat-breath {
  animation-delay: -2.1s;
}

.brand-cat--right .cat-tail {
  animation-delay: -2.6s;
}

.brand-cat--right .cat-eyes {
  animation-delay: -3.3s;
}

@keyframes cat-breathe {
  0%,
  100% {
    transform: scaleY(1);
  }
  50% {
    transform: scaleY(1.016);
  }
}

@keyframes cat-sway {
  0%,
  100% {
    transform: rotate(-3deg);
  }
  50% {
    transform: rotate(5deg);
  }
}

@keyframes cat-tip {
  0%,
  100% {
    transform: rotate(-6deg);
  }
  50% {
    transform: rotate(10deg);
  }
}

@keyframes cat-blink {
  0%,
  92%,
  100% {
    transform: scaleY(1);
  }
  95.5% {
    transform: scaleY(0.08);
  }
}

/* Smaller on the other pages: the join page (and the other short messages) get a smaller logo and cats ... */
#lobby-pages[data-screen='join'] .brand,
#lobby-pages[data-screen='choose'] .brand,
#lobby-pages[data-screen='error'] .brand {
  --logo-width: 300px;
  --cat-width: 140px;
}

/* ... and the waiting room only a small logo. */
#lobby-pages[data-screen='lobby'] .brand {
  --logo-width: 230px;
  grid-template-columns: minmax(0, var(--logo-width));
  grid-template-areas:
    'logo'
    'tagline';
  justify-content: center;
}

#lobby-pages[data-screen='lobby'] .brand-cat {
  display: none;
}

/* Before we know which page this is, show nothing (no flash of the wrong size). */
#lobby-pages[data-screen='none'] .brand {
  visibility: hidden;
}

/* A phone held upright: the logo on top, the cats smaller below it with the tagline between them. */
@media (max-width: 640px) {
  .brand {
    --logo-width: 420px;
    --cat-width: 92px;
    grid-template-columns: minmax(0, 92px) minmax(0, 1fr) minmax(0, 92px);
    grid-template-areas:
      'logo logo logo'
      'cat-left tagline cat-right';
    align-items: center;
  }

  .brand-cat--left,
  .brand-cat--right {
    justify-self: center;
  }

  .tagline {
    margin: 0;
    font-size: 0.95rem;
  }

  #lobby-pages[data-screen='join'] .brand,
  #lobby-pages[data-screen='choose'] .brand,
  #lobby-pages[data-screen='error'] .brand {
    --logo-width: 300px;
    --cat-width: 64px;
    grid-template-columns: minmax(0, 64px) minmax(0, 1fr) minmax(0, 64px);
  }

  #lobby-pages[data-screen='lobby'] .brand {
    --logo-width: 220px;
    grid-template-columns: minmax(0, var(--logo-width));
  }

  .brand-logo {
    justify-self: center;
    width: min(100%, var(--logo-width));
    margin-inline: auto;
  }
}

/* A phone held sideways (short and wide): the brand on the left, the form on the right, so nothing is pushed out of view. */
@media (max-height: 520px) and (min-width: 600px) {
  .lobby-pages {
    display: grid;
    grid-template-columns: minmax(250px, 330px) minmax(300px, 440px);
    column-gap: 28px;
    justify-content: center;
    align-content: center;
    max-width: none;
    min-height: 100dvh;
  }

  .lobby-pages > .brand {
    grid-column: 1;
    grid-row: 1 / span 8;
    align-self: center;
    --logo-width: 330px;
    --cat-width: 78px;
    grid-template-columns: minmax(0, 78px) minmax(0, 1fr) minmax(0, 78px);
    grid-template-areas:
      'logo logo logo'
      'cat-left tagline cat-right';
    align-items: center;
  }

  .lobby-pages > .brand .brand-cat--left,
  .lobby-pages > .brand .brand-cat--right {
    justify-self: center;
  }

  .lobby-pages > .brand .tagline {
    margin: 0;
    font-size: 0.9rem;
  }

  .lobby-pages > .brand .brand-logo {
    justify-self: center;
    width: min(100%, var(--logo-width));
  }

  .lobby-pages > .screen,
  .lobby-pages > .footer-links {
    grid-column: 2;
    max-width: none;
    width: 100%;
  }

  #lobby-pages[data-screen='lobby'] .brand {
    grid-template-columns: minmax(0, 1fr);
    --logo-width: 230px;
  }

  /* Tighter forms, so the whole form (and its button) fits on a phone held sideways. */
  .lobby-pages > .screen.panel {
    padding: 10px 16px 12px;
  }

  .lobby-pages > .screen.panel h2 {
    margin-bottom: 2px;
    font-size: 1.15rem;
  }

  .lobby-pages > .screen.panel form .pill.big,
  .lobby-pages > .screen.panel > .pill.big {
    margin-top: 10px;
  }

  .lobby-pages > .footer-links {
    margin-top: 6px;
    margin-bottom: 0;
  }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  padding: 18px 18px 20px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.panel h2 {
  margin: 0 0 6px;
  font-size: 1.35rem;
}

.panel form .pill.big,
.panel > .pill.big {
  margin-top: 18px;
}

/* "You are already in this game": one big button per seat this browser holds in the room. */
.choose-seats {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.link-row {
  display: flex;
  gap: 8px;
}

.link-row input {
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
}

.lobby-players {
  list-style: none;
  margin: 16px 0 8px;
  padding: 0;
  display: grid;
  gap: 8px;
}

.lobby-player {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 6px 12px 6px 6px;
  border-radius: 14px;
  background: rgba(251, 246, 236, 0.06);
}

.lobby-player.is-empty {
  justify-content: center;
  color: var(--muted);
  border: 2px dashed rgba(251, 246, 236, 0.15);
  background: transparent;
}

.lobby-face {
  width: 40px;
  height: 40px;
}

.lobby-name {
  font-weight: 700;
  flex: 1;
  overflow-wrap: anywhere;
}

.lobby-tags {
  font-size: 0.8rem;
  color: var(--ink);
  background: var(--gold);
  border-radius: 999px;
  padding: 2px 8px;
}

.footer-links {
  text-align: center;
  margin-top: 18px;
  font-size: 0.9rem;
}

/* ---------------------------------------------------------------------------
   The game screen: fills the whole viewport
   --------------------------------------------------------------------------- */

.game-screen {
  position: fixed;
  inset: 0;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.stage {
  position: absolute;
  inset: 0;
  /* Set by hud.js from the real sizes of the top bar and the bottom part of the HUD. */
  --hud-top: 60px;
  --hud-bottom: 220px;
}

.table-layer {
  position: absolute;
  inset: 0;
}

/* ---------------------------------------------------------------------------
   Animations (fx.js): flying cards and callouts. Only transform and opacity change.
   --------------------------------------------------------------------------- */

.fx-layer {
  position: absolute;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  overflow: hidden;
}

.fx-card {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform, opacity;
}

.fx-face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 9%;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.45));
}

/* The real card waits invisibly until its flying copy has landed. */
.is-arriving {
  opacity: 0 !important;
}

.fx-callout {
  position: absolute;
  padding: 4px 16px;
  border-radius: 999px;
  border: 3px solid var(--ink);
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(1.3rem, 4vmin, 2.2rem);
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  will-change: transform, opacity;
}

.fx-callout.is-uno {
  background: var(--coral);
  color: var(--paper);
}

.fx-callout.is-penalty {
  background: #8f1f1f;
  color: #ffe3dc;
}

.fx-callout.is-skip {
  background: rgba(21, 21, 26, 0.85);
  color: var(--paper);
  font-size: clamp(1rem, 3vmin, 1.4rem);
}

.fx-callout.is-win {
  background: var(--gold);
  color: var(--ink);
}

/* In the 3D view the notes go to the top-left corner, so they never cover the table or a cat. */
.stage[data-mode='3d'] .hud-notes {
  top: calc(var(--hud-top) + 2px);
  bottom: auto;
  left: calc(10px + var(--safe-left));
  transform: none;
  width: min(46vw, 300px);
  flex-direction: column;
  align-items: flex-start;
}

/* The 3D garden fills the whole screen behind the HUD. */
.t3d-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* High / Ultra: hidden until the picture pipeline has drawn a few warm-up frames off screen, then faded in. */
.t3d-canvas.is-warming {
  opacity: 0;
}

.t3d-canvas.is-fading-in {
  transition: opacity 0.35s ease-out; /* instant with reduced motion (see the end of this file) */
}

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hud > * {
  pointer-events: auto;
}

.hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + var(--safe-top)) calc(10px + var(--safe-right)) 6px calc(10px + var(--safe-left));
  pointer-events: none;
}

.hud-top > * {
  pointer-events: auto;
}

.hud-round {
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(21, 21, 26, 0.5);
  font-size: 0.9rem;
  color: var(--muted);
}

.hud-spacer {
  flex: 1;
}

.hud-notes {
  position: absolute;
  bottom: calc(var(--hud-bottom) + 4px);
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 420px);
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 4px;
  pointer-events: none;
  z-index: 5;
}

.note {
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(21, 21, 26, 0.72);
  font-size: 0.85rem;
  animation: note-in 0.25s ease-out;
  transition: opacity 0.6s ease;
}

.note.is-leaving {
  opacity: 0;
}

@keyframes note-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.hud-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0 calc(8px + var(--safe-right)) calc(6px + var(--safe-bottom)) calc(8px + var(--safe-left));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  pointer-events: none;
}

.hud-bottom > * {
  pointer-events: auto;
}

.hud-message {
  margin: 0 auto 2px;
  min-height: 1.4em;
  padding: 3px 14px;
  border-radius: 999px;
  text-align: center;
  font-weight: 700;
  color: var(--muted);
  background: rgba(21, 21, 26, 0.45);
  pointer-events: none;
}

.hud-message:empty {
  visibility: hidden;
}

/* "Waiting for <name> to come back…": the game is paused. */
.hud-message.is-paused,
.result-paused {
  color: var(--ink);
  background: var(--gold);
}

.result-paused {
  margin: 12px 0 0;
  padding: 8px 14px;
  border-radius: 999px;
  text-align: center;
  font-weight: 700;
}

.hud-message.is-mine {
  color: var(--ink);
  background: var(--gold);
  animation: breathe 1.6s ease-in-out infinite alternate;
}

@keyframes breathe {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.04);
  }
}

.hud-error {
  margin: 0 auto;
  min-height: 0;
  color: #ffd2cb;
  text-align: center;
  font-size: 0.9rem;
}

.hud-error:empty {
  display: none;
}

.hud-drawn {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0;
  padding: 6px 10px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
}

.mini-card {
  width: 34px;
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
}

.hud-me {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.hud-me-face {
  width: 38px;
  height: 38px;
}

.hud-me-name {
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-me-score {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.hud-draw {
  min-height: 48px;
  min-width: 84px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 2px solid rgba(251, 246, 236, 0.25);
  background: rgba(21, 21, 26, 0.55);
  font-weight: 800;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.hud-draw.is-ready {
  border-color: var(--gold);
  background: rgba(242, 194, 48, 0.2);
}

.hud-draw:disabled {
  opacity: 0.45;
}

/* The big UNO button with its countdown ring. */
.uno-button {
  position: relative;
  width: 76px;
  height: 76px;
  flex: none;
  border-radius: 50%;
  border: 3px solid var(--paper);
  background: radial-gradient(circle at 35% 30%, #ff7a5c, var(--coral) 55%, #a62b20);
  color: var(--paper);
  box-shadow: 0 4px 0 var(--ink), 0 8px 18px rgba(0, 0, 0, 0.45);
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.uno-button:disabled {
  opacity: 0.5;
}

.uno-button:active:not(:disabled) {
  transform: scale(0.94);
}

.uno-label {
  position: relative;
  font-family: var(--display);
  font-weight: 900;
  font-size: 1.15rem;
  -webkit-text-stroke: 1px var(--ink);
  paint-order: stroke fill;
}

.uno-button.is-urgent {
  animation: urgent 0.45s ease-in-out infinite alternate;
}

@keyframes urgent {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.1);
  }
}

.uno-ring {
  position: absolute;
  inset: -9px;
  width: calc(100% + 18px);
  height: calc(100% + 18px);
  transform: rotate(-90deg);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.uno-ring.is-active {
  opacity: 1;
}

.uno-ring-track {
  fill: none;
  stroke: rgba(251, 246, 236, 0.25);
  stroke-width: 6;
}

.uno-ring-bar {
  fill: none;
  stroke: var(--gold);
  stroke-width: 6;
  stroke-linecap: round;
}

/* My hand: a fan of big cards; playable ones are lifted. */
.hand {
  position: relative;
  height: 180px;
  overflow: hidden;
  margin-top: 4px;
}

/* Too many cards for the screen: swipe the row sideways (the scrollbar is hidden so it takes no height;
   a soft fade on the edges hints that there is more). */
.hand.is-scrolling {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 22px), transparent 100%);
}

.hand.is-scrolling::-webkit-scrollbar {
  display: none;
}

.hand-track {
  position: relative;
  height: 100%;
}

.hand-card {
  position: absolute;
  left: 0;
  bottom: 6px;
  width: var(--hand-card-w, 90px);
  aspect-ratio: 2 / 3;
  padding: 0;
  border: 0;
  background: none;
  transform-origin: 50% 100%;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

.hand-card-img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 9%;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.45));
}

/* A soft golden glow behind playable cards (faded in with opacity). */
.hand-card::before {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 12%;
  background: var(--glow);
  filter: blur(6px);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.hand-card.is-playable::before {
  opacity: 0.85;
}

.hand-card.is-drawn::before {
  opacity: 1;
}

/* Darkened (not transparent, so overlapping cards do not show through). */
.hand-card.is-dimmed .hand-card-img {
  filter: brightness(0.55) saturate(0.6) drop-shadow(0 6px 8px rgba(0, 0, 0, 0.45));
}

.hand-card:disabled {
  cursor: default;
}

/* ---------------------------------------------------------------------------
   Overlays: colour picker, results, settings
   --------------------------------------------------------------------------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: calc(12px + var(--safe-top)) 12px calc(12px + var(--safe-bottom));
  background: rgba(12, 8, 10, 0.6);
  animation: fade-in 0.2s ease-out;
  overflow-y: auto;
}

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

.overlay-panel {
  width: min(100%, 420px);
  max-height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
}

.overlay-panel h2 {
  margin: 0;
}

.picker-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.picker-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 96px;
  border-radius: 16px;
  border: 3px solid var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  font-weight: 800;
  text-transform: capitalize;
  transition: transform 0.12s ease;
}

.picker-choice:active {
  transform: scale(0.95);
}

.picker-choice.red {
  background: var(--coral);
}
.picker-choice.yellow {
  background: var(--gold);
  color: var(--ink);
}
.picker-choice.green {
  background: var(--green);
}
.picker-choice.blue {
  background: var(--teal);
}

.picker-shape {
  width: 40px;
  height: 40px;
}

.result-face {
  width: 84px;
  height: 84px;
  margin: 0 auto;
}

.result-points {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--gold);
}

.result-scores {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  text-align: left;
}

.result-scores li {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 70px 48px;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 12px;
  background: rgba(251, 246, 236, 0.06);
}

.result-scores li.is-winner {
  background: rgba(242, 194, 48, 0.18);
}

.score-face {
  width: 32px;
  height: 32px;
}

.score-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.score-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(251, 246, 236, 0.15);
  overflow: hidden;
}

.score-fill {
  display: block;
  height: 100%;
  background: var(--gold);
  transform-origin: 0 50%;
  transition: transform 0.6s ease;
}

.score-total {
  text-align: right;
  font-weight: 800;
}

/* At the end of a round: everybody else's remaining cards, face up, with their points. */
.result-panel.has-hands {
  width: min(100%, 480px);
}

.result-hands {
  display: grid;
  gap: 8px;
  text-align: left;
}

.result-hands h3 {
  margin: 4px 0 0;
  font-size: 1rem;
}

.result-hand {
  display: grid;
  gap: 6px;
  padding: 6px 8px 8px;
  border-radius: 12px;
  background: rgba(251, 246, 236, 0.06);
}

.result-hand-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.result-hand-head .score-name {
  flex: 1;
}

.result-hand-count {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.result-hand-points {
  font-weight: 800;
  color: var(--gold);
  white-space: nowrap;
}

.result-hand-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.result-card {
  width: clamp(30px, 8.5vw, 42px);
  height: auto;
  border-radius: 4px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
}

/* With the cards shown the panel can get long on a phone: the main button stays in view at the bottom. */
.result-panel.has-hands > .pill.big {
  position: sticky;
  bottom: 0;
  box-shadow: 0 -10px 18px 6px var(--panel);
}

.result-hand-total {
  margin: 0;
  font-weight: 800;
  text-align: right;
}

.result-goal {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.graphics-options {
  border: 0;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  text-align: left;
}

.graphics-options legend {
  font-weight: 800;
  margin-bottom: 6px;
}

.graphics-option {
  display: grid;
  grid-template-columns: 24px auto;
  column-gap: 8px;
  align-items: center;
  margin: 0;
  padding: 8px 10px;
  min-height: 44px;
  border-radius: 12px;
  background: rgba(251, 246, 236, 0.06);
  font-weight: 400;
  cursor: pointer;
}

.graphics-option input {
  grid-row: span 2;
  width: 20px;
  height: 20px;
  accent-color: var(--gold);
}

.graphics-option span {
  color: var(--muted);
  font-size: 0.85rem;
}

.settings-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.settings-advanced {
  text-align: left;
  border-radius: 12px;
  background: rgba(251, 246, 236, 0.06);
  padding: 4px 10px;
}

.settings-advanced summary {
  font-weight: 800;
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
}

.settings-advanced[open] {
  padding-bottom: 10px;
}

.advanced-switches {
  display: grid;
  gap: 4px;
}

.advanced-switch {
  display: grid;
  grid-template-columns: 24px 1fr;
  column-gap: 8px;
  align-items: center;
  min-height: 40px;
  font-weight: 400;
  cursor: pointer;
}

.advanced-switch input {
  width: 20px;
  height: 20px;
  accent-color: var(--gold);
}

.advanced-switch input:disabled + span {
  opacity: 0.5;
}

.advanced-switch small {
  grid-column: 2;
}

.advanced-display {
  display: grid;
  gap: 4px;
  margin-top: 8px;
}

.advanced-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  font-weight: 400;
}

.advanced-row select {
  min-height: 36px;
  border-radius: 10px;
  padding: 2px 8px;
  font: inherit;
}

.advanced-row input[type='range'] {
  flex: 1;
  min-width: 100px;
  accent-color: var(--gold);
}

.advanced-row output {
  min-width: 3.5em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Settings → Advanced → "Show frame rate" */
.fps-meter {
  position: absolute;
  right: calc(10px + var(--safe-right, 0px));
  top: calc(var(--hud-top, 48px) + 4px);
  padding: 2px 8px;
  border-radius: 8px;
  background: rgba(21, 21, 26, 0.6);
  color: #fbf6ec;
  font: 600 12px/1.6 ui-monospace, 'Cascadia Mono', Consolas, monospace;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  z-index: 5;
}

.advanced-switch small,
.settings-hint {
  color: var(--muted);
  font-size: 0.8rem;
}

.settings-hint {
  margin: 8px 0;
}

.pill.small {
  min-height: 40px;
  padding: 6px 14px;
  font-size: 0.9rem;
}

.settings-links {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 0;
}

/* ---------------------------------------------------------------------------
   The flat 2D table ("Simple" graphics)
   --------------------------------------------------------------------------- */

.t2d {
  position: absolute;
  left: var(--safe-left);
  right: var(--safe-right);
  /* The top bar only has small things in its corners, so the table may reach up behind it. */
  top: calc(var(--safe-top) + 6px);
  bottom: var(--hud-bottom);
  container-type: size;
  /* Soft lawn and lamplight around the table. */
  background: radial-gradient(ellipse 70% 60% at 50% 55%, rgba(255, 200, 120, 0.16), transparent 70%);
}

.t2d-table {
  --d: min(92cqw, 94cqh);
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--d);
  height: var(--d);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  /* A round wooden table: rings of grain, darker rim. */
  background:
    radial-gradient(circle at 42% 35%, rgba(255, 230, 190, 0.22), transparent 55%),
    repeating-radial-gradient(circle at 50% 50%, rgba(80, 45, 20, 0) 0 9px, rgba(80, 45, 20, 0.16) 10px 11px),
    radial-gradient(circle, #b98251 0%, #9a6538 60%, #7a4a26 100%);
  box-shadow:
    inset 0 0 0 calc(var(--d) * 0.035) #5e3519,
    inset 0 0 0 calc(var(--d) * 0.045) #7b4a24,
    0 18px 40px rgba(0, 0, 0, 0.5);
}

.t2d-felt {
  position: absolute;
  inset: 22%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 220, 160, 0.14), transparent 70%);
}

.t2d-direction {
  position: absolute;
  inset: 9%;
  width: 82%;
  height: 82%;
  animation: spin 40s linear infinite;
}

.is-reversed .t2d-direction {
  animation-name: spin-reversed;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes spin-reversed {
  from {
    transform: scaleX(-1) rotate(0deg);
  }
  to {
    transform: scaleX(-1) rotate(360deg);
  }
}

.t2d-direction-arc {
  fill: none;
  stroke: rgba(251, 246, 236, 0.35);
  stroke-width: 3;
  stroke-linecap: round;
}

.t2d-direction-head {
  fill: rgba(251, 246, 236, 0.45);
}

.t2d-centre {
  --pile-w: clamp(42px, calc(var(--d) * 0.2), 120px);
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -54%);
  display: flex;
  align-items: center;
  gap: calc(var(--pile-w) * 0.45);
}

.t2d-drawpile {
  position: relative;
  width: var(--pile-w);
  aspect-ratio: 2 / 3;
  padding: 0;
  border: 0;
  background: none;
  transition: transform 0.15s ease;
}

.t2d-drawpile:active:not(:disabled) {
  transform: scale(0.96);
}

.t2d-stack {
  position: absolute;
  inset: 0;
}

.t2d-pile-card {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 9%;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}

.t2d-drawpile.is-ready .t2d-stack::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 14%;
  border: 3px solid var(--glow);
  animation: pulse-glow 1.1s ease-in-out infinite alternate;
}

@keyframes pulse-glow {
  from {
    opacity: 0.35;
  }
  to {
    opacity: 1;
  }
}

.t2d-count {
  position: absolute;
  left: 50%;
  bottom: -1.6em;
  transform: translateX(-50%);
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.t2d-discard {
  position: relative;
  width: var(--pile-w);
  aspect-ratio: 2 / 3;
}

.t2d-discard-cards {
  position: absolute;
  inset: 0;
}

.t2d-colour-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 190%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 5px solid transparent;
  opacity: 0.85;
  transition: opacity 0.3s ease;
}

.t2d-colour-ring.red {
  border-color: var(--coral);
}
.t2d-colour-ring.yellow {
  border-color: var(--gold);
}
.t2d-colour-ring.green {
  border-color: var(--green);
}
.t2d-colour-ring.blue {
  border-color: var(--teal);
}

.t2d-colour-chip {
  position: absolute;
  left: 50%;
  top: 74%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 6px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: capitalize;
  background: rgba(21, 21, 26, 0.55);
  border: 2px solid rgba(251, 246, 236, 0.2);
}

.t2d-colour-chip.red {
  border-color: var(--coral);
}
.t2d-colour-chip.yellow {
  border-color: var(--gold);
}
.t2d-colour-chip.green {
  border-color: var(--green);
}
.t2d-colour-chip.blue {
  border-color: var(--teal);
}

.t2d-chip-shape {
  width: 18px;
  height: 18px;
}

/* A golden glow on my side of the table when it is my turn. */
.t2d-my-glow {
  position: absolute;
  left: 15%;
  right: 15%;
  bottom: -2%;
  height: 16%;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 100%, rgba(255, 216, 107, 0.75), transparent 70%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.is-my-turn .t2d-my-glow {
  opacity: 1;
  animation: pulse-glow 1.2s ease-in-out infinite alternate;
}

/* Opponents around the table. */
.t2d-seats {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.t2d-seat {
  --d: min(92cqw, 94cqh);
  --seat-card-w: clamp(20px, 6.5cqmin, 38px);
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 120px;
  transition: opacity 0.3s ease;
}

.slot-top {
  left: 50%;
  top: max(0px, calc(50cqh - var(--d) / 2 - 44px));
  transform: translateX(-50%);
}

.slot-top-left {
  left: max(60px, calc(50cqw - var(--d) * 0.36));
  top: max(0px, calc(50cqh - var(--d) / 2 - 30px));
  transform: translateX(-50%);
}

.slot-top-right {
  left: min(calc(100cqw - 60px), calc(50cqw + var(--d) * 0.36));
  top: max(0px, calc(50cqh - var(--d) / 2 - 30px));
  transform: translateX(-50%);
}

.slot-left {
  left: max(60px, calc(50cqw - var(--d) / 2 - 30px));
  top: 50%;
  transform: translate(-50%, -60%);
}

.slot-right {
  left: min(calc(100cqw - 60px), calc(50cqw + var(--d) / 2 + 30px));
  top: 50%;
  transform: translate(-50%, -60%);
}

.t2d-fan {
  position: relative;
  width: var(--seat-card-w);
  height: calc(var(--seat-card-w) * 1.5);
  margin-bottom: -10px;
}

.t2d-fan-card {
  position: absolute;
  inset: 0;
  width: 100%;
  transform-origin: 50% 110%;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
}

.t2d-face {
  position: relative;
  width: 54px;
  height: 54px;
}

.t2d-face-img {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(21, 21, 26, 0.55);
  border: 2px solid rgba(251, 246, 236, 0.25);
}

.t2d-glow {
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 216, 107, 0.85), rgba(255, 216, 107, 0) 70%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.is-turn .t2d-glow {
  opacity: 1;
  animation: pulse-glow 1.1s ease-in-out infinite alternate;
}

.is-turn .t2d-face-img {
  border-color: var(--glow);
}

.t2d-badge {
  position: absolute;
  right: -8px;
  top: -6px;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 900;
  font-size: 0.8rem;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
}

.t2d-uno {
  position: absolute;
  left: 50%;
  bottom: -10px;
  transform: translateX(-50%) rotate(-6deg);
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--coral);
  border: 2px solid var(--paper);
  font-family: var(--display);
  font-weight: 900;
  font-size: 0.75rem;
}

.t2d-zzz {
  position: absolute;
  right: -14px;
  top: -18px;
  font-weight: 900;
  color: var(--muted);
  animation: zzz 2s ease-in-out infinite;
}

@keyframes zzz {
  from {
    opacity: 0.2;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(-4px);
  }
}

.is-away {
  opacity: 0.55;
}

.t2d-name {
  margin-top: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(21, 21, 26, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 120px;
  line-height: 1.2;
}

.t2d-name-text {
  font-weight: 800;
  font-size: 0.85rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.t2d-score {
  font-size: 0.7rem;
  color: var(--muted);
}

/* Very short table area (phone lying sideways): smaller seats, the top seat hugs the top edge. */
@container (max-height: 300px) {
  .t2d-seat {
    --seat-card-w: 20px;
  }

  .t2d-face {
    width: 40px;
    height: 40px;
  }

  .slot-top,
  .slot-top-left,
  .slot-top-right {
    top: 0;
  }

  .slot-top {
    flex-direction: row;
    gap: 6px;
    width: auto;
    transform: translateX(-50%) translateY(-12%);
  }

  .slot-top .t2d-fan {
    margin-bottom: 0;
  }

  .t2d-name {
    margin-top: 2px;
  }
}

/* ---------------------------------------------------------------------------
   Wide screens (desktops, phones lying sideways): hand and buttons side by side,
   so the table keeps as much height as possible
   --------------------------------------------------------------------------- */

@media (orientation: landscape) {
  .hud-bottom {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 12px;
    align-items: end;
  }

  /* The message, the error line and the "you drew" panel float just above the hand instead of taking rows. */
  .hud-message,
  .hud-error,
  .hud-drawn {
    position: absolute;
    left: 0;
    right: 0;
    width: max-content;
    max-width: 92%;
    margin: 0 auto;
  }

  .hud-message {
    bottom: calc(100% + 4px);
  }

  .hud-drawn {
    bottom: calc(100% + 36px);
  }

  .hud-error {
    bottom: calc(100% + 36px);
    padding: 3px 12px;
    border-radius: 999px;
    background: rgba(21, 21, 26, 0.75);
  }

  .hud-notes {
    bottom: calc(var(--hud-bottom) + 40px);
  }

  .hud-actions {
    grid-column: 2;
    grid-row: 4;
    flex-direction: column-reverse;
    align-items: center;
    gap: 10px;
    padding-bottom: 10px;
  }

  .hud-me {
    flex-direction: column;
    gap: 2px;
    flex: none;
    max-width: 110px;
  }

  .hand {
    grid-column: 1;
    grid-row: 4;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .hud-me {
    display: none;
  }

  .uno-button {
    width: 64px;
    height: 64px;
  }

  .t2d-face {
    width: 44px;
    height: 44px;
  }
}

/* ---------------------------------------------------------------------------
   Less motion when the visitor asked their system for it
   --------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .cat-breath,
  .cat-tail,
  .cat-eyes {
    animation: none !important;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
}
