:root {
  color-scheme: dark;
  --panel: rgba(15, 18, 14, 0.94);
  --panel-border: rgba(214, 196, 150, 0.24);
  --text: #efe9d8;
  --muted: #b7ad96;
  --accent: #d99a43;
  --good: #69d17c;
  --bad: #ef6461;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: #090c08;
  color: var(--text);
  overscroll-behavior: none;
}

button, input { font: inherit; }

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 45%, #20251b 0, #0b0e09 68%);
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  touch-action: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.42);
  /* No backdrop-filter here: blurring a fullscreen animated Canvas is one
     of the most expensive effects on Android GPUs. */
}

.hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  width: 252px;
  padding: 12px 14px;
  pointer-events: none;
  z-index: 5;
}

.hud-title {
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.hud-title span { color: var(--accent); }

.hud-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.hud-toggle {
  display: none;
  width: 30px;
  height: 28px;
  flex: 0 0 30px;
  place-items: center;
  border: 1px solid rgba(255, 213, 140, 0.28);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.06);
  color: #ffd58c;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

.hud-line {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.dot {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border-radius: 999px;
  background: var(--bad);
  box-shadow: 0 0 10px currentColor;
}

.dot.online { background: var(--good); color: var(--good); }
.dot.offline { background: var(--bad); color: var(--bad); }
.dot.connecting { background: #ffc857; color: #ffc857; }

.hud-grid {
  display: grid;
  grid-template-columns: 68px 1fr;
  gap: 4px 8px;
  margin-top: 10px;
  font-size: 12.5px;
}

.hud-grid span { color: var(--muted); }
.hud-grid strong { font-weight: 650; text-align: right; }

.role-text {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  color: #d8c58f;
  font-size: 12.5px;
  line-height: 1.35;
}

.top-actions {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  z-index: 6;
}

.small-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 42px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--panel-border);
  border-radius: 11px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.small-btn.active {
  border-color: var(--accent);
  color: #ffd58c;
}

.help {
  position: absolute;
  top: 62px;
  right: max(12px, env(safe-area-inset-right));
  width: min(330px, calc(100vw - 24px));
  padding: 16px;
  z-index: 7;
  line-height: 1.45;
}

.help h2 { margin: 0 0 10px; font-size: 17px; }
.help p { margin: 7px 0; color: #ded6c3; font-size: 14px; }
.hidden { display: none !important; }

.inventory {
  position: absolute;
  top: 62px;
  right: max(12px, env(safe-area-inset-right));
  width: min(350px, calc(100vw - 24px));
  max-height: calc(100dvh - 76px);
  overflow-y: auto;
  padding: 15px;
  z-index: 8;
}

.inventory-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.inventory-header h2 {
  margin: 0;
  font-size: 19px;
}

.inventory-weight {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12.5px;
}

.inventory-close {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.weight-bar {
  height: 9px;
  margin: 11px 0 13px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.weight-bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #8fae67, #d99a43);
  transition: width 0.2s ease;
}

.inventory-items {
  display: grid;
  gap: 9px;
}

.inventory-item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.045);
}

.inventory-item-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  font-size: 24px;
}

.inventory-item-name {
  font-weight: 800;
  font-size: 14px;
}

.inventory-item-desc {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.35;
}

.inventory-item-count {
  text-align: right;
}

.inventory-item-count strong {
  display: block;
  color: #ffd58c;
  font-size: 18px;
}

.inventory-item-count span {
  color: var(--muted);
  font-size: 11px;
}

.inventory-note {
  margin-top: 11px;
  color: #9d957f;
  font-size: 11.5px;
  line-height: 1.4;
}

.plot {
  position: absolute;
  top: 62px;
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  width: min(390px, calc(100vw - 24px));
  max-height: calc(100dvh - 76px);
  overflow: hidden;
  padding: 15px;
  z-index: 8;
}

.plot-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin: 11px 0 10px;
}

.plot-tab {
  min-height: 38px;
  padding: 0 7px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.055);
  color: #ded6c3;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 800;
  touch-action: manipulation;
}

.plot-tab.active {
  border-color: rgba(255, 213, 140, 0.62);
  background: rgba(217, 154, 67, 0.24);
  color: #ffe0a1;
}

.plot-scroll {
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
  scrollbar-width: thin;
}

.plot-footer {
  flex: 0 0 auto;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.plot-close-wide {
  width: 100%;
  min-height: 46px;
  border: 1px solid rgba(255, 220, 150, 0.58);
  border-radius: 12px;
  background: linear-gradient(180deg, #dfa94f, #bd7e2e);
  color: #211605;
  cursor: pointer;
  font-size: 14px;
  font-weight: 900;
  touch-action: manipulation;
}

.plot h2 {
  margin: 0;
  font-size: 19px;
}

.plot-storage-summary {
  margin-top: 0;
  color: #e6d7ae;
  font-size: 13px;
  font-weight: 750;
}

.plot-transfer-row {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.045);
}

.plot-counts {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.4;
}

.plot-transfer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.plot-mini-btn,
.plot-action-btn {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(255, 213, 140, 0.32);
  border-radius: 9px;
  background: rgba(217, 154, 67, 0.18);
  color: #ffe0a1;
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
}

.plot-mini-btn:disabled,
.plot-action-btn:disabled {
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: #8f8876;
  cursor: default;
}

.plot-mini-btn.secondary {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: #ded6c3;
}

.plot-members {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.plot-members h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.plot-member-row,
.plot-nearby-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 0;
  color: #ded6c3;
  font-size: 12.5px;
}

.plot-member-row .role,
.plot-nearby-row .role {
  color: var(--muted);
  font-size: 11px;
}

.plot-member-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}

.plot-buildings {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.plot-buildings h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.plot-building-row {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  margin-top: 8px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.045);
}

.plot-building-desc,
.plot-building-cost {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.4;
}

.plot-building-cost.missing {
  color: #e8a09a;
}

.condition-bar {
  height: 7px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.condition-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #9cbf69;
}

.condition-bar span.worn {
  background: #d9a44b;
}

.condition-bar span.critical {
  background: #d96357;
}

.plot-building-actions {
  margin-top: 8px;
}

.plot-actions {
  margin-top: 12px;
}

.plot-action-btn.danger {
  width: 100%;
  border-color: rgba(239, 100, 97, 0.42);
  background: rgba(160, 45, 42, 0.2);
  color: #ffb1ad;
}

.plot-empty {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
}

.interact-panel {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  bottom: 178px;
  display: flex;
  align-items: stretch;
  gap: 10px;
  max-width: min(410px, calc(100vw - 170px));
  z-index: 6;
  pointer-events: none;
}

.interact-copy {
  position: relative;
  min-width: 190px;
  max-width: 290px;
  padding: 11px 36px 11px 12px;
  border: 1px solid rgba(255, 213, 140, 0.34);
  border-radius: 14px;
  background: rgba(13, 16, 12, 0.94);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.interact-close {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: #efe9d8;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  pointer-events: auto;
  touch-action: manipulation;
}

.interact-panel.copy-hidden .interact-copy {
  display: none;
}

.interact-copy strong {
  display: block;
  font-size: 14px;
}

.interact-copy > span {
  display: block;
  margin-top: 3px;
  color: #cfc6ae;
  font-size: 12px;
  line-height: 1.35;
}

.gather-progress {
  height: 8px;
  margin-top: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.gather-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #d99a43, #ffd58c);
}

.action-btn {
  width: 76px;
  height: 76px;
  flex: 0 0 76px;
  align-self: center;
  border: 2px solid rgba(255, 220, 150, 0.72);
  border-radius: 999px;
  background: radial-gradient(circle at 35% 28%, #f0bd68, #b87927 68%, #865818);
  color: #251607;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.38), inset 0 2px 5px rgba(255, 255, 255, 0.3);
  font-size: 31px;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

.action-btn:active { transform: scale(0.96); }
.action-btn:disabled {
  /* Avoid CSS filters over the animated Canvas on Android GPUs. */
  background: #77705e;
  opacity: 0.58;
  cursor: default;
}
.action-btn.gathering {
  background:
    radial-gradient(circle, #d8d2bd 0 57%, rgba(216, 210, 189, 0) 58%),
    conic-gradient(#ffd58c var(--gather-progress, 0%), #655e4c 0);
  color: #181711;
  font-size: 25px;
}

.chat {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  width: min(430px, calc(100vw - 176px));
  padding: 10px;
  z-index: 5;
}

.chat-header {
  margin-bottom: 6px;
}

.chat-toggle {
  display: flex;
  width: 100%;
  min-height: 28px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 0;
  border-radius: 8px;
  padding: 3px 6px;
  background: transparent;
  color: #e8dcba;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 850;
  touch-action: manipulation;
}

.chat-unread {
  min-width: 22px;
  margin-left: auto;
  border-radius: 999px;
  padding: 2px 6px;
  background: #d99a43;
  color: #211605;
  font-size: 11px;
  text-align: center;
}

.chat.chat-collapsed {
  width: 196px;
  padding: 5px;
}

.chat.chat-collapsed .chat-header {
  margin-bottom: 0;
}

.chat.chat-collapsed .chat-log,
.chat.chat-collapsed .chat-form {
  display: none;
}

.event-toast {
  position: absolute;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  width: min(360px, 40vw);
  padding: 9px 12px;
  border: 1px solid rgba(255, 213, 140, 0.38);
  border-radius: 12px;
  background: rgba(13, 16, 12, 0.94);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.34);
  color: #f3ead2;
  font-size: 12.5px;
  line-height: 1.35;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 9;
}

.event-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.chat-log {
  height: 124px;
  overflow-y: auto;
  padding: 2px 3px 8px;
  font-size: 13.5px;
  line-height: 1.38;
  scrollbar-width: thin;
}

.chat-entry { margin: 0 0 6px; overflow-wrap: anywhere; }
.chat-entry .who { color: #ffd58c; font-weight: 750; }
.chat-entry.system { color: #a9b39c; font-style: italic; }
.chat-entry.action { color: #d7c7ff; }
.chat-entry .role { color: #9d927b; font-size: 11.5px; }

.chat-form {
  display: flex;
  gap: 8px;
}

.chat-form input {
  min-width: 0;
  flex: 1;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  outline: none;
}

.chat-form input:focus { border-color: var(--accent); }

.chat-form button {
  width: 46px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #211605;
  cursor: pointer;
  font-size: 18px;
}

.joystick {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(20px, env(safe-area-inset-bottom));
  width: 124px;
  height: 124px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(10, 12, 9, 0.36);
  box-shadow: inset 0 0 0 10px rgba(255, 255, 255, 0.025), 0 10px 24px rgba(0,0,0,.28);
  touch-action: none;
  z-index: 5;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  border: 1px solid rgba(255, 215, 150, 0.36);
  border-radius: 999px;
  background: rgba(74, 68, 49, 0.76);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.rotate-overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: rgba(5, 7, 5, 0.96);
  z-index: 80;
}

.rotate-card {
  width: min(410px, 100%);
  padding: 28px 24px;
  border: 1px solid rgba(225, 194, 132, 0.32);
  border-radius: 20px;
  background: #12150f;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.62);
  text-align: center;
}

.rotate-phone {
  width: 58px;
  height: 96px;
  margin: 8px auto 22px;
  border: 2px solid #d8c58f;
  border-radius: 12px;
  transform: rotate(90deg);
  position: relative;
}

.rotate-phone span {
  position: absolute;
  left: 50%;
  bottom: 7px;
  width: 18px;
  height: 3px;
  border-radius: 999px;
  background: #d8c58f;
  transform: translateX(-50%);
}

.rotate-card h2 {
  margin: 0 0 10px;
  font-size: 25px;
}

.rotate-card p {
  color: #cfc6ae;
  line-height: 1.5;
}

.rotate-btn {
  width: 100%;
  min-height: 50px;
  margin-top: 14px;
  border: 0;
  border-radius: 13px;
  background: linear-gradient(180deg, #e0aa54, #bd7e2e);
  color: #201304;
  font-weight: 900;
  cursor: pointer;
}

.rotate-note {
  margin-top: 12px;
  color: #9d957f;
  font-size: 12.5px;
  line-height: 1.45;
}

.join-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(rgba(5, 7, 5, 0.62), rgba(5, 7, 5, 0.82)),
    radial-gradient(circle at center, transparent, rgba(0,0,0,.58));
  z-index: 20;
}

.join-overlay.hidden { display: none; }

.join-card {
  width: min(430px, 100%);
  max-height: calc(100dvh - 36px);
  overflow-y: auto;
  padding: 28px;
  border: 1px solid rgba(225, 194, 132, 0.3);
  border-radius: 20px;
  background: rgba(17, 19, 14, 0.94);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.62);
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.join-card h1 {
  margin: 10px 0 2px;
  font-size: clamp(34px, 9vw, 52px);
  line-height: 0.95;
  letter-spacing: 0.03em;
}

.subtitle {
  color: #d8c58f;
  font-size: 18px;
  font-weight: 700;
}

.join-text {
  color: #cfc6ae;
  line-height: 1.5;
  margin: 18px 0;
}

.join-card label {
  display: block;
  margin: 14px 0 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.join-card input {
  width: 100%;
  height: 48px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 12px;
  padding: 0 14px;
  background: rgba(255,255,255,.07);
  color: var(--text);
  outline: none;
}

.join-card input:focus { border-color: var(--accent); }

.owner-details {
  margin-top: 13px;
  color: var(--muted);
  font-size: 13px;
}

.owner-details input { margin-top: 8px; }

.join-btn {
  width: 100%;
  height: 52px;
  margin-top: 20px;
  border: 0;
  border-radius: 13px;
  background: linear-gradient(180deg, #e0aa54, #bd7e2e);
  color: #201304;
  font-size: 17px;
  font-weight: 900;
  cursor: pointer;
}

.join-btn:disabled { opacity: .55; cursor: wait; }

.join-error {
  min-height: 20px;
  margin-top: 12px;
  color: #ff918d;
  font-size: 14px;
  line-height: 1.4;
}

.asset-status, .join-note {
  margin-top: 10px;
  color: #9d957f;
  font-size: 12.5px;
  line-height: 1.45;
}

@media (max-width: 720px) {
  .hud {
    width: 214px;
    padding: 10px 12px;
  }

  .hud-grid { grid-template-columns: 58px 1fr; font-size: 11.5px; }
  .role-text { font-size: 11.5px; }

  .chat {
    left: 158px;
    width: auto;
    padding: 8px;
  }

  .chat-log { height: 92px; font-size: 12.5px; }
  .chat-form input { height: 40px; }

  .joystick {
    width: 112px;
    height: 112px;
    bottom: 22px;
  }
}

@media (max-width: 520px) {
  .hud { width: 190px; }
  .hud-title { font-size: 13px; }
  .chat {
    left: 142px;
    right: 8px;
    bottom: 10px;
  }
  .chat-log { height: 76px; }
  .joystick { left: 12px; width: 104px; height: 104px; }
  .joystick-knob { width: 48px; height: 48px; }
  .top-actions { top: auto; bottom: 176px; }
  .help { top: auto; bottom: 224px; }
}

@media (pointer: fine) and (min-width: 900px) {
  .joystick { opacity: 0.58; }
}

/* The game itself is landscape-only. In portrait show the blocker above the
   join form and every control until Android/Chrome reports landscape. */
@media (orientation: portrait) {
  .rotate-overlay { display: grid; }
}

/* Phones in landscape usually provide only 360–480 CSS px of height. Keep the
   HUD/chat compact so most of that height remains playable map. */
@media (orientation: landscape) and (max-height: 560px) {
  .hud {
    width: 222px;
    padding: 8px 10px;
  }

  .hud-title { font-size: 13px; }
  .hud-line { margin-top: 4px; font-size: 11.5px; }
  .hud-grid {
    grid-template-columns: 56px 1fr;
    gap: 2px 7px;
    margin-top: 6px;
    font-size: 11px;
  }

  .role-text {
    margin-top: 6px;
    padding-top: 6px;
    font-size: 11px;
    line-height: 1.25;
  }

  .top-actions { gap: 6px; }
  .small-btn {
    min-width: 38px;
    height: 34px;
    padding: 0 9px;
    font-size: 12.5px;
  }

  .help {
    top: 52px;
    max-height: calc(100dvh - 64px);
    overflow-y: auto;
    padding: 12px;
  }

  .inventory {
    top: 52px;
    width: min(330px, 44vw);
    max-height: calc(100dvh - 64px);
    padding: 12px;
  }

  .inventory-header h2 { font-size: 17px; }
  .inventory-item { padding: 8px; }
  .inventory-item-icon { width: 38px; height: 38px; }
  .inventory-note { display: none; }

  .plot {
    top: 52px;
    width: min(365px, 46vw);
    max-height: calc(100dvh - 64px);
    padding: 12px;
  }

  .plot h2 { font-size: 17px; }
  .plot-transfer-row { padding: 8px; }
  .plot-members { margin-top: 9px; }

  .interact-panel {
    right: max(10px, env(safe-area-inset-right));
    bottom: 126px;
    max-width: min(390px, calc(100vw - 150px));
  }

  .interact-copy {
    min-width: 168px;
    padding: 9px 10px;
  }

  .action-btn {
    width: 66px;
    height: 66px;
    flex-basis: 66px;
    font-size: 27px;
  }

  .chat {
    width: min(365px, 43vw);
    padding: 7px;
  }

  .chat-log {
    height: 62px;
    font-size: 12px;
    line-height: 1.3;
  }

  .chat-form input { height: 36px; }
  .chat-form button { width: 42px; }

  .joystick {
    width: 106px;
    height: 106px;
    left: max(14px, env(safe-area-inset-left));
    bottom: max(14px, env(safe-area-inset-bottom));
  }

  .joystick-knob { width: 50px; height: 50px; }

  .join-overlay { padding: 10px; }
  .join-card {
    width: min(560px, calc(100vw - 20px));
    max-height: calc(100dvh - 20px);
    padding: 18px 22px;
    border-radius: 17px;
  }

  .join-card h1 {
    margin-top: 6px;
    font-size: 38px;
  }

  .subtitle { font-size: 16px; }
  .join-text { margin: 9px 0; line-height: 1.38; }
  .join-card label { margin-top: 9px; }
  .join-card input { height: 42px; }
  .join-btn { height: 46px; margin-top: 14px; }
}

/* Stage 2C-2 owner feedback: on a short Android landscape screen the map is
   the interface. Secondary HUD rows, chat history and long prompts stay one
   tap away instead of permanently covering the playable area. */
@media (orientation: landscape) and (max-height: 560px) {
  .hud {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    width: 190px;
    padding: 7px 9px;
    border-radius: 11px;
  }

  .hud-title {
    font-size: 11.5px;
    letter-spacing: 0.035em;
    line-height: 1.2;
  }

  .hud-toggle { display: grid; }

  .hud-line {
    margin-top: 3px;
    font-size: 10.5px;
  }

  .hud-grid {
    grid-template-columns: 50px 1fr;
    gap: 1px 6px;
    margin-top: 5px;
    font-size: 10.5px;
  }

  .hud:not(.expanded) .hud-detail {
    display: none;
  }

  .hud.expanded .role-text {
    display: block;
  }

  .top-actions {
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    gap: 5px;
  }

  .small-btn {
    width: 37px;
    min-width: 37px;
    height: 37px;
    padding: 0;
    border-radius: 10px;
    font-size: 17px;
  }

  .small-btn .btn-label {
    display: none;
  }

  .help,
  .inventory {
    top: 50px;
    right: max(8px, env(safe-area-inset-right));
    max-height: calc(100dvh - 58px);
  }

  .plot {
    top: 50px;
    right: max(8px, env(safe-area-inset-right));
    width: min(350px, 47vw);
    height: calc(100dvh - 58px);
    max-height: none;
    padding: 10px;
  }

  .plot h2 { font-size: 16px; }

  .plot .inventory-weight {
    margin-top: 2px;
    font-size: 11px;
  }

  .plot .inventory-close {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  .plot-tabs {
    margin: 8px 0;
  }

  .plot-tab {
    min-height: 35px;
    font-size: 11.5px;
  }

  .plot-transfer-row,
  .plot-building-row {
    grid-template-columns: 34px 1fr;
    gap: 8px;
    padding: 7px;
  }

  .plot .inventory-item-icon {
    width: 34px;
    height: 34px;
    font-size: 19px;
  }

  .plot .inventory-item-name { font-size: 13px; }

  .plot-counts,
  .plot-building-desc,
  .plot-building-cost {
    font-size: 10.5px;
    line-height: 1.3;
  }

  .plot-mini-btn,
  .plot-action-btn {
    min-height: 34px;
    font-size: 11.5px;
  }

  .plot-building-actions .plot-mini-btn {
    width: 100%;
    min-height: 38px;
  }

  .plot-footer {
    margin-top: 8px;
    padding-top: 8px;
  }

  .plot-close-wide { min-height: 44px; }

  body.plot-open .chat,
  body.plot-open .interact-panel {
    display: none;
  }

  .interact-panel {
    right: max(8px, env(safe-area-inset-right));
    bottom: 58px;
    gap: 7px;
    max-width: calc(100vw - 140px);
  }

  #chatPanel:not(.chat-collapsed) ~ .interact-panel {
    bottom: 150px;
  }

  .interact-copy {
    width: min(198px, 39vw);
    min-width: 0;
    max-width: 198px;
    padding: 7px 32px 7px 9px;
    border-radius: 11px;
  }

  .interact-copy strong,
  .interact-copy > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .interact-copy strong { font-size: 12.5px; }

  .interact-copy > span {
    margin-top: 2px;
    font-size: 11px;
  }

  .interact-close {
    top: 5px;
    right: 5px;
    width: 25px;
    height: 25px;
    font-size: 16px;
  }

  .gather-progress {
    height: 5px;
    margin-top: 5px;
  }

  .interact-panel.gathering .interact-copy {
    display: none;
  }

  .action-btn {
    width: 57px;
    height: 57px;
    flex-basis: 57px;
    font-size: 24px;
  }

  .action-btn.gathering { font-size: 22px; }

  .chat {
    left: auto;
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    width: min(342px, 43vw);
    padding: 6px;
  }

  .chat.chat-collapsed {
    width: 178px;
    padding: 4px;
  }

  .chat-toggle {
    min-height: 30px;
    font-size: 12px;
  }

  .chat-log {
    height: 68px;
    font-size: 11.5px;
  }

  .chat-form input { height: 36px; }

  .event-toast {
    bottom: max(8px, env(safe-area-inset-bottom));
    width: min(300px, 34vw);
    padding: 7px 9px;
    font-size: 11.5px;
  }

  .joystick {
    width: 100px;
    height: 100px;
    left: max(10px, env(safe-area-inset-left));
    bottom: max(10px, env(safe-area-inset-bottom));
  }

  .joystick-knob {
    width: 47px;
    height: 47px;
  }
}
