* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #8fd3ff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #2b2233;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

[hidden] { display: none !important; }

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* --- HUD --- */

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.panel {
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 12px;
  padding: 12px 16px;
  min-width: 220px;
  max-width: 300px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.panel h1 { font-size: 18px; }
.panel .sub { font-size: 13px; opacity: 0.7; }
.panel p { font-size: 14px; margin: 4px 0; }

#my-kingdom {
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  padding-bottom: 10px;
  margin-bottom: 8px;
}
#my-kingdom ~ #game-title { display: none; }
#my-kingdom[hidden] ~ #game-title { display: block; }

.kingdom-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
#panel-toggle { margin-left: auto; align-self: flex-start; padding: 4px 9px; }
.score { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
#player-list .score { display: inline; font-size: 12px; margin-left: 4px; }

/* Folded panel: just the kingdom and its buttons (the connection line comes back if it drops) */
.panel.collapsed .panel-details,
.panel.collapsed #my-location,
.panel.collapsed #my-kingdom-status:not(.danger),
.panel.collapsed:not(.disconnected) #connection-line { display: none; }
.panel.collapsed #my-kingdom { border-bottom: none; padding-bottom: 0; margin-bottom: 0; }
.panel.collapsed .kingdom-row { margin-bottom: 6px; }

.flag-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 28px;
  border-radius: 4px;
  font-size: 18px;
  flex: none;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.flag-badge.mini {
  width: 26px;
  height: 18px;
  font-size: 12px;
  border-radius: 3px;
}

#player-list {
  list-style: none;
  font-size: 13px;
  margin-top: 6px;
}
#player-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}
#player-list li.me { font-weight: 700; }
#player-list .device { opacity: 0.55; font-weight: 400; }

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  background: #e0a030;
}
.dot.ok { background: #2fb84f; }
.dot.bad { background: #e04040; }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  -webkit-tap-highlight-color: transparent;
}

.hud-right { margin-left: auto; display: flex; gap: 8px; }
#mute-btn {
  pointer-events: auto;
  font-size: 18px;
  width: 42px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}
#fullscreen-btn {
  pointer-events: auto;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.small-btn {
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 8px;
  background: #efe8f5;
}

#fullscreen-hint {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  max-width: calc(100% - 32px);
  text-align: center;
}

/* --- Play controls --- */

#controls-hint {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
}

#touch-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

/* Appears under the left thumb while moving */
#joystick {
  position: fixed;
  left: 18%;
  top: 72%;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 3px solid rgba(255, 255, 255, 0.5);
  opacity: 0.45;
  transition: opacity 0.15s;
}
#joystick.active { opacity: 1; }

#joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

#jump-btn {
  position: fixed;
  right: max(28px, env(safe-area-inset-right));
  bottom: max(36px, env(safe-area-inset-bottom));
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  font-size: 34px;
  font-weight: 700;
  color: #2b2233;
  pointer-events: auto;
  touch-action: none;
}
#jump-btn.pressed { transform: scale(0.92); background: rgba(255, 255, 255, 0.95); }
#attack-btn {
  position: fixed;
  right: max(124px, calc(env(safe-area-inset-right) + 96px));
  bottom: max(28px, env(safe-area-inset-bottom));
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(255, 235, 235, 0.85);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  font-size: 30px;
  pointer-events: auto;
  touch-action: none;
}
#attack-btn.pressed { transform: scale(0.9); background: rgba(255, 200, 200, 0.95); }

.button-row { display: flex; gap: 6px; flex-wrap: wrap; }
#my-location { margin: 4px 0 8px; display: flex; align-items: center; gap: 8px; }
#home-btn { padding: 2px 10px; font-size: 13px; }
#home-btn[hidden] { display: none; }

/* --- Combat --- */

#combat-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.hp-bar {
  position: absolute;
  left: 0;
  top: 0;
  width: 46px;
  height: 7px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.55);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.7);
}
.hp-bar > div { height: 100%; background: #e04040; transition: width 0.15s; }
.hp-bar.me > div { background: #2fb84f; }
.hp-bar.dummy > div { background: #f0a030; }

.floater {
  position: absolute;
  left: 0;
  top: 0;
  font: 800 18px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45), 0 0 4px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
}
.floater.dmg { color: #ffdddd; }
.floater.counter { color: #ffd23f; font-size: 22px; }
.floater.heal { color: #8dff9a; }
.floater.down { font-size: 26px; }

.res.health { background: rgba(255, 235, 235, 0.92); }
.res.health.low { background: #ffb3b3; animation: bump 0.6s infinite; }
/* Not full: tap to eat a meal (the bar itself lets clicks through, this chip doesn't) */
.res.can-eat { pointer-events: auto; cursor: pointer; border: 2px solid #f0a040; font: inherit; font-size: 15px; font-weight: 700; color: inherit; }

#encounter-card {
  position: fixed;
  top: max(70px, calc(env(safe-area-inset-top) + 54px));
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 32px));
  padding: 14px 16px;
  border: 3px solid #f2c230;
}
#encounter-title { font-size: 17px; font-weight: 800; }
#encounter-sub { font-size: 14px; margin: 2px 0 8px; }
.encounter-timer { height: 6px; border-radius: 3px; background: #eee; overflow: hidden; }
#encounter-timer-fill { height: 100%; width: 100%; background: #f2c230; }
#encounter-card .actions button { font-size: 16px; padding: 12px 18px; }
#encounter-fight { background: #e04040; }
#encounter-card.chosen .actions button { opacity: 0.45; }

#fight-status {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%) translateY(46px);
  padding: 6px 14px;
  border-radius: 999px;
  background: #e04040;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  pointer-events: none;
  animation: alert-pulse 1.2s infinite;
}

#ally-fight-card {
  position: fixed;
  top: max(70px, calc(env(safe-area-inset-top) + 54px));
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 32px));
  padding: 14px 16px;
  border: 3px solid #4aa3df;
}
#ally-fight-text { font-size: 16px; font-weight: 700; }
#my-ally { display: flex; align-items: center; gap: 6px; }
#my-ally[hidden] { display: none; }
#unally-btn { padding: 2px 8px; font-size: 12px; }

#raid-alert {
  position: fixed;
  top: max(70px, calc(env(safe-area-inset-top) + 54px));
  left: 50%;
  transform: translateX(-50%);
  width: min(440px, calc(100% - 32px));
  padding: 14px 16px;
  background: #fff1f0;
  border: 3px solid #e04040;
  animation: alert-pulse 1s ease-in-out 3;
}
#raid-alert p { font-size: 16px; font-weight: 700; }
#raid-alert #raid-defend { background: #e04040; }
@keyframes alert-pulse { 50% { box-shadow: 0 0 0 8px rgba(224, 64, 64, 0.35); } }
#my-kingdom-status.danger { color: #d32f2f; font-weight: 700; opacity: 1; }
.toast.big { font-size: 15px; max-width: min(520px, 90vw); white-space: normal; text-align: center; border-radius: 14px; animation-duration: 5s; }

#defeat-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(40, 10, 20, 0.35);
  pointer-events: none;
}
#defeat-overlay .card { text-align: center; padding: 22px 28px; width: auto; }
#defeat-overlay h2 { font-size: 26px; margin-bottom: 6px; }
#defeat-overlay p { font-size: 16px; }

/* --- Resources, gathering, building --- */

#resource-bar {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  pointer-events: none;
}
.res {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.res small { font-weight: 400; opacity: 0.55; }
/* Not enough room beside the info panel: stack under the Fullscreen button instead */
@media (max-width: 960px) {
  #resource-bar {
    left: auto;
    right: max(16px, env(safe-area-inset-right));
    top: max(68px, calc(env(safe-area-inset-top) + 52px));
    transform: none;
    flex-direction: column;
    align-items: flex-end;
  }
}
.res.full { background: #ffe1a8; }
.res.bump { animation: bump 0.35s ease-out; }
@keyframes bump { 50% { transform: scale(1.18); } }

#toasts {
  position: fixed;
  top: max(70px, calc(env(safe-area-inset-top) + 54px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.toast {
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(20, 16, 28, 0.75);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  animation: toast 2.2s ease-out forwards;
}
.toast.warn { background: rgba(190, 90, 20, 0.9); font-size: 14px; }
@keyframes toast {
  0% { opacity: 0; transform: translateY(8px); }
  10%, 75% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-10px); }
}

#action-btn {
  position: fixed;
  left: 50%;
  bottom: max(64px, calc(env(safe-area-inset-bottom) + 52px));
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  font-size: 17px;
  font-weight: 700;
  overflow: hidden;
  touch-action: manipulation;
}
#action-icon { font-size: 24px; }
#action-btn.busy { background: #f4f0f8; }
#action-progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 5px;
  width: 0;
  background: #8e6bbf;
}

.key-hint {
  font: 600 11px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.08);
  color: inherit;
}
/* No keyboard on touch devices: hide key hints */
@media (pointer: coarse) { .key-hint { display: none; } }

#build-menu {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  top: max(68px, env(safe-area-inset-top));
  width: min(360px, calc(100% - 32px));
  max-height: calc(100% - 140px);
}
.build-header { display: flex; justify-content: space-between; align-items: center; }
.build-header h2 { margin: 0; }
#build-menu .sub { font-size: 13px; opacity: 0.7; margin: 4px 0 10px; }
#build-list { display: flex; flex-direction: column; gap: 8px; }
.build-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f4f0f8;
  text-align: left;
}
.build-item:not(:disabled):hover { background: #ebe3f3; }
.build-item:disabled { opacity: 0.5; cursor: default; }
.build-icon { font-size: 28px; }
.build-text { flex: 1; display: flex; flex-direction: column; }
.build-text small { opacity: 0.7; font-size: 12px; }
.build-cost { font-weight: 700; font-size: 13px; white-space: nowrap; }
.build-cost.short { color: #d32f2f; }

#army-panel, #help-panel {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  top: max(68px, env(safe-area-inset-top));
  width: min(380px, calc(100% - 32px));
  max-height: calc(100% - 140px);
}
@media (max-width: 960px) {
  /* make room for the resource pills stacked on the right */
  #army-panel, #build-menu, #help-panel { right: auto; left: 50%; transform: translateX(-50%); }
}
#help-panel { overflow-y: auto; font-size: 14px; line-height: 1.4; }
#help-panel h3 { margin: 14px 0 4px; font-size: 16px; }
#help-panel p { margin: 4px 0; }
#help-panel ul { margin: 4px 0; padding-left: 20px; }
#help-panel li { margin: 2px 0; }
#army-panel .sub { font-size: 13px; opacity: 0.75; margin: 4px 0 10px; }
#army-list { display: flex; flex-direction: column; gap: 8px; }
#army-panel .army-jobs { margin-top: -4px; }
.army-row {
  padding: 8px 10px;
  border-radius: 12px;
  background: #f4f0f8;
  font-size: 14px;
}
.army-row.troop { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.army-name small { opacity: 0.6; }
.mode-btn { background: #fff; }
.mode-btn.following { background: #8e6bbf; color: #fff; }
.army-row.troop > :first-child { flex: 1; }
.free-btn { background: #fff; color: #a04040; }
.meal-btn { background: #fff4e0; }
.cat-hp { color: #c0392b; }
#army-feed-all[hidden] { display: none; }
.path-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}
.path-btn {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
  border-radius: 10px;
  background: #fff;
  text-align: left;
  font-size: 14px;
}
.path-btn:hover { background: #ebe3f3; }
.path-btn small { font-size: 11px; opacity: 0.7; }
#army-panel .actions { margin-top: 12px; flex-wrap: wrap; }
#army-panel .actions button { font-size: 14px; padding: 10px 12px; }

#select-box {
  position: fixed;
  border: 2px solid #4cff7a;
  background: rgba(76, 255, 122, 0.15);
  border-radius: 4px;
  pointer-events: none;
}

#command-bar {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  padding: 12px 16px;
}
.command-title { display: flex; justify-content: space-between; align-items: baseline; }
#command-count { font-size: 13px; opacity: 0.7; }
.command-help { font-size: 13px; opacity: 0.75; margin: 4px 0 2px; }
#command-bar .actions { flex-wrap: wrap; }
#command-bar .actions button { font-size: 14px; padding: 10px 12px; }
.touch-only { display: none; }
@media (pointer: coarse) {
  .touch-only { display: block; }
  .mouse-only { display: none; }
}
body.commanding #hud .panel,
body.commanding #controls-hint,
body.commanding #action-btn,
body.commanding #touch-controls { display: none !important; }

#shield-bar {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(440px, calc(100% - 140px));
  padding: 12px 16px;
}
#shield-bar .actions { justify-content: center; flex-wrap: wrap; }
#shield-bar .actions button { padding: 10px 14px; font-size: 15px; }
#shield-drop { background: #2f7fc0; }

#building-bar {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(420px, calc(100% - 140px));
  padding: 12px 16px;
}
#building-bar .actions { justify-content: center; flex-wrap: wrap; }
#building-bar .actions button { padding: 10px 14px; font-size: 15px; }
body.building-selected #action-btn, body.building-selected #controls-hint,
body.shield-bar-open #action-btn, body.shield-bar-open #controls-hint { display: none; }

#place-bar {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(460px, calc(100% - 140px));
  padding: 14px 16px;
}
#place-bar p { font-size: 14px; margin: 4px 0; }
#place-bar p.error { color: #d32f2f; }
#place-bar .actions { justify-content: center; flex-wrap: wrap; }
#place-bar .actions button { padding: 10px 14px; font-size: 15px; }
body.placing #action-btn, body.placing #controls-hint { display: none; }

#fish-bar {
  position: fixed;
  left: 50%;
  bottom: max(130px, calc(env(safe-area-inset-bottom) + 118px));
  transform: translateX(-50%);
  width: min(380px, calc(100% - 32px));
  padding: 12px 18px;
  pointer-events: none;
  overflow: visible; /* the fish pokes out at the ends of the bar */
}
.fish-bar-head { display: flex; justify-content: space-between; font-size: 15px; margin-bottom: 8px; }
#fish-bar-percent { font-weight: 800; font-variant-numeric: tabular-nums; }
.fish-bar-track {
  position: relative;
  margin: 0 6px;
  height: 30px;
  border-radius: 15px;
  /* red at the ends, gold toward the middle, green in the middle */
  background: linear-gradient(90deg, #f28b82, #f6d365 35%, #7ddc8a 50%, #f6d365 65%, #f28b82);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15);
}
.fish-bar-center {
  position: absolute;
  left: 50%;
  top: -4px;
  bottom: -4px;
  width: 4px;
  margin-left: -2px;
  border-radius: 2px;
  background: #1f7a35;
}
#fish-bar-fish {
  position: absolute;
  left: 50%;
  top: 50%;
  font-size: 24px;
  transform: translate(-50%, -50%);
  will-change: left;
}
#fish-bar-fish.flip { transform: translate(-50%, -50%) scaleX(-1); }
#fish-bar.caught .fish-bar-track { box-shadow: 0 0 0 3px #2fb84f; }
#fish-bar.missed .fish-bar-track { box-shadow: 0 0 0 3px #e04040; }
#fish-bar .sub { font-size: 12px; opacity: 0.65; margin-top: 6px; }

/* --- Land picker / world map --- */

#land-screen {
  position: fixed;
  inset: 0;
  pointer-events: none;
}
body.land-open #hud .panel { display: none; }

#spot-labels {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.spot-label {
  position: absolute;
  left: 0;
  top: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: auto;
  will-change: transform;
}
.spot-label:disabled { cursor: default; color: inherit; }
.spot-label.free { background: rgba(255, 255, 255, 0.75); border: 2px dashed #8e6bbf; }
#land-screen[data-mode="pick"] .spot-label.free { cursor: pointer; }
#land-screen[data-mode="pick"] .spot-label.free:hover { background: #fff; }
.spot-label.selected { background: #8e6bbf; color: #fff; border-style: solid; }
.spot-label.mine { outline: 3px solid #2fb84f; }
.spot-label.under-attack { background: #ffdede; outline: 3px solid #e04040; animation: alert-pulse 1s infinite; }
.spot-label.you { background: #2b2233; color: #fff; padding: 6px 10px; font-size: 13px; pointer-events: none; }
/* Other online rulers on the world map: a pill outlined in their flag color */
.spot-label.ruler-marker { padding: 4px 9px; font-size: 12px; border: 3px solid #ccc; pointer-events: none; }
.spot-label.ruler-marker[hidden] { display: none; }

/* "Who's online" on the world map (only in map mode, not when choosing land) */
#map-online {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  max-width: min(320px, calc(100% - 32px));
  padding: 10px 14px;
  pointer-events: auto;
}
#land-screen[data-mode="pick"] #map-online { display: none; }
#map-online h3 { margin: 0 0 6px; font-size: 15px; }
#map-online ul { margin: 0; padding: 0; list-style: none; font-size: 13px; }
#map-online li { margin: 3px 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#map-online small { opacity: 0.7; }
.map-online-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.land-header {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 32px));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
}
.land-header h2 { font-size: 20px; margin-bottom: 4px; }
.land-header p { font-size: 14px; opacity: 0.8; }
.land-header .error { opacity: 1; }

#land-confirm {
  position: absolute;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(420px, calc(100% - 32px));
  padding: 16px 18px;
}
#land-confirm p { font-size: 16px; font-weight: 600; }

/* --- Worlds (lobby) --- */

#worlds-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(30, 20, 50, 0.25);
}
.worlds-card { width: min(560px, 100%); max-height: 100%; }
.worlds-card h2 { font-size: 22px; margin-bottom: 4px; }
.worlds-card > .sub { font-size: 14px; opacity: 0.75; margin-bottom: 12px; }
#worlds-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.world-row {
  padding: 12px 14px;
  border-radius: 14px;
  background: #f4f0f8;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.world-row.mine { background: #ece4f7; outline: 2px solid #8e6bbf; }
.world-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.world-head strong { font-size: 17px; }
.world-head small { opacity: 0.65; white-space: nowrap; }
.world-kingdoms { display: flex; flex-wrap: wrap; gap: 6px; font-size: 13px; }
.world-kingdom { display: inline-flex; align-items: center; gap: 4px; background: #fff; padding: 3px 8px; border-radius: 999px; }
.world-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.world-actions button { padding: 8px 12px; border-radius: 10px; font-weight: 600; font-size: 14px; background: #fff; }
.world-actions .play { background: #8e6bbf; color: #fff; }
.world-actions .leave { color: #c62828; }
.world-actions button:disabled { opacity: 0.45; cursor: default; }
.world-create { display: flex; gap: 8px; }
.world-create input {
  flex: 1;
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border: 2px solid #ddd3e6;
  border-radius: 10px;
  -webkit-user-select: text;
  user-select: text;
}
.world-create button { padding: 10px 14px; border-radius: 10px; background: #2b2233; color: #fff; font-weight: 600; }
#my-world { margin-top: 2px; }
#profile-subtitle { font-size: 14px; opacity: 0.75; margin: -8px 0 12px; }
#profile-subtitle:empty { display: none; }

/* --- Create / edit ruler --- */

#profile-screen {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  /* top padding leaves room for the Fullscreen button */
  padding: max(68px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) 16px;
  pointer-events: none;
}

.card {
  pointer-events: auto;
  width: min(420px, 100%);
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.card h2 { font-size: 22px; margin-bottom: 14px; }

.field {
  display: block;
  margin-bottom: 14px;
}
.field .label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}
.field .label small { font-weight: 400; opacity: 0.6; }

.field input {
  width: 100%;
  font: inherit;
  font-size: 16px; /* 16px stops iPad Safari from zooming in */
  padding: 10px 12px;
  border: 2px solid #ddd3e6;
  border-radius: 10px;
  background: #fff;
  color: inherit;
  -webkit-user-select: text;
  user-select: text;
}
.field input:focus { outline: none; border-color: #8e6bbf; }
.field input.invalid { border-color: #e04040; }

.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choice {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 3px solid transparent;
  background: #f1ecf5;
  font-size: 15px;
  cursor: pointer;
}
.choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.choice.swatch { padding: 0; width: 44px; }
.choice.emoji { padding: 0; width: 44px; font-size: 22px; }
.choice:has(input:checked) { border-color: #2b2233; }
.choice:has(input:focus-visible) { outline: 2px solid #8e6bbf; outline-offset: 2px; }
.choice.locked {
  cursor: not-allowed;
  opacity: 0.35;
}
.choice.locked::after {
  content: '🔒';
  position: absolute;
  font-size: 16px;
}

.error {
  display: block;
  color: #d32f2f;
  font-size: 13px;
  margin-top: 4px;
  min-height: 0;
}
.error:empty { display: none; }

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}
.actions button {
  font-size: 16px;
  padding: 12px 18px;
  border-radius: 12px;
  background: #8e6bbf;
  color: #fff;
  font-weight: 600;
}
.actions button.secondary {
  background: #efe8f5;
  color: inherit;
}
.actions button:disabled { opacity: 0.5; cursor: default; }

/* Phones, narrow windows and portrait iPads: form as a bottom sheet, preview above it */
@media (max-width: 700px), (orientation: portrait) {
  #profile-screen {
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
  }
  .card { max-height: 62%; }
  body.profile-open #hud .panel { display: none; }
}
