/* ============================================================
   The Velvet Rail — billiards parlour
   dark charcoal room · steel-blue felt · walnut · brass gold
   ============================================================ */

:root {
  --bg: #101318;
  --bg-2: #171b22;
  --ink: #e8e4da;
  --ink-dim: #9a958a;
  --gold: #c9a35c;
  --gold-bright: #e6c789;
  --felt: #35586e;
  --line: rgba(201, 163, 92, 0.25);
  --glass: rgba(16, 19, 24, 0.72);
  --danger: #c25549;
  --font-display: 'Marcellus', 'Palatino Linotype', serif;
  --font-body: 'Instrument Sans', 'Avenir Next', sans-serif;
}

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

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  height: 100dvh;
  position: relative;
}

/* felt-room atmosphere: vignette + grain */
body::before {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 5;
  background:
    radial-gradient(120% 90% at 50% 30%, transparent 40%, rgba(0,0,0,0.45) 100%);
}
body::after {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 5;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
}

#game {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: block;
}

.hidden { display: none !important; }

/* ---------------- HUD ---------------- */

#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }

#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 58px;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  padding: 0 14px;
  background: linear-gradient(to bottom, rgba(10,12,16,0.85), rgba(10,12,16,0.35) 80%, transparent);
  pointer-events: none;
}

.player {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-width: 130px;
  padding: 6px 12px;
  border-bottom: 2px solid transparent;
  transition: border-color 0.25s, opacity 0.25s;
  opacity: 0.45;
}
.player.active {
  opacity: 1;
  border-bottom-color: var(--gold);
}
.player.active .pname { color: var(--gold-bright); }
.player.right { align-items: flex-end; }

.pline { display: flex; align-items: baseline; gap: 8px; }
.pname {
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: 0.06em;
  transition: color 0.25s;
}
.ptag {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.tray { display: flex; gap: 4px; height: 14px; }
.tray .tball {
  width: 13px; height: 13px;
  border-radius: 50%;
  box-shadow: inset -1px -2px 3px rgba(0,0,0,0.5), 0 1px 2px rgba(0,0,0,0.6);
  opacity: 0;
  transform: translateY(-6px);
  animation: tball-in 0.35s ease forwards;
}
.tray .tball.stripe-icon {
  background-image: linear-gradient(to bottom, #f6f2e7 22%, transparent 22%, transparent 78%, #f6f2e7 78%);
}
@keyframes tball-in { to { opacity: 1; transform: none; } }

#status {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 0 10px;
}
#status-text {
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  text-align: center;
  transition: color 0.3s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46vw;
}

/* ---------------- controls (spin / power / menu) ---------------- */

#controls {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  pointer-events: auto;
}

.ctl {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(8px);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, transform 0.15s;
}
.ctl:active { transform: scale(0.94); }
.ctl:hover { border-color: var(--gold); }

.spin-face {
  position: relative;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fffdf5, #ded8c8 70%, #b9b2a1);
  box-shadow: inset -2px -3px 5px rgba(0,0,0,0.25);
}
.spin-dot {
  position: absolute;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--danger);
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  transition: left 0.15s, top 0.15s;
}
.spin-btn-set .spin-dot { box-shadow: 0 0 6px var(--danger); }

#power {
  position: relative;
  width: 46px;
  height: min(38vh, 300px);
  border-radius: 23px;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(8px);
  overflow: hidden;
  cursor: grab;
}
#power-fill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 0%;
  background: linear-gradient(to top, #7a4a2c, var(--gold) 60%, var(--gold-bright));
  transition: height 0.05s linear;
}
#power .plabel {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%) rotate(-90deg);
  font-size: 10px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--ink-dim);
  pointer-events: none;
  mix-blend-mode: difference;
}

/* ---------------- fine aim strip ---------------- */

#fine-aim {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 26px;
  background: linear-gradient(to top, rgba(10,12,16,0.85), transparent);
  color: var(--ink-dim);
  pointer-events: auto;
  cursor: ew-resize;
}
#fine-aim .chev { font-size: 20px; opacity: 0.7; }
#fine-aim .fa-label {
  font-size: 10px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
}
#fine-aim.dragging { color: var(--gold); }

/* portrait layout: controls move to a bottom row */
body.portrait #controls {
  top: auto;
  right: auto;
  bottom: 52px;
  left: 0;
  width: 100%;
  transform: none;
  flex-direction: row;
  justify-content: center;
  gap: 16px;
  padding: 0 14px;
}
body.portrait #power {
  width: min(52vw, 260px);
  height: 46px;
  border-radius: 23px;
}
body.portrait #power-fill {
  left: 0; top: 0; bottom: 0;
  right: auto;
  height: 100%;
  width: 0%;
  background: linear-gradient(to right, #7a4a2c, var(--gold) 60%, var(--gold-bright));
}
body.portrait #power .plabel { transform: translate(-50%, -50%); }
body.portrait #topbar { padding: 0 8px; }
body.portrait .player { min-width: 96px; padding: 6px 6px; }
body.portrait #status-text { font-size: 11px; }

/* ---------------- toast ---------------- */

#toast {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  background: var(--glass);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px 22px;
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 0.1em;
  color: var(--gold-bright);
  pointer-events: none;
  animation: toast-in 0.3s ease;
  max-width: 90vw;
  text-align: center;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -8px); }
}
#toast.out { opacity: 0; transition: opacity 0.4s; }

/* ---------------- overlays ---------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 13, 0.62);
  backdrop-filter: blur(6px);
  animation: fade-in 0.25s ease;
}
@keyframes fade-in { from { opacity: 0; } }

.spin-card, .sheet-card, .over-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 26px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
  animation: card-in 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes card-in { from { opacity: 0; transform: translateY(14px) scale(0.97); } }

.spin-card h3, .sheet-card h3 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 17px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

#spin-big {
  position: relative;
  width: min(56vw, 230px);
  height: min(56vw, 230px);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fffdf5, #e6e0d0 55%, #b9b2a1);
  box-shadow: inset -8px -14px 30px rgba(0,0,0,0.28), 0 10px 30px rgba(0,0,0,0.5);
  cursor: crosshair;
  touch-action: none;
}
#spin-big .cross-h, #spin-big .cross-v {
  position: absolute;
  background: rgba(0,0,0,0.12);
  pointer-events: none;
}
#spin-big .cross-h { left: 8%; right: 8%; top: 50%; height: 1px; }
#spin-big .cross-v { top: 8%; bottom: 8%; left: 50%; width: 1px; }
.spin-dot.big {
  width: 18px; height: 18px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  transition: none;
}

.row { display: flex; gap: 12px; }

.btn {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 12px 26px;
  border-radius: 3px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  transition: all 0.2s;
  min-height: 44px;
}
.btn.gold {
  background: var(--gold);
  border-color: var(--gold);
  color: #16130c;
}
.btn.gold:hover { background: var(--gold-bright); }
.btn.ghost:hover { border-color: var(--gold); color: var(--gold-bright); }
.btn.wide { width: 240px; }

/* ---------------- game over ---------------- */

.over-card { padding: 40px 54px; }
.over-kicker {
  font-size: 11px;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
#over-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(26px, 6vw, 40px);
  color: var(--gold-bright);
  text-align: center;
}
#over-reason { color: var(--ink-dim); font-size: 14px; text-align: center; }

/* ---------------- main menu ---------------- */

#menu-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(90% 70% at 50% 12%, rgba(53, 88, 110, 0.34), transparent 60%),
    linear-gradient(to bottom, #0c0e12, var(--bg) 45%, #0b0d11);
  overflow: hidden;
  transition: opacity 0.45s ease, visibility 0.45s;
}
#menu-screen.closing { opacity: 0; visibility: hidden; }

.menu-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px;
  max-width: 680px;
  width: 100%;
}
.menu-inner > * {
  opacity: 0;
  transform: translateY(16px);
  animation: rise 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}
.menu-inner > *:nth-child(1) { animation-delay: 0.05s; }
.menu-inner > *:nth-child(2) { animation-delay: 0.15s; }
.menu-inner > *:nth-child(3) { animation-delay: 0.25s; }
.menu-inner > *:nth-child(4) { animation-delay: 0.35s; }
.menu-inner > *:nth-child(5) { animation-delay: 0.45s; }
.menu-inner > *:nth-child(6) { animation-delay: 0.6s; }
@keyframes rise { to { opacity: 1; transform: none; } }

.crest {
  font-size: 13px;
  color: var(--gold);
  letter-spacing: 0.5em;
  margin-bottom: 10px;
}
#menu-screen h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(38px, 9vw, 68px);
  letter-spacing: 0.04em;
  color: var(--ink);
  line-height: 1.05;
}
#menu-screen .sub {
  margin-top: 8px;
  font-family: var(--font-display);
  font-size: clamp(13px, 3vw, 16px);
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--gold);
}
.rule {
  width: 72px;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--gold), transparent);
  margin: 30px 0;
}

.modes {
  display: flex;
  gap: 16px;
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
}
.mode-card {
  flex: 1 1 220px;
  max-width: 280px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  gap: 8px;
  padding: 22px 24px 20px;
  background: rgba(53, 88, 110, 0.10);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.25s ease;
}
.mode-card:hover, .mode-card:focus-visible {
  background: rgba(53, 88, 110, 0.24);
  border-color: var(--gold);
  transform: translateY(-3px);
  box-shadow: 0 16px 40px rgba(0,0,0,0.45);
  outline: none;
}
.mode-num {
  font-size: 10px;
  letter-spacing: 0.34em;
  color: var(--gold);
}
.mode-name {
  font-family: var(--font-display);
  font-size: 24px;
  letter-spacing: 0.03em;
}
.mode-desc {
  font-size: 12px;
  color: var(--ink-dim);
  letter-spacing: 0.04em;
}

.hint {
  margin-top: 34px;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
  text-transform: uppercase;
}

@media (max-width: 480px) {
  .hint { display: none; }
  .over-card { padding: 30px 26px; }
}
