* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: system-ui, "Segoe UI", sans-serif;
  background: #141b24; color: #e8eef2;
  overflow: hidden;
}

.screen { display: none; width: 100%; height: 100%; }
.screen.active { display: flex; }

/* ===== Panels (menu / lobby / overlays) ===== */
#menu, #lobby { align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 20%, #213047, #11161e); }
#menu { gap: 18px; }

/* Public lobby browser — pinned to the right edge, scrollable list */
#publicPanel {
  position: fixed; right: 0; top: 0; bottom: 0; z-index: 5;
  width: 320px; display: flex; flex-direction: column;
  background: #1d2733; border-left: 1px solid #2c3a4a; padding: 16px;
  box-shadow: -8px 0 30px rgba(0,0,0,0.4);
}
.pp-head { display: flex; align-items: center; justify-content: space-between; font-size: 14px; font-weight: 700; color: #9fb3c8; margin-bottom: 10px; flex-shrink: 0; }
.pp-head button { height: 28px; width: 28px; padding: 0; font-size: 14px; background: #2c3a4a; }
.lobby-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; flex: 1; min-height: 0; }
.lobby-row { background: #141b24; border: 1px solid #2c3a4a; border-radius: 9px; padding: 9px 11px; }
.lobby-row .lr-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.lobby-row .lr-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lobby-row .lr-count { color: #9fb3c8; font-size: 12px; white-space: nowrap; }
.lobby-row .lr-sub { color: #7d93a8; font-size: 12px; margin: 3px 0 7px; }
.lobby-row .lr-sub .live { color: #f0c419; }
.lobby-row button { width: 100%; height: 34px; font-size: 13px; }
.lobby-empty { color: #7d93a8; font-size: 13px; text-align: center; padding: 16px 0; }
@media (max-width: 900px) {
  #menu { flex-direction: column; }
  #publicPanel { position: static; transform: none; width: 360px; max-height: 36vh; align-self: center; }
}
.panel {
  background: #1d2733; border: 1px solid #2c3a4a; border-radius: 14px;
  padding: 28px 30px; width: 360px; box-shadow: 0 18px 50px rgba(0,0,0,0.5);
  display: flex; flex-direction: column; gap: 14px;
}
.panel h1 { margin: 0 0 4px; font-size: 27px; text-align: center; display: flex; align-items: center; justify-content: center; gap: 9px; letter-spacing: 0.3px; }
.panel h1 .logo { font-size: 24px; }
.panel h2 { margin: 0; font-size: 22px; }

.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.7px; color: #8b9bb0; font-weight: 600; }
input, select {
  background: #141b24; border: 1px solid #34465a; color: #e8eef2;
  height: 44px; padding: 0 14px; border-radius: 9px; font-size: 15px; width: 100%;
}
select { cursor: pointer; }
input:focus, select:focus { outline: none; border-color: #6fd3a6; }
/* Segmented toggle (aim style) */
.segmented { display: flex; background: #141b24; border: 1px solid #34465a; border-radius: 10px; padding: 4px; gap: 4px; }
.segmented input { display: none; }
.segmented label {
  flex: 1; text-align: center; padding: 9px 6px; border-radius: 7px; cursor: pointer;
  font-size: 14px; color: #9fb3c8; transition: all 0.15s; user-select: none;
}
.segmented label:hover { color: #e8eef2; background: rgba(255,255,255,0.04); }
.segmented input:checked + label { background: #6fd3a6; color: #10241a; font-weight: 600; box-shadow: 0 2px 8px rgba(111,211,166,0.3); }

/* Toggle switch (sound) */
.switch-row { display: flex; align-items: center; justify-content: space-between; font-size: 15px; color: #e8eef2; cursor: pointer; }
.switch { position: relative; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: #34465a; border-radius: 26px; transition: 0.2s;
}
.switch .slider::before {
  content: ''; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px;
  background: #e8eef2; border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .slider { background: #6fd3a6; }
.switch input:checked + .slider::before { transform: translateX(20px); background: #10241a; }

button {
  background: #2c3a4a; border: none; color: #e8eef2; height: 44px; padding: 0 16px;
  border-radius: 9px; font-weight: 600; font-size: 15px; cursor: pointer; transition: background 0.15s;
}
button:hover { background: #3a4c61; }
button.primary { background: #6fd3a6; color: #10241a; }
button.primary:hover { background: #84e2b8; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.menu-buttons { display: flex; flex-direction: column; gap: 10px; }
.course-row { display: flex; gap: 8px; }
.course-row select { flex: 1; }
.icon-btn { width: 44px; height: 44px; flex-shrink: 0; padding: 0; font-size: 18px; background: #243240; display: flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: #2f4256; }

.join-row { display: flex; gap: 8px; }
.join-row #joinCode { flex: 1; text-transform: uppercase; letter-spacing: 2px; }
.join-row #joinBtn { width: 92px; flex-shrink: 0; }

/* labelled divider */
.divider { display: flex; align-items: center; gap: 10px; color: #6c7c90; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; margin: 2px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: #2c3a4a; }

.secondary { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 2px; }
.ghost {
  background: transparent; color: #9fb3c8; height: auto; padding: 7px 12px; font-size: 14px;
  font-weight: 600; text-decoration: none; border-radius: 8px; display: inline-flex; align-items: center; gap: 6px;
}
.ghost:hover { color: #e8eef2; background: rgba(255,255,255,0.06); }

/* In-game settings button + range */
.hud-btn {
  position: absolute; bottom: 18px; right: 18px; width: 42px; height: 42px; padding: 0;
  background: rgba(10,15,22,0.7); border-radius: 10px; font-size: 20px; line-height: 1;
}
.hud-btn:hover { background: rgba(20,30,44,0.9); }
input[type="range"] { -webkit-appearance: none; appearance: none; height: 6px; background: #34465a; border-radius: 3px; padding: 0; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: #6fd3a6; cursor: pointer; }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border: none; border-radius: 50%; background: #6fd3a6; cursor: pointer; }
.join-row input { text-transform: uppercase; letter-spacing: 3px; text-align: center; }
.join-row button { white-space: nowrap; }
.link { color: #6fd3a6; text-decoration: none; text-align: center; font-size: 14px; margin-top: 4px; }
.link:hover { text-decoration: underline; }
.msg { min-height: 18px; font-size: 13px; color: #e8a33a; text-align: center; }
.sub { font-size: 13px; color: #9fb3c8; }

.code-box { font-size: 18px; text-align: center; }
#lobbyCode { font-size: 26px; letter-spacing: 6px; color: #6fd3a6; font-weight: 700; }
#playerList { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
#playerList li { background: #141b24; padding: 9px 12px; border-radius: 8px; display: flex; gap: 8px; align-items: center; }
.host-tag { margin-left: auto; font-size: 11px; color: #6fd3a6; }
.swatch { width: 12px; height: 12px; border-radius: 50%; }

/* ===== Playforia map browser ===== */
#browser { background: radial-gradient(circle at 50% 0%, #1a2535, #0a0e14); align-items: stretch; justify-content: center; }
.browser-panel {
  width: 100%; max-width: 1000px; height: 100%; display: flex; flex-direction: column; padding: 18px;
}
.browser-head { display: flex; align-items: center; gap: 14px; }
.browser-head h2 { margin: 0; font-size: 22px; white-space: nowrap; }
.browser-head input { flex: 1; }
.browser-head button { white-space: nowrap; }
.browser-body { flex: 1; min-height: 0; display: flex; gap: 14px; margin-top: 14px; }
.cat-tabs { display: flex; flex-direction: column; gap: 6px; width: 170px; flex-shrink: 0; overflow-y: auto; }
.cat-tab {
  background: #1d2733; border: 1px solid #2c3a4a; border-radius: 8px; padding: 10px 12px;
  cursor: pointer; font-size: 14px; text-align: left; color: #e8eef2;
}
.cat-tab:hover { background: #243240; }
.cat-tab.sel { background: #6fd3a6; color: #10241a; font-weight: 600; }
.cat-tab .cnt { float: right; opacity: 0.7; font-size: 12px; }
.track-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding-right: 6px; }
.track-row {
  display: flex; align-items: center; gap: 12px; background: #1d2733; border: 1px solid #2c3a4a;
  border-radius: 8px; padding: 9px 12px; font-size: 14px;
}
.track-row:hover { background: #243240; }
.track-row .tname { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-row .tauthor { color: #9fb3c8; font-size: 12px; white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.track-row .tpar { color: #f0c419; font-size: 12px; min-width: 44px; }
.track-row button { padding: 6px 12px; }
.track-row.set { border-color: #6fd3a6; }
.browser-empty { color: #7d93a8; padding: 20px; text-align: center; }

/* ===== Game ===== */
#game { background: radial-gradient(circle at 50% 0%, #1a2535, #0a0e14); }
#stage { position: relative; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
canvas {
  background: #46b35a;
  border-radius: 12px;
  box-shadow: 0 18px 60px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.06);
  cursor: crosshair;
  touch-action: none;               /* let pointer capture own drags */
  /* width/height set by JS (fitCanvas) to fill the stage, aspect-preserved */
}

.hud {
  position: absolute; top: 14px; padding: 8px 12px;
  background: rgba(10,15,22,0.7); border-radius: 8px; font-size: 14px;
  pointer-events: none;
}
#hudTopLeft { left: 14px; }
#shotClock { left: 50%; transform: translateX(-50%); top: 14px; font-size: 16px; font-weight: 700; display: none; }
#shotClock.show { display: block; }
#shotClock.low { color: #e8503a; }
#hudTopRight { right: 14px; color: #9fb3c8; }

/* Persistent right-side scoreboard (includes the whose-turn indicator). */
#scorePanel {
  right: 14px; top: 14px; padding: 10px 12px; min-width: 200px; max-width: 260px;
  display: flex; flex-direction: column; gap: 6px;
}
.sp-head { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: #9fb3c8; display: flex; justify-content: space-between; align-items: center; }
.sp-head kbd { font-size: 10px; }
#scoreRows { display: flex; flex-direction: column; gap: 3px; }
.sp-row {
  display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 6px;
  border-radius: 6px; opacity: 0.8;
}
.sp-row.turn { opacity: 1; background: rgba(111,211,166,0.16); box-shadow: inset 2px 0 0 #6fd3a6; }
.sp-row .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.sp-row .pturn { width: 8px; color: #6fd3a6; font-weight: 700; }
.sp-row .pname { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sp-row .pstrokes { color: #c8d4de; font-variant-numeric: tabular-nums; font-size: 12px; }
.sp-row .ptopar { color: #9fb3c8; font-variant-numeric: tabular-nums; min-width: 22px; text-align: right; }
.sp-row.sunk .pname { color: #6fd3a6; }
.sp-row.me .pname { font-weight: 700; }
kbd { background: #2c3a4a; border-radius: 4px; padding: 1px 6px; font-size: 12px; }

.banner {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  font-size: 26px; font-weight: 700; padding: 10px 22px; border-radius: 10px;
  background: rgba(10,15,22,0.6); opacity: 0; transition: opacity 0.25s;
  pointer-events: none; text-align: center;
}
.banner.show { opacity: 1; }

#powerbar {
  position: absolute; left: 18px; bottom: 18px; width: 200px; height: 16px;
  background: rgba(0,0,0,0.45); border-radius: 8px; overflow: hidden;
  border: 1px solid rgba(255,255,255,0.2);
}
#powerfill { height: 100%; width: 0%; background: linear-gradient(90deg,#6fd3a6,#f0c419,#e8503a); }

#scoreOverlay {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(8,12,18,0.82);
}
#scoreOverlay.show { display: flex; }
#scoreCard { background: #1d2733; padding: 22px; border-radius: 12px; max-width: 92%; overflow: auto; }

table { border-collapse: collapse; font-size: 14px; }
th, td { padding: 6px 10px; text-align: center; border: 1px solid #34465a; }
th { background: #141b24; color: #9fb3c8; }
td.name { text-align: left; white-space: nowrap; }
tr.me td { background: #243c2c; }

.overlay {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center; background: rgba(8,12,18,0.85);
}
.overlay.show { display: flex; }

.preview-panel { width: auto; max-width: 92vw; }
.preview-panel h2 { text-align: center; }
#previewCanvas {
  width: min(680px, 84vw); height: auto; background: #46b35a;
  border-radius: 8px; image-rendering: auto; display: block;
}
.preview-panel .menu-buttons { flex-direction: row; flex-wrap: wrap; justify-content: center; }
.preview-panel .menu-buttons button { flex: 1; min-width: 120px; }
.preview-nav { display: flex; align-items: center; justify-content: center; gap: 14px; }
.preview-nav button { padding: 6px 14px; }
.preview-nav span { font-size: 14px; color: #9fb3c8; min-width: 130px; text-align: center; }
