:root {
  --bg-glass: rgba(255, 252, 245, 0.86);
  --bg-glass-strong: rgba(255, 252, 245, 0.96);
  --border-soft: rgba(255, 255, 255, 0.85);
  --shadow-soft: 0 8px 28px rgba(45, 72, 95, 0.16);
  --shadow-btn: 0 3px 10px rgba(45, 72, 95, 0.12);
  --text-main: #354756;
  --text-muted: #6c7f8e;
  --accent-mint: #5ec9a7;
  --accent-mint-dark: #43af8d;
  --accent-sky: #65b8f0;
  --accent-coral: #ff8a7a;
  --accent-coral-dark: #e86d5c;
  --accent-amber: #ffbe5c;
  --accent-lavender: #a992f5;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-pill: 999px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Prompt', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text-main);
  background: #87ceeb;
  touch-action: none;
}

#canvas-container {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ===== TOP BAR ===== */
.top-bar {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.top-group {
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid var(--border-soft);
  border-radius: var(--radius-pill);
  padding: 5px 8px;
  box-shadow: var(--shadow-soft);
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px 5px 10px;
}

.brand-icon {
  font-size: 22px;
  line-height: 1;
}

.brand-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.2px;
  color: var(--text-main);
  line-height: 1.1;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Buttons */
.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: none;
  background: rgba(255, 255, 255, 0.72);
  color: var(--text-main);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 11px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: transform 0.14s ease, background 0.16s ease, box-shadow 0.16s ease;
  box-shadow: 0 2px 6px rgba(45, 72, 95, 0.08);
  min-height: 36px;
  min-width: 36px;
}

.icon-btn:hover {
  background: #ffffff;
  transform: translateY(-1px);
  box-shadow: var(--shadow-btn);
}

.icon-btn:active {
  transform: scale(0.95);
}

.icon-btn.active {
  background: var(--accent-mint);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(94, 201, 167, 0.4);
}

.icon-btn.trade-btn {
  background: linear-gradient(135deg, #ffd166, #ffad5c);
  color: #4a2e10;
  box-shadow: 0 3px 10px rgba(255, 173, 92, 0.42);
}

.icon-btn.trade-btn:hover {
  background: linear-gradient(135deg, #ffe08a, #ffb970);
}

.trade-badge {
  position: absolute;
  top: -5px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ff5e5e;
  color: #ffffff;
  font-size: 10.5px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(255, 94, 94, 0.45);
}

.icon-btn.danger:hover {
  background: var(--accent-coral);
  color: #ffffff;
}

.icon-btn:disabled {
  opacity: 0.42;
  pointer-events: none;
}

.time-pill, .weather-pill, .size-pill {
  padding: 6px 9px;
  font-size: 12.5px;
}

.time-pill.active {
  background: var(--accent-sky);
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(101, 184, 240, 0.45);
}

.weather-pill.active {
  background: var(--accent-lavender);
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(169, 146, 245, 0.45);
}

.size-pill.active {
  background: var(--accent-mint);
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(94, 201, 167, 0.42);
}

.mode-pill {
  padding: 6px 12px;
  font-size: 13px;
}

.mode-pill.active[data-mode="build"] {
  background: var(--accent-mint);
  color: #ffffff;
}

.mode-pill.active[data-mode="play"] {
  background: linear-gradient(135deg, #ff7e6b, #ff9f5a);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(255, 126, 107, 0.42);
}

/* ===== MODE HINT BANNER ===== */
.hint-wrap {
  flex-basis: 100%;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.hint-banner {
  background: var(--bg-glass-strong);
  backdrop-filter: blur(12px);
  border: 1.5px solid var(--border-soft);
  border-radius: var(--radius-pill);
  padding: 7px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
  box-shadow: var(--shadow-soft);
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  white-space: nowrap;
  max-width: 92vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hint-banner.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ===== FLOATING CONTEXT ACTION BAR ===== */
.context-bar {
  position: fixed;
  bottom: 162px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  z-index: 22;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-glass-strong);
  backdrop-filter: blur(14px);
  border: 1.5px solid var(--border-soft);
  border-radius: var(--radius-pill);
  padding: 6px 10px;
  box-shadow: var(--shadow-soft);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: 95vw;
  flex-wrap: wrap;
  justify-content: center;
}

.context-bar.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.context-label {
  font-size: 13px;
  font-weight: 700;
  padding: 0 8px;
  color: var(--text-main);
}

.context-divider {
  width: 1px;
  height: 22px;
  background: rgba(53, 71, 86, 0.14);
  margin: 0 2px;
}

/* ===== BOTTOM DOCK ===== */
.bottom-dock {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  width: min(890px, calc(100vw - 20px));
  background: var(--bg-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1.5px solid var(--border-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.category-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.cat-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: rgba(255, 255, 255, 0.65);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all 0.16s ease;
}

.cat-tab:hover {
  background: #ffffff;
  color: var(--text-main);
}

.cat-tab.active {
  background: var(--accent-mint);
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(94, 201, 167, 0.35);
}

.items-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
  padding: 2px 2px 4px;
}

.items-strip::-webkit-scrollbar {
  height: 5px;
}

.items-strip::-webkit-scrollbar-thumb {
  background: rgba(53, 71, 86, 0.18);
  border-radius: 10px;
}

.item-card {
  flex: 0 0 auto;
  width: 92px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 6px;
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 2px 8px rgba(45, 72, 95, 0.08);
}

.item-card:hover {
  transform: translateY(-2px);
  background: #ffffff;
  box-shadow: 0 5px 14px rgba(45, 72, 95, 0.14);
}

.item-card:active {
  transform: scale(0.95);
}

.item-card.selected {
  border-color: var(--accent-mint-dark);
  background: #ecfff8;
  box-shadow: 0 4px 14px rgba(94, 201, 167, 0.35);
}

.item-card.locked {
  opacity: 0.78;
  background: rgba(246, 242, 255, 0.85);
}

.item-emoji {
  font-size: 26px;
  line-height: 1.1;
}

.item-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
  text-align: center;
  line-height: 1.2;
  white-space: nowrap;
}

.item-tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 99px;
  font-weight: 500;
}

.tag-land  { background: #e5f7ea; color: #2f8b55; }
.tag-water { background: #e2f3ff; color: #2278b8; }
.tag-shore { background: #fff3dc; color: #b5731a; }
.tag-draw  { background: #efe8ff; color: #6b4cd4; }

/* ===== TOAST NOTIFICATION ===== */
.toast {
  position: fixed;
  top: 126px;
  right: 16px;
  z-index: 50;
  background: var(--text-main);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ===== MODALS (Clear & Trading) ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(28, 46, 62, 0.44);
  backdrop-filter: blur(5px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  background: #fffdf8;
  border-radius: 24px;
  padding: 22px 24px;
  width: min(350px, 92vw);
  box-shadow: 0 18px 48px rgba(24, 42, 60, 0.28);
  text-align: center;
}

.modal-card h3 {
  margin: 0 0 8px;
  font-size: 18px;
  color: var(--text-main);
}

.modal-card p {
  margin: 0 0 18px;
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.modal-actions .icon-btn {
  flex: 1;
  padding: 10px 14px;
  font-size: 14px;
}

.btn-primary-danger {
  background: var(--accent-coral);
  color: #fff;
}

.btn-primary-danger:hover {
  background: var(--accent-coral-dark);
  color: #fff;
}

/* ===== TRADING MODAL ===== */
.trade-card {
  width: min(560px, 95vw);
  max-height: 86vh;
  overflow-y: auto;
  text-align: left;
  padding: 20px 22px;
}

.trade-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.trade-header h3 {
  margin: 0;
  font-size: 18px;
}

.trade-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.trade-resources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
  padding: 10px;
  border-radius: 16px;
  background: #f4f8fb;
}

.res-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #ffffff;
  border: 1px solid rgba(53, 71, 86, 0.08);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 600;
}

.res-rate {
  font-size: 10.5px;
  color: #2f8b55;
  background: #e5f7ea;
  border-radius: 99px;
  padding: 1px 5px;
}

.res-swap-btn {
  border: none;
  background: #fff2d6;
  color: #9e6214;
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 700;
  border-radius: 99px;
  padding: 2px 6px;
  cursor: pointer;
  margin-left: 2px;
}

.res-swap-btn:hover {
  background: #ffd166;
}

.trade-tagline {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 10px 0 12px;
}

.trade-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.trade-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: #ffffff;
  border: 1.5px solid rgba(53, 71, 86, 0.08);
  box-shadow: 0 2px 8px rgba(45, 72, 95, 0.05);
}

.trade-row.unlocked {
  background: #f2fff9;
  border-color: rgba(94, 201, 167, 0.35);
}

.trade-item-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.trade-emoji {
  font-size: 30px;
  line-height: 1;
}

.trade-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}

.trade-costs {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
}

.cost-pill {
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
}

.cost-ok  { background: #e5f7ea; color: #267d4a; }
.cost-low { background: #ffecec; color: #c94747; }

.trade-tip {
  margin-top: 12px;
  font-size: 11.5px;
  color: var(--text-muted);
  text-align: center;
}

/* ===== PLAY MODE HUD ===== */
.play-hud {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 19;
  pointer-events: none;
}

body.mode-play .play-hud {
  display: block;
}

body.mode-play .bottom-dock,
body.mode-play .context-bar,
body.mode-play .hint-wrap {
  display: none !important;
}

.play-top-stack {
  position: fixed;
  top: 122px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: 94vw;
}

.play-compass, .play-resources {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1.5px solid var(--border-soft);
  border-radius: var(--radius-pill);
  padding: 5px 12px;
  box-shadow: var(--shadow-soft);
}

.compass-pill {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.72);
  padding: 2px 8px;
  border-radius: 99px;
}

.compass-pill.here {
  background: #e5f7ea;
  color: #267d4a;
}

.play-res-item {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-main);
  padding: 1px 5px;
}

.quest-card {
  position: fixed;
  top: 152px;
  left: 14px;
  width: min(230px, 60vw);
  background: var(--bg-glass-strong);
  backdrop-filter: blur(12px);
  border: 1.5px solid var(--border-soft);
  border-radius: 18px;
  padding: 10px 14px;
  box-shadow: var(--shadow-soft);
}

.quest-title {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--accent-mint-dark);
  margin-bottom: 3px;
}

.quest-text {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.35;
}

.quest-progress {
  margin-top: 5px;
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  background: #fff3dc;
  color: #a86414;
  padding: 2px 9px;
  border-radius: 99px;
}

/* Virtual Joystick */
.joy-zone {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: rgba(255, 252, 245, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  touch-action: none;
}

.joy-knob {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5ec9a7, #43af8d);
  border: 2.5px solid #ffffff;
  box-shadow: 0 4px 14px rgba(45, 72, 95, 0.25);
  transition: transform 0.04s linear;
}

/* Bottom-Right Action & Jump */
.play-actions {
  position: fixed;
  bottom: 24px;
  right: 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: auto;
}

.play-action-btn, .play-jump-btn {
  border: 2px solid rgba(255, 255, 255, 0.9);
  font-family: inherit;
  font-weight: 700;
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.14s ease, background 0.16s ease;
}

.play-action-btn {
  padding: 11px 18px;
  font-size: 13.5px;
  background: var(--bg-glass-strong);
  color: var(--text-muted);
}

.play-action-btn.ready {
  background: linear-gradient(135deg, #ffd166, #ff9f5a);
  color: #4a2a0b;
  transform: scale(1.03);
}

.play-action-btn:active, .play-jump-btn:active {
  transform: scale(0.95);
}

.play-jump-btn {
  padding: 11px 18px;
  font-size: 14px;
  background: linear-gradient(135deg, #65b8f0, #4ea3e0);
  color: #ffffff;
}

/* ===== RESPONSIVE MOBILE ===== */
@media (max-width: 720px) {
  .brand-sub, .btn-text-hide { display: none; }
  .brand-badge { padding: 4px 10px 4px 8px; }
  .brand-title { font-size: 13.5px; }
  .top-bar { top: 8px; left: 8px; right: 8px; gap: 6px; }
  .top-group { padding: 4px 6px; gap: 4px; }
  .icon-btn { padding: 6px 9px; font-size: 12.5px; min-height: 34px; min-width: 34px; }
  .bottom-dock { bottom: 8px; width: calc(100vw - 14px); padding: 7px 8px 8px; }
  .item-card { width: 82px; padding: 7px 4px; }
  .item-emoji { font-size: 24px; }
  .context-bar { bottom: 154px; padding: 5px 8px; }
  .hint-banner { font-size: 12px; }
}
