:root {
  --navy: #0B2A4A;
  --navy-2: #103a63;
  --blue: #0092BC;
  --red: #E4002B;
  --green: #00AF66;
  --gold: #FFD200;
  --bg: #0b1f36;
  --card: #ffffff;
  --text: #14243a;
  --muted: #6b7a90;
  --field: #4f6f14;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .25);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }
body { overflow: hidden; }
#app { height: 100%; height: 100dvh; }
.screen { display: none; height: 100%; flex-direction: column; }
.screen.active { display: flex; }
.grow { flex: 1; }
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--red); min-height: 20px; font-size: 14px; margin: 8px 0 0; }
hr { border: 0; border-top: 1px solid #e6ebf2; margin: 16px 0; }
h1, h2, h3 { margin: 0 0 12px; color: var(--navy); }
h1 { font-size: 30px; letter-spacing: 1px; }
h3 { font-size: 16px; }
a { color: var(--blue); }

/* ---- brand screens ---- */
#screen-license, #screen-name {
  background: radial-gradient(1200px 600px at 50% -10%, #17588a 0%, var(--bg) 60%);
  align-items: center; justify-content: center; padding: 24px;
}
.card { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.brand-card { width: min(420px, 100%); text-align: center; padding: 32px 28px; }
.brand-card .logo { width: 260px; max-width: 80%; margin-bottom: 10px; }
.brand-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.foot { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; color: rgba(255,255,255,.55); font-size: 12px; padding: 0 16px; }

input[type=text] {
  font: inherit; font-size: 17px; padding: 12px 14px; border-radius: 10px; border: 2px solid #d9e0ea; outline: none; width: 100%;
  transition: border-color .15s;
}
input[type=text]:focus { border-color: var(--blue); }
select { font: inherit; padding: 8px 10px; border-radius: 8px; border: 2px solid #d9e0ea; background: #fff; }
.btn {
  font: inherit; font-weight: 600; font-size: 15px; padding: 11px 16px; border-radius: 10px; border: 2px solid var(--navy);
  background: #fff; color: var(--navy); cursor: pointer; transition: transform .05s, background .15s; white-space: nowrap;
}
.btn:hover { background: #f1f5fa; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #007ea3; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--blue); }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.big { font-size: 18px; padding: 14px; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.pill { background: rgba(255,255,255,.12); color: #fff; padding: 6px 12px; border-radius: 99px; font-size: 13px; }

/* ---- top bars ---- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--navy); color: #fff; }
.logo-sm { height: 30px; background: #fff; border-radius: 8px; padding: 3px 8px; }
.logo-xs { height: 26px; background: #fff; border-radius: 6px; padding: 2px 6px; }

/* ---- lobby ---- */
#screen-lobby, #screen-room { background: linear-gradient(180deg, #0f3457, var(--bg)); }
.lobby-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; padding: 16px; overflow: auto; flex: 1; min-height: 0; align-content: start; -webkit-overflow-scrolling: touch; }
.row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.row label { min-width: 110px; font-size: 14px; color: var(--muted); }
.row.check { gap: 8px; font-size: 14px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid #e6ebf2; border-radius: 10px; margin-bottom: 8px; }
.list li .code { font-family: ui-monospace, Consolas, monospace; font-weight: 700; color: var(--navy); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #eef2f6; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.table tr.me td { background: #eaf6fb; font-weight: 700; }

/* ---- room ---- */
.room-wrap { display: grid; grid-template-columns: 1fr; gap: 14px; padding: 14px; padding-bottom: max(24px, env(safe-area-inset-bottom)); overflow: auto; flex: 1; min-height: 0; align-content: start; max-width: 900px; width: 100%; margin: 0 auto; -webkit-overflow-scrolling: touch; }
.room-code-card { text-align: center; }
.room-code { font-family: ui-monospace, Consolas, monospace; font-size: 42px; font-weight: 800; letter-spacing: 8px; color: var(--navy); margin: 6px 0 10px; }
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.slot { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 10px; border: 2px dashed #dfe6ee; min-height: 52px; font-size: 14px; }
.slot.filled { border-style: solid; border-color: #e6ebf2; background: #fbfcfe; }
.slot .num { font-size: 11px; color: var(--muted); width: 16px; }
.slot .tag { font-size: 10px; background: #eef2f6; color: var(--muted); padding: 2px 6px; border-radius: 6px; margin-left: auto; }
.slot.off { opacity: .5; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 14px; flex-shrink: 0; position: relative; box-shadow: inset 0 -3px 0 rgba(0,0,0,.2); }
.avatar .badge { position: absolute; right: -6px; top: -6px; background: var(--navy); color: #fff; font-size: 10px; width: 17px; height: 17px; border-radius: 50%; display: flex; align-items: center; justify-content: center; border: 2px solid #fff; }
.host-only { display: none; }
.is-host .host-only { display: flex; }
.is-host .guest-only { display: none; }
.is-host button.host-only { display: block; }

/* ---- game ---- */
.game { background: var(--field); color: #fff; }
.game-top { display: flex; align-items: center; gap: 8px; padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top)); background: rgba(0,0,0,.25); }
.game-title { display: flex; align-items: center; gap: 8px; }
.hole-name { font-weight: 800; font-size: 15px; line-height: 1.1; }
.hole-sub { font-size: 11px; opacity: .8; }
.icon-btn { background: rgba(255,255,255,.14); color: #fff; border: 0; width: 36px; height: 36px; border-radius: 50%; font-size: 16px; cursor: pointer; }
.wind { display: flex; align-items: center; gap: 4px; font-size: 12px; background: rgba(255,255,255,.14); padding: 4px 8px; border-radius: 99px; }
.wind-arrow { display: inline-block; font-size: 16px; }
.players-strip { display: flex; gap: 6px; overflow-x: auto; padding: 18px 10px 6px; background: rgba(0,0,0,.18); scrollbar-width: none; }
.players-strip::-webkit-scrollbar { display: none; }
.pchip { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; width: 74px; padding: 6px 4px; border-radius: 12px; position: relative; transition: background .2s; }
.pchip.active { background: rgba(255,255,255,.16); }
.pchip .avatar { width: 38px; height: 38px; }
.pchip .pname { font-size: 11px; max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 4px; }
.pchip .pshot { font-size: 11px; font-weight: 800; letter-spacing: .5px; }
.pchip .turn-bubble { position: absolute; top: -13px; left: 50%; transform: translateX(-50%); background: var(--blue); color: #fff; font-size: 9px; padding: 2px 6px; border-radius: 99px; white-space: nowrap; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
.pchip .timer { width: 56px; height: 5px; background: rgba(0,0,0,.35); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.pchip .timer i { display: block; height: 100%; background: var(--gold); width: 100%; }
.pchip.done .avatar::after { content: '✓'; position: absolute; inset: 0; background: rgba(0,175,102,.85); border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.pchip.out .avatar::after { content: '✕'; position: absolute; inset: 0; background: rgba(228,0,43,.8); border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.pchip.offline { opacity: .45; }
.canvas-wrap { flex: 1; position: relative; min-height: 0; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.banner { position: absolute; left: 50%; top: 18%; transform: translateX(-50%); background: rgba(11,42,74,.92); color: #fff; padding: 14px 24px; border-radius: 14px; text-align: center; box-shadow: var(--shadow); pointer-events: none; min-width: 240px; animation: pop .25s ease-out; }
.banner b { display: block; font-size: 20px; }
.banner small { opacity: .8; }
.turn-hint { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.45); font-size: 12px; padding: 6px 12px; border-radius: 99px; pointer-events: none; white-space: nowrap; max-width: 95%; overflow: hidden; text-overflow: ellipsis; }
@keyframes pop { from { transform: translateX(-50%) scale(.9); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
.game-bottom { background: rgba(0,0,0,.28); padding: 6px 10px; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
.chat-log { max-height: 54px; overflow-y: auto; font-size: 12px; opacity: .9; }
.chat-log div b { color: var(--gold); }
#form-chat { margin: 4px 0 0; }
#form-chat input { background: rgba(255,255,255,.12); border-color: transparent; color: #fff; padding: 8px 12px; font-size: 14px; }
#form-chat input::placeholder { color: rgba(255,255,255,.6); }
#form-chat .btn { background: var(--blue); border-color: var(--blue); color: #fff; }

.overlay { position: absolute; inset: 0; background: rgba(6,20,36,.72); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 5; }
.overlay-card { width: min(560px, 100%); max-height: 92%; overflow: auto; text-align: center; color: var(--text); }
.overlay-card .logo { width: 200px; }
.overlay-card .table { text-align: left; }
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 10px; margin: 12px 0 18px; }
.podium .p { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 96px; }
.podium .p .step { width: 100%; border-radius: 8px 8px 0 0; color: #fff; font-weight: 800; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px; }
.podium .p.r1 .step { height: 76px; background: linear-gradient(#ffe066, #e6b800); color: #5b4600; }
.podium .p.r2 .step { height: 56px; background: linear-gradient(#e0e6ee, #aab4c2); color: #2d3a4a; }
.podium .p.r3 .step { height: 42px; background: linear-gradient(#e8b98a, #b8784a); color: #4a2b10; }
.podium .p .nm { font-size: 12px; font-weight: 700; max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 20; font-size: 14px; max-width: 90%; }

@media (min-width: 900px) {
  .room-wrap { grid-template-columns: 1fr 1fr; }
  .room-wrap > .card:nth-child(2) { grid-column: 1 / -1; }
  .pchip { width: 84px; }
  .chat-log { max-height: 72px; }
}
