:root { --bg: #0d1117; --panel: rgba(22, 27, 34, .88); --text: #e6edf3; --muted: #8b949e; --accent: #f2cc60;
  --safe-top: env(safe-area-inset-top, 0px); --hud-h: calc(66px + var(--safe-top)); }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; touch-action: none; user-select: none; }
canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }
[hidden] { display: none !important; }

#hud { position: fixed; top: 0; left: 0; right: 0; padding: calc(8px + var(--safe-top)) max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left)); background: linear-gradient(var(--panel), transparent); pointer-events: none; }
#bars { display: flex; gap: 6px; }
.fbar { flex: 1; min-width: 0; }
.fbar .label { display: flex; justify-content: space-between; gap: 4px; font-size: 12px; font-weight: 600; }
.fbar .label span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fbar .track { height: 6px; background: #21262d; border-radius: 3px; overflow: hidden; margin-top: 2px; }
.fbar .fill { height: 100%; width: 0; transition: width .4s; }
.fbar.me .label { text-decoration: underline; }
#metaRow { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
#meta { flex: 1; min-width: 0; font-size: 12px; color: var(--muted); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hudBtn { pointer-events: auto; flex: none; width: 32px; height: 32px; padding: 0; border-radius: 50%; background: var(--panel); border: 1px solid #30363d; color: var(--text); font-size: 15px; line-height: 1; }
.hudBtn.on { border-color: var(--accent); }

#alert, #announce { position: fixed; left: 50%; transform: translateX(-50%); max-width: min(92vw, 520px); padding: 7px 14px; border-radius: 8px; font-weight: 600; text-align: center; pointer-events: none; }
#alert { top: calc(var(--hud-h) + 4px); background: rgba(218, 54, 51, .92); color: #fff; }
#announce { top: calc(var(--hud-h) + 48px); background: var(--accent); color: #0d1117; }

#board { position: fixed; top: calc(var(--hud-h) + 4px); right: 10px; width: 170px; padding: 8px 10px; background: var(--panel); border-radius: 8px; font-size: 12px; }
#board h3 { margin: 0 0 4px; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
#board ol { margin: 0; padding-left: 18px; }
#board li.empty { color: var(--muted); list-style: none; margin-left: -18px; }
#board li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#energyBox { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--panel) 35%); text-align: center; pointer-events: none; }
#who { font-weight: 600; margin-bottom: 4px; }
#energyBar { position: relative; max-width: 420px; height: 20px; margin: 0 auto; background: #21262d; border-radius: 10px; overflow: hidden; }
#energyFill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
#energyText { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #0d1117; mix-blend-mode: normal; text-shadow: 0 0 3px rgba(255,255,255,.4); }

#toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: 92vw; text-align: center; padding: 8px 14px; background: #da3633; color: #fff; border-radius: 6px; font-weight: 600; pointer-events: none; }

#join, #seasonOver { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(13, 17, 23, .92); z-index: 10; }
#join[hidden], #seasonOver[hidden] { display: none; }
#joinForm, .card { width: min(92vw, 360px); padding: 28px; background: #161b22; border: 1px solid #30363d; border-radius: 12px; text-align: center; user-select: auto; }
#joinForm h1 { margin: 0 0 8px; letter-spacing: .25em; font-size: 28px; }
#joinForm p { color: var(--muted); margin: 0 0 18px; }
input, button { font: inherit; width: 100%; padding: 12px; border-radius: 8px; border: 1px solid #30363d; }
input { font-size: 16px; background: #0d1117; color: var(--text); margin-bottom: 10px; text-align: center; }
button { background: var(--accent); color: #0d1117; font-weight: 700; border: 0; cursor: pointer; }
#joinError { margin-top: 10px; color: #ff7b72; min-height: 1.4em; }
.card h2 { margin: 0 0 8px; }

/* accounts */
#signInToggle { display: inline-block; margin-top: 12px; color: var(--muted); font-size: 13px; }
#joinError.ok, #accountBox .msg.ok { color: #7ee787; }
#saveAccount { width: auto; margin-left: 8px; padding: 2px 10px; font-size: 12px; border-radius: 10px; pointer-events: auto; }
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(13, 17, 23, .92); z-index: 11; }
#accountBox p { color: var(--muted); }
#accountBox .secondary { margin-top: 8px; background: transparent; color: var(--muted); border: 1px solid #30363d; }
#accountBox .msg { margin-top: 10px; color: #ff7b72; min-height: 1.4em; }

/* First-play tutorial: a card above the energy bar, leaving the map around your land free to tap. */
#tut { position: fixed; z-index: 5; bottom: calc(66px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: min(calc(100vw - 20px), 400px); padding: 14px 16px 12px; background: #161b22; border: 1px solid #30363d; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.5); }
#tut h2 { margin: 2px 0 6px; font-size: 17px; }
#tut p { margin: 0 0 10px; color: #c9d1d9; }
.tut-count { font-size: 11px; color: var(--muted); letter-spacing: .05em; }
.tut-wait { margin: -4px 0 10px; font-size: 12px; color: var(--accent); }
.tut-buttons { display: flex; gap: 8px; justify-content: flex-end; }
.tut-buttons button { width: auto; padding: 9px 16px; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid #30363d; }
.tut-focus { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; animation: tutPulse 1.2s ease-in-out infinite alternate; }
#tut.top { bottom: auto; top: calc(var(--hud-h) + 6px); }
@keyframes tutPulse { from { outline-color: rgba(242, 204, 96, .35); } to { outline-color: var(--accent); } }

/* Phones */
@media (max-width: 600px) {
  .fbar .label { font-size: 11px; }
  #board { right: 8px; width: min(200px, 60vw); }
}
/* Short screens (phones held sideways): keep the energy panel compact. */
@media (max-height: 480px) {
  #energyBox { padding-top: 4px; }
  #who { display: none; }
  #tut, #tut.top { top: calc(var(--hud-h) + 6px); bottom: auto; left: auto; right: max(10px, env(safe-area-inset-right)); transform: none; width: min(300px, 40vw); padding: 10px 12px; }
  #tut p { font-size: 13px; margin-bottom: 8px; }
}
