:root {
  --bg: #07101f;
  --panel: rgba(12, 22, 39, 0.86);
  --panel-strong: rgba(10, 18, 34, 0.96);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f4f8ff;
  --muted: #9fb1cb;
  --accent: #7dd3fc;
  --warm: #fbbf24;
  --danger: #fb7185;
  --ok: #34d399;
  --wood: #b87945;
  --meat: #fb7185;
  --stone: #94a3b8;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body, #app {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 10%, rgba(125, 211, 252, 0.18), transparent 30%),
    radial-gradient(circle at 80% 0%, rgba(251, 191, 36, 0.12), transparent 28%),
    linear-gradient(180deg, #081527 0%, #08101e 50%, #050913 100%);
  color: var(--text);
}

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

.app-shell {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 360px;
  gap: 14px;
  padding: 14px;
}

.game-column {
  position: relative;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.04);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.34);
  overflow: hidden;
}

.side-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.hud {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 30;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(7, 16, 31, 0.72);
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.2);
  font-weight: 800;
  font-size: 13px;
}

.pill small {
  color: var(--muted);
  font-weight: 700;
}

.heat-panel {
  display: grid;
  gap: 5px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(7, 16, 31, 0.68);
  backdrop-filter: blur(12px);
}

.heat-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 800;
  font-size: 12px;
  color: #dbeafe;
}

.bar {
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.11);
  border: 1px solid rgba(255,255,255,0.09);
}

.bar-fill {
  height: 100%;
  width: 50%;
  border-radius: inherit;
  background: linear-gradient(90deg, #38bdf8, #fbbf24, #fb7185);
  transition: width 0.2s ease;
}

.game-map {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 47%, rgba(255, 255, 255, 0.12), transparent 22%),
    linear-gradient(135deg, rgba(255,255,255,0.16) 0 1px, transparent 1px 36px),
    linear-gradient(225deg, rgba(255,255,255,0.10) 0 1px, transparent 1px 36px),
    linear-gradient(180deg, #bde7ff 0%, #88bde3 48%, #537aa8 100%);
  touch-action: none;
}

.game-map::before {
  content: "";
  position: absolute;
  inset: -10%;
  background:
    radial-gradient(circle at 18% 22%, rgba(255,255,255,0.5) 0 2px, transparent 3px),
    radial-gradient(circle at 66% 14%, rgba(255,255,255,0.45) 0 1px, transparent 2px),
    radial-gradient(circle at 88% 42%, rgba(255,255,255,0.45) 0 2px, transparent 3px),
    radial-gradient(circle at 36% 70%, rgba(255,255,255,0.45) 0 2px, transparent 3px);
  background-size: 160px 160px, 110px 110px, 150px 150px, 190px 190px;
  animation: snowDrift 18s linear infinite;
  opacity: 0.7;
  pointer-events: none;
}

@keyframes snowDrift {
  from { transform: translate3d(0, -4%, 0); }
  to { transform: translate3d(-4%, 4%, 0); }
}

.warm-radius {
  position: absolute;
  width: var(--radius);
  height: var(--radius);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(251, 191, 36, 0.32), rgba(251, 191, 36, 0.12) 45%, transparent 72%);
  filter: blur(1px);
  pointer-events: none;
  transition: width 0.4s ease, height 0.4s ease;
}

.facility, .resource, .player, .worker, .notice-float {
  position: absolute;
  left: var(--x);
  top: var(--y);
  transform: translate(-50%, -50%);
  user-select: none;
}

.facility {
  width: var(--size);
  height: var(--size);
  display: grid;
  place-items: center;
  border-radius: 24px;
  border: 2px solid rgba(255, 255, 255, 0.32);
  background: rgba(10, 25, 47, 0.42);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.22), inset 0 0 30px rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.facility:hover { transform: translate(-50%, -50%) scale(1.04); }
.facility.locked { opacity: 0.46; filter: grayscale(0.55); }
.facility.ready { box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.18), 0 18px 44px rgba(0,0,0,0.24); }

.facility .emoji {
  font-size: calc(var(--size) * 0.44);
  filter: drop-shadow(0 7px 8px rgba(0,0,0,0.25));
}

.facility .label {
  position: absolute;
  bottom: -28px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 88px;
  text-align: center;
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(7, 16, 31, 0.72);
  border: 1px solid rgba(255,255,255,0.16);
  font-size: 11px;
  font-weight: 900;
  white-space: nowrap;
}

.facility .level-badge {
  position: absolute;
  right: -6px;
  top: -6px;
  min-width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #0f172a;
  border: 2px solid rgba(255,255,255,0.22);
  color: #fff;
  font-size: 11px;
  font-weight: 950;
}

.resource {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.32);
  border: 1px solid rgba(255,255,255,0.4);
  box-shadow: 0 12px 24px rgba(6, 20, 42, 0.18);
  font-size: 23px;
  animation: bob 1.9s ease-in-out infinite;
}

.resource::after {
  content: "+" attr(data-value);
  position: absolute;
  bottom: -14px;
  right: -10px;
  padding: 2px 5px;
  border-radius: 999px;
  background: rgba(15,23,42,0.82);
  border: 1px solid rgba(255,255,255,0.16);
  color: #fff;
  font-size: 10px;
  font-weight: 950;
}

@keyframes bob {
  0%, 100% { transform: translate(-50%, -50%) translateY(0); }
  50% { transform: translate(-50%, -50%) translateY(-5px); }
}

.player {
  width: 54px;
  height: 54px;
  z-index: 20;
  border-radius: 20px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #f8fafc, #93c5fd);
  border: 3px solid rgba(255,255,255,0.8);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.32);
  font-size: 31px;
}

.player::after {
  content: attr(data-carry);
  position: absolute;
  top: -11px;
  right: -16px;
  min-width: 30px;
  padding: 4px 7px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(255,255,255,0.22);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
}

.worker {
  width: 34px;
  height: 34px;
  z-index: 10;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #fef3c7, #fb923c);
  border: 2px solid rgba(255,255,255,0.62);
  box-shadow: 0 10px 22px rgba(0,0,0,0.2);
  font-size: 20px;
  transition: left 0.5s ease, top 0.5s ease;
}

.notice-float {
  z-index: 40;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(7, 16, 31, 0.86);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
  font-weight: 950;
  font-size: 13px;
  pointer-events: none;
  animation: floatUp 1.05s ease forwards;
}

@keyframes floatUp {
  from { opacity: 0; transform: translate(-50%, -45%); }
  15% { opacity: 1; }
  to { opacity: 0; transform: translate(-50%, -120%); }
}

.panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: 0 18px 48px rgba(0,0,0,0.24);
  overflow: hidden;
}

.panel-header {
  padding: 14px 15px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.09);
}

.title {
  margin: 0;
  font-size: 21px;
  letter-spacing: 0.02em;
  line-height: 1.1;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.panel-body {
  padding: 12px;
  overflow: auto;
}

.quest-card {
  padding: 14px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(125,211,252,0.16), rgba(251,191,36,0.12));
  border: 1px solid rgba(255,255,255,0.13);
}

.quest-card h3 {
  margin: 0 0 6px;
  font-size: 15px;
}

.quest-card p {
  margin: 0;
  color: #dbeafe;
  font-size: 13px;
  line-height: 1.5;
}

.facility-list {
  display: grid;
  gap: 10px;
  max-height: 45vh;
  overflow: auto;
  padding-right: 2px;
}

.facility-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 18px;
  background: rgba(255,255,255,0.055);
}

.facility-card.locked { opacity: 0.55; }

.card-top {
  display: flex;
  gap: 10px;
  align-items: center;
}

.card-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: rgba(255,255,255,0.1);
  font-size: 24px;
}

.card-main { flex: 1; min-width: 0; }
.card-name { font-weight: 950; font-size: 14px; }
.card-desc { margin-top: 3px; font-size: 12px; color: var(--muted); line-height: 1.35; }

.cost-row, .worker-row {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  align-items: center;
}

.cost-chip {
  padding: 5px 7px;
  border-radius: 999px;
  background: rgba(15,23,42,0.6);
  color: #e2e8f0;
  font-size: 11px;
  font-weight: 850;
}
.cost-chip.missing { color: #fecdd3; background: rgba(127, 29, 29, 0.42); }

.action-row {
  display: flex;
  gap: 8px;
}

.primary-btn, .ghost-btn, .mini-btn {
  border-radius: 13px;
  padding: 10px 12px;
  font-weight: 950;
  background: linear-gradient(180deg, #38bdf8, #2563eb);
  color: white;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.28);
}
.primary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}
.ghost-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: none;
}
.mini-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 12px;
}

.selected-detail {
  min-height: 88px;
}

.log-list {
  display: grid;
  gap: 7px;
  max-height: 120px;
  overflow: auto;
}
.log-item {
  color: #cbd5e1;
  font-size: 12px;
  line-height: 1.4;
  border-bottom: 1px dashed rgba(255,255,255,0.08);
  padding-bottom: 6px;
}

.joystick {
  position: absolute;
  left: 22px;
  bottom: 22px;
  z-index: 50;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(7, 16, 31, 0.28);
  border: 1px solid rgba(255,255,255,0.18);
  display: none;
  place-items: center;
  backdrop-filter: blur(10px);
  touch-action: none;
}

.joystick-knob {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255,255,255,0.78);
  box-shadow: 0 10px 24px rgba(0,0,0,0.26);
  transform: translate(var(--jx), var(--jy));
}

.mobile-actions {
  position: absolute;
  right: 18px;
  bottom: 22px;
  z-index: 50;
  display: none;
  gap: 8px;
  flex-direction: column;
}

.floating-button {
  width: 62px;
  height: 62px;
  border-radius: 22px;
  background: rgba(7, 16, 31, 0.56);
  border: 1px solid rgba(255,255,255,0.18);
  backdrop-filter: blur(10px);
  font-size: 24px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.24);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(3, 7, 18, 0.64);
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal {
  width: min(520px, 100%);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 28px;
  background: var(--panel-strong);
  box-shadow: 0 28px 80px rgba(0,0,0,0.46);
  overflow: hidden;
}

.modal-content {
  padding: 18px;
}

.modal h2 { margin: 0 0 8px; }
.modal p { margin: 0 0 14px; color: #cbd5e1; line-height: 1.6; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.stat-box {
  padding: 10px;
  border-radius: 16px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.09);
}
.stat-box b { display: block; font-size: 17px; }
.stat-box span { color: var(--muted); font-size: 11px; }

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 0;
    gap: 0;
  }
  .game-column {
    border-radius: 0;
    border: none;
    height: 100dvh;
  }
  .side-column {
    position: absolute;
    inset: auto 10px 10px 10px;
    z-index: 80;
    max-height: 42dvh;
    pointer-events: none;
  }
  .side-column .panel:not(.mobile-open) { display: none; }
  .side-column .panel { pointer-events: auto; }
  .joystick, .mobile-actions { display: grid; }
  .hud { top: env(safe-area-inset-top, 0px); padding-top: 8px; }
  .resource-row { max-width: calc(100% - 88px); }
  .pill { font-size: 12px; padding: 7px 9px; }
  .facility-list { max-height: 30dvh; }
}

@media (min-width: 901px) {
  .mobile-toggle { display: none; }
}
