:root {
  --bg: #0d1320;
  --panel: #16203a;
  --panel-edge: #24335c;
  --text: #e8edf7;
  --muted: #8b98b8;
  --gold: #f5c542;
  --green: #4ade80;
  --red: #f87171;
  --blue: #60a5fa;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

main { max-width: 1000px; margin: 0 auto; padding: 24px 16px 64px; }

h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; margin-top: 0; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-edge);
}
.brand { font-weight: 700; color: var(--gold); font-size: 1.1rem; }
.topnav { display: flex; align-items: center; gap: 16px; }
.who { color: var(--muted); }

.flash {
  max-width: 1000px;
  margin: 16px auto 0;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
}
.flash-success { background: #14351f; color: var(--green); border: 1px solid #1d5a33; }
.flash-error { background: #3a1518; color: var(--red); border: 1px solid #6b2226; }

.card {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}

.auth-card { max-width: 380px; margin: 60px auto; }

.balance-row { display: flex; gap: 20px; flex-wrap: wrap; }
.balance-card { flex: 1; min-width: 220px; }
.balance-label { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; }
.balance-value { font-size: 2rem; font-weight: 700; color: var(--gold); margin: 6px 0; }
.balance-value.won { color: var(--green); }

label { display: block; margin-bottom: 14px; color: var(--muted); font-size: 0.9rem; }
input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--panel-edge);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.btn {
  display: inline-block;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--panel-edge);
  background: var(--panel-edge);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover:not(:disabled) { filter: brightness(1.2); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--gold); border-color: var(--gold); color: #201a05; }
.btn-small { padding: 4px 10px; font-size: 0.85rem; }

.linklike {
  background: none;
  border: none;
  color: var(--blue);
  cursor: pointer;
  font-size: 1rem;
  padding: 0;
}
.linklike:hover { text-decoration: underline; }
.inline { display: inline; }

.transfer-form { display: flex; gap: 8px; margin-top: 8px; }
.transfer-form input { width: auto; flex: 1; margin-top: 0; }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--panel-edge); }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--green); }
.neg { color: var(--red); }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}
.tag-load { background: #1d3a5c; color: var(--blue); }
.tag-transfer { background: #3a2f14; color: var(--gold); }
.tag-bet { background: #3a1518; color: var(--red); }
.tag-win { background: #14351f; color: var(--green); }
.tag-adjust { background: #2c2440; color: #c4b5fd; }
.tag-admin { background: #3a2f14; color: var(--gold); margin-left: 6px; }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}
.setting { margin-bottom: 0; }
.setting-key {
  display: block;
  color: var(--text);
  font-weight: 600;
  text-transform: capitalize;
  margin-bottom: 4px;
}
.setting-desc {
  display: block;
  font-size: 0.8rem;
  margin-top: 4px;
  line-height: 1.35;
}

/* ---------- game table ---------- */

.game-body { overflow: hidden; }

#stage { position: fixed; inset: 0; background: #03101f; }
#game { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }

.exit {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(22, 32, 58, 0.85);
  border: 1px solid var(--panel-edge);
  color: var(--muted);
  font-size: 0.85rem;
}
.exit:hover { color: var(--text); text-decoration: none; }

#mute, #music, #fs {
  position: absolute;
  top: 12px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgba(22, 32, 58, 0.85);
  border: 1px solid var(--panel-edge);
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
}
#mute { left: calc(50% + 72px); }
#music { left: calc(50% + 112px); }
#fs { left: calc(50% + 152px); color: var(--muted); }
#mute:hover, #music:hover, #fs:hover { filter: brightness(1.3); }
#music.off { opacity: 0.35; }

/* remove double-tap-to-zoom on everything in the game (iOS ignores the
   viewport user-scalable flag, but it does honor touch-action) */
.game-body, .game-body * { touch-action: manipulation; }

/* no text selection or long-press copy/lookup callout during play */
.game-body, .game-body * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* mobile: block portrait play (landscape-only table) */
#rotate-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #03101f;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--gold);
  font-size: 1.15rem;
  font-weight: 600;
  text-align: center;
}
.rotate-icon {
  font-size: 64px;
  animation: rotate-hint 2.2s ease-in-out infinite;
}
@keyframes rotate-hint {
  0%, 15% { transform: rotate(0); }
  50%, 75% { transform: rotate(90deg); }
  100% { transform: rotate(90deg); }
}
@media (pointer: coarse) and (orientation: portrait) {
  #rotate-overlay { display: flex; }
}

/* keep panels clear of phone notches in landscape */
#panel-0, #panel-2 { left: max(4%, env(safe-area-inset-left)); }
#panel-1, #panel-3 { right: max(4%, env(safe-area-inset-right)); }

.player-panel {
  position: absolute;
  width: 230px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(22, 32, 58, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--panel-edge);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  font-size: 0.9rem;
  user-select: none;
}
.player-panel.mine { border-color: var(--gold); box-shadow: 0 0 18px rgba(245, 197, 66, 0.25); }
.player-panel.empty { opacity: 0.45; }
#panel-0 { bottom: 14px; left: 4%; }
#panel-1 { bottom: 14px; right: 4%; }
#panel-2 { top: 14px; left: 4%; }
#panel-3 { top: 14px; right: 4%; }

.pp-wait { color: var(--muted); text-align: center; padding: 14px 0; }
.pp-name { font-weight: 700; margin-bottom: 6px; }
.pp-you {
  font-size: 0.7rem;
  color: #201a05;
  background: var(--gold);
  border-radius: 999px;
  padding: 1px 8px;
  vertical-align: middle;
}
.pp-row {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  margin: 4px 0;
}
.pp-row span { color: var(--muted); }
.pp-row b { color: var(--gold); font-variant-numeric: tabular-nums; }
.pp-row b.pp-won { color: var(--green); }
.pp-bet { justify-content: center; margin-top: 8px; }
.pp-bet b { color: var(--text); }

.pp-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--panel-edge);
  background: var(--panel-edge);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}
.pp-btn { touch-action: none; }
.pp-btn:hover { filter: brightness(1.3); }
.pp-btn:active { transform: scale(0.92); }
.pp-mode:active:not(:disabled) { transform: scale(0.95); }

@keyframes pp-pulse {
  0% { transform: scale(1); }
  30% { transform: scale(1.35); color: #fff; text-shadow: 0 0 12px var(--green); }
  100% { transform: scale(1); }
}
.pp-pulse {
  display: inline-block;
  animation: pp-pulse 0.5s ease-out;
}

.pp-modes { display: flex; gap: 4px; margin-top: 8px; }
.pp-mode {
  flex: 1;
  padding: 4px 0;
  border-radius: 6px;
  border: 1px solid var(--panel-edge);
  background: transparent;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 700;
  cursor: pointer;
}
.pp-mode.active { background: var(--gold); border-color: var(--gold); color: #201a05; }
.pp-mode:disabled { opacity: 0.4; cursor: not-allowed; }

#toast {
  position: absolute;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: 999px;
  background: rgba(58, 21, 24, 0.95);
  border: 1px solid #6b2226;
  color: var(--red);
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
#toast.show { opacity: 1; }
