:root {
  --bg: #06140e;
  --panel: rgba(10, 22, 17, 0.88);
  --panel-line: rgba(255, 255, 255, 0.09);
  --text: #f3efe4;
  --muted: #9fb0a6;
  --gold: #f2c14e;
  --gold-deep: #c8961f;
  --red: #e0524f;
  --fold: #5a2a2a;
  --call: #1f6f54;
  --input: rgba(255, 255, 255, 0.06);
  --radius: 14px;
  --font: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 40%, #0f2a1f 0%, #071a12 55%, #030b07 100%);
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; touch-action: none; }

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 16px;
  overflow-y: auto;
  z-index: 5;
}
.panel {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.brand { text-align: center; margin-bottom: 18px; }
.suits { font-size: 20px; letter-spacing: 6px; color: #d9d4c7; }
.suits .red { color: var(--red); }
h1 { margin: 4px 0 2px; font-size: 40px; font-weight: 800; letter-spacing: -0.02em; color: var(--gold); }
.sub { margin: 0; color: var(--muted); font-size: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
input[type='number'], input:not([type]), .field input {
  width: 100%;
  background: var(--input);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 16px;
  outline: none;
}
.field input:focus { border-color: var(--gold); }
.suffix { position: relative; }
.suffix em { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-size: 13px; pointer-events: none; }
.suffix input { padding-right: 56px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid .field:last-child:nth-child(odd) { grid-column: 1 / -1; }
.code-input { text-transform: uppercase; letter-spacing: 0.4em; text-align: center; font-size: 24px !important; font-weight: 700; }

.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--input); border-radius: 12px; padding: 4px; margin: 6px 0 16px; }
.tab { border: 0; background: none; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab.active { background: rgba(255, 255, 255, 0.1); color: var(--text); }

.schedule { margin: 2px 0 16px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.schedule b { color: var(--text); font-weight: 600; }

.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 700; font-size: 15px;
  cursor: pointer; transition: transform 0.06s ease, filter 0.15s ease, opacity 0.15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.wide { width: 100%; }
.btn.primary { background: linear-gradient(180deg, var(--gold), var(--gold-deep)); color: #1d1405; }
.btn.ghost { background: var(--input); border: 1px solid var(--panel-line); }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn:hover:not(:disabled) { filter: brightness(1.08); }

.err { color: #ff8b85; font-size: 14px; min-height: 1em; margin: 12px 0 0; text-align: center; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ---------- lobby ---------- */
#lobby .panel { text-align: center; }
.kicker { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.code {
  display: block; margin: 4px auto 8px; background: none; border: 0; cursor: pointer;
  font-size: 46px; font-weight: 800; letter-spacing: 0.18em; color: var(--gold); padding: 0 0 0 0.18em;
}
.settings { list-style: none; padding: 0; margin: 18px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; text-align: left; }
.settings li { background: var(--input); border-radius: 10px; padding: 8px 10px; font-size: 12px; color: var(--muted); }
.settings li b { display: block; color: var(--text); font-size: 15px; margin-top: 2px; }
.players-head { display: flex; justify-content: space-between; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 8px; }
.players { list-style: none; padding: 0; margin: 0 0 18px; display: grid; gap: 6px; text-align: left; }
.players li { display: flex; align-items: center; gap: 10px; background: var(--input); padding: 8px 10px; border-radius: 10px; }
.players .av { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 13px; color: #10120f; flex: none; }
.players .nm { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .tag { font-size: 11px; font-weight: 700; color: var(--gold); text-transform: uppercase; letter-spacing: 0.06em; }
.players .tag.off { color: var(--muted); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 4; }
#hud > * { pointer-events: auto; }
#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
}
.chip {
  background: rgba(0, 0, 0, 0.45); border: 1px solid var(--panel-line); border-radius: 999px;
  padding: 7px 14px; font-weight: 700; font-size: 13px; letter-spacing: 0.06em; cursor: pointer;
}
.blinds { text-align: center; line-height: 1.2; background: rgba(0, 0, 0, 0.35); border-radius: 12px; padding: 5px 14px; }
.blinds strong { font-size: 15px; color: var(--gold); }
.blinds span { display: block; font-size: 11px; color: var(--muted); }

#log {
  position: absolute; top: 56px; right: 16px; width: min(320px, calc(100vw - 32px)); max-height: 50vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: var(--radius); padding: 10px 14px;
  font-size: 13px; line-height: 1.5; color: #d4dcd6; z-index: 6;
}
#log ol { list-style: none; margin: 0; padding: 0; }
#log li.sep { color: var(--gold); margin-top: 6px; font-weight: 600; }

#actionbar {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 8px 16px max(12px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
#status { font-size: 14px; color: var(--muted); min-height: 1.2em; text-align: center; text-shadow: 0 1px 4px #000; }
#status b { color: var(--text); }
#status .hand { color: var(--gold); font-weight: 700; }
#controls {
  width: 100%; max-width: 560px;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 18px; padding: 10px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  animation: rise 0.18s ease-out;
}
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }
.buttons { display: grid; grid-template-columns: 1fr 1.2fr 1.3fr; gap: 8px; }
.buttons .btn { padding: 13px 8px; font-size: 15px; }
.btn.fold { background: var(--fold); color: #ffd9d6; }
.btn.call { background: var(--call); color: #e2fff2; }
.btn.raise { background: linear-gradient(180deg, var(--gold), var(--gold-deep)); color: #1d1405; }
kbd { font: 600 10px var(--font); opacity: 0.55; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; }
@media (hover: none) { kbd { display: none; } }

#raise-box { display: flex; flex-direction: column; gap: 8px; }
.presets { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.presets button {
  background: var(--input); border: 1px solid var(--panel-line); border-radius: 8px; padding: 6px 2px;
  font-size: 12px; font-weight: 600; cursor: pointer; color: #d9e3dd;
}
.presets button:hover { border-color: var(--gold); }
.raise-row { display: flex; gap: 10px; align-items: center; }
.raise-row input[type='range'] { flex: 1; accent-color: var(--gold); height: 28px; }
.raise-row input[type='number'] { width: 110px; padding: 8px 10px; text-align: right; font-weight: 700; }

/* ---------- overlays ---------- */
#overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, 0.55); z-index: 20; padding: 16px; }
#overlay .panel { text-align: center; }
#overlay h2 { margin: 6px 0; font-size: 28px; color: var(--gold); }
#overlay .standings { list-style: none; padding: 0; margin: 16px 0; text-align: left; display: grid; gap: 6px; }
#overlay .standings li { display: flex; justify-content: space-between; background: var(--input); padding: 8px 12px; border-radius: 10px; }
#overlay .actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }

#toast {
  position: fixed; left: 50%; top: 64px; transform: translateX(-50%);
  background: #2b1515; border: 1px solid #6d2a2a; color: #ffd0cc; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; z-index: 30; max-width: calc(100vw - 32px); text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
#toast.info { background: #13261e; border-color: #2c5a45; color: #d8f5e7; }
#conn {
  position: fixed; left: 50%; bottom: 50%; transform: translate(-50%, 50%);
  background: rgba(0, 0, 0, 0.8); padding: 12px 20px; border-radius: 12px; font-weight: 600; z-index: 25;
}

@media (max-width: 420px) {
  .panel { padding: 18px; }
  h1 { font-size: 34px; }
  .buttons .btn { font-size: 13px; padding: 13px 4px; white-space: nowrap; }
  .code { font-size: 38px; }
}
