/* Oink! Mahjong — design tokens, the scaled 1600x900 stage and shared controls
   (buttons, panels, toggles, segmented choices, sliders). Used by every screen and the table. */

:root {
  --cream: #fff8ec;
  --cream-2: #fbeedb;
  --cream-3: #f4e1c4;
  --cream-edge: #e2c9a3;
  --jade: #2e9e6b;
  --jade-dark: #1f7a51;
  --jade-deep: #155c3c;
  --jade-light: #cdeedc;
  --gold: #f2b632;
  --gold-dark: #c98d14;
  --gold-light: #ffe7a8;
  --coral: #e5484d;
  --coral-dark: #b5313a;
  --coral-light: #ffd9d6;
  --choc: #4a2c23;
  --choc-soft: #7b5b4c;
  --pink: #f7a1b8;
  --pink-light: #ffe3ea;

  --font-display: "Fredoka", "Arial Rounded MT Bold", "Nunito", system-ui, sans-serif;
  --font-body: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-cn: "Noto Serif SC", "Songti SC", "SimSun", serif;

  --shadow-soft: 0 10px 30px rgba(74, 44, 35, .18), 0 2px 6px rgba(74, 44, 35, .12);
  --shadow-panel: 0 0 0 6px rgba(255, 255, 255, .55), 0 28px 70px rgba(40, 20, 10, .45);
  --ease-pop: cubic-bezier(.2, 1.5, .4, 1);
  --ease-out: cubic-bezier(.2, .8, .3, 1);
  --t-screen: 420ms;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #2b1a16;
  color: var(--choc);
  font: 600 18px/1.4 var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  /* The page itself never scrolls, bounces or pull-to-refreshes (a pull-down on the table would reload
     the game mid-hand), and double-tap never zooms (it left the table zoomed with the hand off-screen).
     Pinch-zoom stays allowed; js/ui/viewport.js re-fits the stage to whatever is visible. Tiles and
     piggies keep their own touch-action: none, scroll lists keep panning (manipulation allows pan). */
  overscroll-behavior: none;
  touch-action: manipulation;
}

button, input, select, textarea { font: inherit; color: inherit; }
img { -webkit-user-drag: none; }

/* ---- letterbox backdrop + stage ------------------------------------------------------------ */

#backdrop {
  position: fixed; left: 0; top: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at 50% 40%, #6b3d2f 0%, #3a2019 60%, #24130f 100%);
}
#backdrop .backdrop-art {
  position: absolute; left: -6%; top: -6%; width: 112%; height: 112%;
  background-size: cover; background-position: center;
  filter: blur(26px) saturate(1.15) brightness(.55);
  opacity: 0; transition: opacity .8s ease;
}
#backdrop .backdrop-art.is-on { opacity: 1; }

/* Fixed, so the unscaled 1600px box never widens the page (phones would otherwise zoom out to fit it). */
#stage {
  position: fixed; left: 0; top: 0;
  width: 1600px; height: 900px;
  overflow: hidden;
  transform-origin: 0 0;
  background: var(--cream-2);
  box-shadow: 0 0 60px rgba(0, 0, 0, .45);
  -webkit-user-select: none; user-select: none;
  contain: layout paint;
}

.screen-layer, .overlay-layer { position: absolute; left: 0; top: 0; width: 1600px; height: 900px; }
.overlay-layer { z-index: 50; pointer-events: none; }
.overlay-layer > * { pointer-events: auto; }

/* boot splash (outside the stage, before JS has scaled anything) */
#boot {
  position: fixed; left: 0; top: 0; right: 0; bottom: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  color: var(--cream); font: 700 20px/1.2 var(--font-display); letter-spacing: .5px;
  background: radial-gradient(ellipse at 50% 40%, #6b3d2f 0%, #3a2019 60%, #24130f 100%);
  transition: opacity .45s ease;
}
#boot p { margin: 0; }
#boot.is-done { opacity: 0; pointer-events: none; }
.boot-snout {
  position: relative; width: 92px; height: 70px; border-radius: 46px / 35px;
  background: radial-gradient(ellipse at 40% 30%, #ffd3de, #f590a9 70%, #e07190);
  box-shadow: 0 6px 0 #c55f7c, 0 12px 26px rgba(0, 0, 0, .35);
  animation: boot-bounce 1s var(--ease-pop) infinite alternate;
}
.boot-snout::before, .boot-snout::after {
  content: ""; position: absolute; top: 22px; width: 17px; height: 26px; border-radius: 50%; background: #9c3f5a;
}
.boot-snout::before { left: 23px; }
.boot-snout::after { right: 23px; }
@keyframes boot-bounce { from { transform: translateY(0) scale(1, 1); } to { transform: translateY(-14px) scale(.96, 1.04); } }

/* portrait phones: a friendly nudge to turn sideways */
#rotate-hint {
  position: fixed; left: 12px; right: 12px; top: 12px; z-index: 90;
  display: none; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--cream); color: var(--choc); border-radius: 16px; box-shadow: var(--shadow-soft);
  font: 700 15px/1.3 var(--font-body);
}
#rotate-hint .rot-icon { font-size: 26px; }
@media (orientation: portrait) and (max-width: 820px) {
  #rotate-hint { display: flex; }
}

/* ---- accessibility helpers ------------------------------------------------------------------ */

.sr-only {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* Focus rings: :focus everywhere, hidden again for pointer focus where :focus-visible exists. */
#stage :focus { outline: 4px solid var(--jade); outline-offset: 3px; }
#stage :focus:not(:focus-visible) { outline: none; }
#stage .btn-jade:focus, #stage .btn-coral:focus { outline-color: var(--gold); }

.cn { font-family: var(--font-cn); font-weight: 900; }

/* ---- buttons -------------------------------------------------------------------------------- */

.btn {
  --b-bg: var(--cream);
  --b-fg: var(--choc);
  --b-edge: var(--cream-edge);
  --b-hi: rgba(255, 255, 255, .85);
  --b-lift: 6px;
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 60px; padding: 10px 28px 12px;
  border: 0; border-radius: 20px;
  background: var(--b-bg);
  color: var(--b-fg);
  font: 600 24px/1.1 var(--font-display);
  letter-spacing: .3px;
  cursor: pointer;
  box-shadow: inset 0 3px 0 var(--b-hi), 0 var(--b-lift) 0 var(--b-edge), 0 calc(var(--b-lift) + 6px) 16px rgba(60, 30, 20, .28);
  transform: translateY(0);
  transition: transform .12s ease, box-shadow .12s ease, filter .15s ease;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.04); transform: translateY(-2px); box-shadow: inset 0 3px 0 var(--b-hi), 0 calc(var(--b-lift) + 2px) 0 var(--b-edge), 0 calc(var(--b-lift) + 10px) 20px rgba(60, 30, 20, .3); }
.btn:active, .btn.is-pressed {
  transform: translateY(calc(var(--b-lift) - 1px));
  box-shadow: inset 0 3px 0 var(--b-hi), 0 1px 0 var(--b-edge), 0 3px 8px rgba(60, 30, 20, .25);
  transition-duration: .05s;
}
.btn[disabled] { filter: grayscale(.6) opacity(.6); cursor: default; transform: none; }
.btn .btn-sub { display: block; font: 700 14px/1.2 var(--font-body); opacity: .8; letter-spacing: 0; }
.btn .btn-stack { display: flex; flex-direction: column; align-items: center; }
.btn svg { width: 1.1em; height: 1.1em; flex: none; }

.btn-jade  { --b-bg: linear-gradient(#3dba81, var(--jade) 60%); --b-fg: #fff; --b-edge: var(--jade-deep); --b-hi: rgba(255, 255, 255, .35); text-shadow: 0 2px 0 rgba(0, 0, 0, .18); }
.btn-gold  { --b-bg: linear-gradient(#ffd060, var(--gold) 65%); --b-fg: var(--choc); --b-edge: var(--gold-dark); --b-hi: rgba(255, 255, 255, .55); }
.btn-coral { --b-bg: linear-gradient(#f06a6d, var(--coral) 65%); --b-fg: #fff; --b-edge: var(--coral-dark); --b-hi: rgba(255, 255, 255, .3); text-shadow: 0 2px 0 rgba(0, 0, 0, .18); }
.btn-ghost { --b-bg: rgba(255, 248, 236, .18); --b-fg: var(--cream); --b-edge: rgba(0, 0, 0, .25); --b-hi: rgba(255, 255, 255, .2); }

.btn-lg { min-height: 84px; padding: 12px 46px 16px; border-radius: 26px; font-size: 36px; --b-lift: 8px; }
.btn-sm { min-height: 46px; padding: 6px 18px 8px; border-radius: 15px; font-size: 19px; --b-lift: 4px; }
.btn-icon { width: 60px; min-height: 60px; padding: 0; border-radius: 50%; }
.btn-icon.btn-sm { width: 46px; min-height: 46px; }

/* ---- panels & cards ------------------------------------------------------------------------- */

.panel {
  position: relative;
  background: var(--cream);
  border-radius: 34px;
  box-shadow: var(--shadow-panel);
  color: var(--choc);
}
.panel-title {
  margin: 0; font: 700 44px/1.1 var(--font-display); color: var(--choc); letter-spacing: .3px;
}
.panel-close { position: absolute; right: 22px; top: 22px; z-index: 2; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px 5px;
  border-radius: 999px; background: var(--cream-2); color: var(--choc);
  font: 800 15px/1.2 var(--font-body);
}

.stars { display: inline-flex; gap: 3px; }
.star { width: 24px; height: 24px; }
.star.is-off { opacity: .28; filter: grayscale(1); }

/* ---- overlays (modal dialogs) --------------------------------------------------------------- */

.overlay {
  position: absolute; left: 0; top: 0; width: 1600px; height: 900px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(45, 24, 18, .5);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  animation: overlay-in .28s ease both;
}
.overlay > .panel { animation: panel-in .42s var(--ease-pop) both; }
.overlay.is-leaving { pointer-events: none; animation: overlay-out .22s ease both; }
.overlay.is-leaving > .panel { animation: panel-out .22s ease both; }
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes overlay-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes panel-in { from { transform: translateY(26px) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes panel-out { to { transform: translateY(14px) scale(.96); opacity: 0; } }

/* ---- form controls ---------------------------------------------------------------------------- */

/* Segmented choice: <div class="seg"><label><input type="radio"><span>Quick</span></label>…</div> */
.seg {
  display: inline-flex; padding: 5px; gap: 4px; border-radius: 18px;
  background: var(--cream-3); box-shadow: inset 0 2px 4px rgba(74, 44, 35, .16);
}
.seg label { position: relative; display: block; cursor: pointer; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.seg span {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 108px; min-height: 48px; padding: 6px 18px; border-radius: 14px;
  font: 600 20px/1.1 var(--font-display); color: var(--choc-soft);
  transition: background .15s ease, color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.seg span small { font: 700 12px/1.2 var(--font-body); opacity: .8; margin-top: 2px; }
.seg label:hover span { color: var(--choc); background: rgba(255, 255, 255, .45); }
.seg input:checked + span {
  background: var(--jade); color: #fff;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .3), 0 3px 0 var(--jade-deep), 0 5px 10px rgba(21, 92, 60, .3);
  transform: translateY(-2px);
}
.seg input:focus + span { outline: 4px solid var(--gold); outline-offset: 2px; }
.seg input:focus:not(:focus-visible) + span { outline: none; }

/* Toggle switch: <label class="toggle"><input type="checkbox" role="switch"><span class="toggle-track"></span></label> */
.toggle { position: relative; display: inline-block; width: 82px; height: 44px; cursor: pointer; flex: none; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.toggle-track {
  position: absolute; left: 0; top: 0; right: 0; bottom: 0; border-radius: 22px;
  background: #d9c6ab; box-shadow: inset 0 2px 5px rgba(74, 44, 35, .25);
  transition: background .18s ease;
}
.toggle-track::after {
  content: ""; position: absolute; left: 4px; top: 4px; width: 36px; height: 36px; border-radius: 50%;
  background: #fffdf8; box-shadow: 0 2px 0 rgba(74, 44, 35, .2), 0 3px 8px rgba(74, 44, 35, .25);
  transition: transform .22s var(--ease-pop);
}
.toggle input:checked + .toggle-track { background: var(--jade); }
.toggle input:checked + .toggle-track::after { transform: translateX(38px); }
.toggle input:focus + .toggle-track { outline: 4px solid var(--gold); outline-offset: 3px; }
.toggle input:focus:not(:focus-visible) + .toggle-track { outline: none; }

/* Slider */
.slider { -webkit-appearance: none; appearance: none; width: 220px; height: 30px; background: transparent; cursor: pointer; margin: 0; }
.slider::-webkit-slider-runnable-track { height: 12px; border-radius: 6px; background: linear-gradient(to right, var(--jade) 0, var(--jade) var(--fill, 50%), #dcc8ac var(--fill, 50%)); box-shadow: inset 0 1px 3px rgba(74, 44, 35, .25); }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 30px; height: 30px; margin-top: -9px; border-radius: 50%; background: #fffdf8; border: 3px solid var(--jade); box-shadow: 0 2px 6px rgba(74, 44, 35, .3); }
.slider::-moz-range-track { height: 12px; border-radius: 6px; background: #dcc8ac; }
.slider::-moz-range-progress { height: 12px; border-radius: 6px; background: var(--jade); }
.slider::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: #fffdf8; border: 3px solid var(--jade); }
.slider[disabled] { opacity: .45; cursor: default; }

.text-input {
  width: 100%; height: 60px; padding: 0 20px; border-radius: 18px;
  border: 3px solid var(--cream-edge); background: #fffdf8;
  font: 700 26px/1 var(--font-body); color: var(--choc);
  box-shadow: inset 0 2px 5px rgba(74, 44, 35, .12);
  -webkit-user-select: text; user-select: text;
}
.text-input:focus { border-color: var(--jade); }

/* ---- reduced motion ------------------------------------------------------------------------- */

/* The table handles settings.reduceMotion itself; this covers the menus, overlays and transitions. */
.reduce-motion .screen, .reduce-motion .menu-screen *, .reduce-motion .menu-screen *::before, .reduce-motion .menu-screen *::after,
.reduce-motion .overlay, .reduce-motion .overlay *, .reduce-motion .overlay *::before, .reduce-motion .overlay *::after {
  animation-duration: .01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .01ms !important;
}

/* ---- effects: lite (js/ui/perf.js sets .fx-lite on <html> and <body> for older devices) ------------
   The same screens without the costly bits: no backdrop blur, no blurred full-screen art, no filter
   pulses, and quicker dialog transitions. Colours are tuned so the result still reads the same. */
.fx-lite #backdrop .backdrop-art { display: none; }
.fx-lite .overlay { -webkit-backdrop-filter: none; backdrop-filter: none; background: rgba(45, 24, 18, .64); animation-duration: .2s; }
.fx-lite .overlay > .panel { animation-duration: .28s; }
.fx-lite .overlay.is-leaving, .fx-lite .overlay.is-leaving > .panel { animation-duration: .16s; }
.fx-lite .btn:hover { filter: none; }
