:root {
  --bg: #0e0c0a;
  --panel: #1a1612;
  --panel-2: #242018;
  --gold: #daa520;
  --gold-dim: #8b6914;
  --cream: #f5f5dc;
  --muted: #9a8b7a;
  --text: #f0e6d8;
  --border: #3d342c;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  touch-action: manipulation;
}

#app { height: 100%; position: relative; }

.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
  background: var(--bg);
}

.screen.active { display: flex; }

.screen.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: var(--bg);
}

/* Splash */
#screen-splash {
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
}

.splash-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% 20%, rgba(218, 165, 32, 0.18), transparent),
    radial-gradient(ellipse 60% 40% at 80% 80%, rgba(178, 34, 34, 0.12), transparent),
    var(--bg);
}

.splash-content { position: relative; z-index: 1; padding: 2rem; width: 100%; max-width: 360px; }

.logo-ring {
  width: 88px;
  height: 88px;
  margin: 0 auto 1.5rem;
  border: 2px solid var(--gold);
  border-radius: 50%;
  background: conic-gradient(from 45deg, #b22222, #191970, #daa520, #93c572, #b22222);
  mask: radial-gradient(circle at center, transparent 55%, black 56%);
  -webkit-mask: radial-gradient(circle at center, transparent 55%, black 56%);
  animation: spin 12s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#screen-splash h1 {
  font-size: 2.8rem;
  font-weight: 300;
  letter-spacing: 0.35em;
  text-indent: 0.35em;
  color: var(--gold);
}

.splash-sub {
  font-size: 0.75rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 0.25rem;
}

.splash-tag {
  margin: 1.5rem 0 2rem;
  color: var(--cream);
  font-size: 1rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 0.7rem 1.2rem;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  margin-bottom: 0.5rem;
}

.btn:active { transform: scale(0.98); }

.btn.primary {
  background: linear-gradient(180deg, #d4ab3a, var(--gold));
  color: #1a1208;
  border-color: var(--gold-dim);
  font-weight: 700;
}

.btn.lg { padding: 1rem 1.5rem; font-size: 1.05rem; }

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  width: auto;
  margin: 0.5rem auto;
}

.btn:disabled { opacity: 0.4; pointer-events: none; }

.btn-back {
  background: none;
  border: none;
  color: var(--gold);
  font-size: 0.95rem;
  padding: 0.5rem;
  cursor: pointer;
}

/* HUD */
.top-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  background: rgba(26, 22, 18, 0.95);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.top-hud.compact h2 { font-size: 1rem; flex: 1; text-align: center; }

.hud-title { font-weight: 700; font-size: 0.9rem; display: block; }

.hud-muted { font-size: 0.72rem; color: var(--muted); }

.hud-stats {
  display: flex;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.hud-stats b { color: var(--cream); }

/* Map */
.map-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
}

#map-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.map-hint {
  position: absolute;
  bottom: 0.75rem;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  pointer-events: none;
}

.bottom-nav {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
}

.bottom-nav button {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0.6rem 0.25rem;
  font-size: 0.65rem;
  cursor: pointer;
}

.bottom-nav .nav-icon {
  display: block;
  font-size: 1.25rem;
  margin-bottom: 0.15rem;
}

/* Hub */
.hub-scene {
  position: relative;
  height: 38vh;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 1.5rem;
  text-align: center;
  overflow: hidden;
}

.hub-scene[data-scene="pastoral"] {
  background: linear-gradient(180deg, #4a6741 0%, #2d4a2d 40%, #1e1812 100%);
}

.hub-scene[data-scene="bazaar"] {
  background: linear-gradient(180deg, #6b4423 0%, #3d2e1e 50%, #1e1812 100%);
}

.hub-scene[data-scene="palace"] {
  background: linear-gradient(180deg, #191970 0%, #2a1f4e 40%, #1e1812 100%);
}

.scene-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 80%, rgba(218, 165, 32, 0.25), transparent 60%);
}

.hub-scene h2 {
  position: relative;
  font-size: 2rem;
  font-weight: 300;
  letter-spacing: 0.15em;
  color: var(--cream);
}

.hub-tagline {
  position: relative;
  font-size: 0.85rem;
  color: rgba(245, 245, 220, 0.75);
  margin-top: 0.35rem;
  max-width: 280px;
}

.hub-order {
  margin: 0.75rem 1rem;
  padding: 0.75rem 1rem;
  background: rgba(218, 165, 32, 0.1);
  border: 1px solid rgba(218, 165, 32, 0.35);
  border-radius: 10px;
  font-size: 0.82rem;
}

.hub-order strong { display: block; color: var(--gold); margin-bottom: 0.2rem; }

.hub-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
  padding: 1rem;
  flex: 1;
}

.hub-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 0.75rem;
  color: var(--text);
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.hub-btn:active { background: var(--panel-2); }

.hub-icon {
  font-size: 1.75rem;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.25rem;
}

.hub-icon.gather { background: rgba(147, 197, 114, 0.2); }
.hub-icon.market { background: rgba(205, 133, 63, 0.2); }
.hub-icon.loom { background: rgba(218, 165, 32, 0.2); }
.hub-icon.orders { background: rgba(178, 34, 34, 0.15); }

.hub-btn span:nth-child(2) { font-weight: 600; font-size: 0.95rem; }
.hub-btn small { font-size: 0.7rem; color: var(--muted); }

/* Gather */
.gather-wrap {
  flex: 1;
  min-height: 0;
  padding: 0.5rem;
}

#gather-canvas {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  touch-action: none;
}

/* Market */
.market-list { padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }

.market-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  width: 100%;
}

.market-row span:last-child { margin-left: auto; color: var(--gold); font-weight: 700; }

.market-row .dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
}

/* Orders */
.orders-list {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
  flex: 1;
}

.order-card {
  display: flex;
  gap: 1rem;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  position: relative;
}

.order-card.locked { opacity: 0.45; pointer-events: none; }
.order-card.active { border-color: var(--gold); }

.order-preview canvas { border-radius: 8px; }

.order-body h3 { font-size: 0.95rem; margin-bottom: 0.2rem; }
.order-body .patron { font-size: 0.8rem; color: var(--muted); }
.order-body .rewards { font-size: 0.8rem; color: var(--gold); margin-top: 0.35rem; }

.badge {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  font-size: 0.65rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: var(--panel-2);
}

.badge.done { color: var(--pistachio, #93c572); }
.badge.lock { color: var(--muted); }
.badge.active { color: var(--gold); }

/* Satchel */
.satchel-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  padding: 1rem;
  overflow-y: auto;
}

.inv-cell {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
  text-align: center;
}

.inv-cell.empty { opacity: 0.35; }

.inv-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin: 0 auto 0.35rem;
  border: 2px solid rgba(255,255,255,0.15);
}

.inv-qty { font-size: 1.25rem; font-weight: 700; display: block; }
.inv-name { font-size: 0.7rem; color: var(--muted); }

/* Gallery */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
}

.gallery-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
  text-align: center;
}

.gallery-card canvas { width: 100%; border-radius: 6px; margin-bottom: 0.5rem; }
.gallery-card p { font-size: 0.75rem; color: var(--muted); }

.empty-msg { padding: 2rem; text-align: center; color: var(--muted); grid-column: 1 / -1; }

/* Loom */
.loom-materials {
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
}

.loom-materials ul { list-style: none; display: flex; flex-wrap: wrap; gap: 0.5rem; }

.loom-materials li {
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  background: var(--panel);
}

.loom-materials li.ok { color: #93c572; }
.loom-materials li.no { color: #e74c3c; }

.loom-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 0.5rem;
  background: #0a0908;
}

#loom-canvas {
  touch-action: none;
  border: 3px solid var(--gold-dim);
  border-radius: 8px;
  box-shadow: 0 0 40px rgba(218, 165, 32, 0.15);
}

.loom-footer {
  padding: 1rem;
  background: var(--panel);
  border-top: 1px solid var(--border);
}

.loom-bar {
  height: 8px;
  background: var(--panel-2);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

#loom-progress {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #b22222, var(--gold));
  transition: width 0.2s ease;
}

.loom-hint {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

/* Reveal */
#screen-reveal {
  align-items: center;
  justify-content: center;
  text-align: center;
  background: radial-gradient(ellipse at center, rgba(218,165,32,0.12), var(--bg));
}

.reveal-wrap { padding: 1.5rem; max-width: 400px; width: 100%; }

.reveal-label {
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
}

#reveal-title { font-size: 1.5rem; margin: 0.5rem 0 1rem; }

#reveal-canvas {
  border: 3px solid var(--gold);
  border-radius: 8px;
  margin-bottom: 1rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.reveal-payout { color: var(--gold); font-weight: 700; margin-bottom: 0.25rem; }
.reveal-rank { color: var(--muted); font-size: 0.9rem; margin-bottom: 1.5rem; }

/* Toast */
.toast {
  position: fixed;
  bottom: calc(1.5rem + var(--safe-b));
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: rgba(0, 0, 0, 0.9);
  border: 1px solid var(--border);
  padding: 0.65rem 1.2rem;
  border-radius: 10px;
  font-size: 0.85rem;
  z-index: 50;
  transition: transform 0.25s ease;
  max-width: 90%;
  text-align: center;
}

.toast.show { transform: translateX(-50%) translateY(0); }
