:root {
  --bg: #0c1410;
  --panel: rgba(10, 24, 14, 0.92);
  --cream: #f6f0e2;
  --moss: #6fbf73;
  --moss-deep: #2f6b3a;
  --sun: #ffd54a;
  --danger: #e85d4c;
  --line: rgba(255, 255, 255, 0.12);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  font-family: "Segoe UI", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
}

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

html, body {
  margin: 0; width: 100%; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--cream);
  touch-action: none; user-select: none;
}

#app { position: relative; width: 100%; height: 100%; }
#game-canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.hidden { display: none !important; }

/* ===== HUD ===== */
#hud {
  position: absolute; inset: 0; pointer-events: none;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: calc(8px + var(--safe-top)) 8px calc(8px + var(--safe-bottom));
  z-index: 5;
}

.hud-top {
  display: flex; align-items: center; gap: 8px; pointer-events: auto;
}

.sun-badge {
  display: flex; align-items: center; gap: 8px; min-width: 88px;
  padding: 8px 12px; border-radius: 999px;
  background: linear-gradient(180deg, #4a3208, #1f1606);
  border: 1px solid rgba(255, 213, 74, 0.5);
  box-shadow: 0 6px 18px rgba(0,0,0,.4);
  font-weight: 800; font-size: 1.1rem;
}
.sun-icon { color: var(--sun); filter: drop-shadow(0 0 6px rgba(255,213,74,.7)); }

.level-block { flex: 1; text-align: center; min-width: 0; }
.level-title {
  font-size: 0.88rem; font-weight: 800;
  text-shadow: 0 2px 8px rgba(0,0,0,.7);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.level-sub { font-size: 0.68rem; opacity: .75; margin-top: 2px; }

.hud-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  border: 1px solid var(--line); background: var(--panel); color: var(--cream);
  border-radius: 11px; padding: 8px 10px; font-weight: 700; font-size: 0.85rem;
  min-width: 36px;
}
.chip:active { transform: scale(0.96); }

.banner {
  align-self: center; margin-top: 10px; padding: 10px 16px; border-radius: 14px;
  background: rgba(160, 30, 24, 0.94); border: 1px solid rgba(255,200,180,.35);
  font-weight: 800; animation: pulse 1.1s ease-in-out infinite; pointer-events: none;
  max-width: 92%; text-align: center;
}
@keyframes pulse {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

.hud-mid {
  flex: 1; display: flex; align-items: flex-start; justify-content: space-between;
  gap: 8px; padding: 8px 0; pointer-events: none; min-height: 0;
}

.cam-dock {
  /* Style Bible: single reset control only */
  display: grid; grid-template-columns: 44px; gap: 6px;
  pointer-events: auto; align-content: start;
}
.cam-btn {
  width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid var(--line); background: rgba(8,20,12,.82);
  color: var(--cream); font-size: 1rem; font-weight: 800;
  box-shadow: 0 4px 12px rgba(0,0,0,.35);
}
.cam-btn:active { background: rgba(80,140,80,.35); }

.inspect-card {
  pointer-events: auto; width: min(280px, 72vw);
  background: linear-gradient(180deg, rgba(20,40,24,.96), rgba(8,16,10,.96));
  border: 1px solid var(--line); border-radius: 16px; padding: 12px;
  display: flex; gap: 10px; position: relative;
  box-shadow: 0 12px 30px rgba(0,0,0,.45); max-height: 42vh; overflow: auto;
}
.inspect-x {
  position: absolute; top: 6px; right: 8px; border: 0; background: transparent;
  color: var(--cream); font-size: 1.2rem; opacity: .7;
}
.inspect-swatch {
  width: 48px; height: 48px; border-radius: 14px; flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.2);
}
.inspect-name { font-weight: 800; font-size: 0.95rem; padding-right: 18px; }
.inspect-role { font-size: 0.72rem; color: var(--moss); margin: 2px 0 6px; }
.inspect-stats { font-size: 0.72rem; opacity: .85; margin-bottom: 6px; line-height: 1.4; }
.inspect-desc, .inspect-tips { margin: 0 0 6px; font-size: 0.75rem; line-height: 1.4; opacity: .9; }
.inspect-tips { color: #f0d78c; }

.hud-bottom { pointer-events: auto; }
.seed-bar {
  display: flex; gap: 8px; overflow-x: auto; padding: 8px 2px 4px;
  -webkit-overflow-scrolling: touch;
}
.seed {
  position: relative; flex: 0 0 auto; width: 80px; min-height: 108px;
  border-radius: 14px; border: 1.5px solid rgba(44,36,22,.22);
  background: linear-gradient(180deg, #fff8ee, #f0e6d4);
  color: #2c2416; display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start; gap: 4px;
  padding: 8px 6px 6px; box-shadow: 0 6px 16px rgba(40,30,10,.2);
  transition: transform .12s ease, filter .12s ease, border-color .12s ease;
}
.seed:hover:not(.disabled) {
  transform: translateY(-2px);
  border-color: rgba(61,139,64,.45);
}
.seed.selected {
  border-color: #e8a317;
  box-shadow: 0 0 0 2px rgba(232,163,23,.35), 0 8px 18px rgba(40,30,10,.22);
  transform: translateY(-3px);
}
.seed.disabled {
  opacity: 1;
  filter: saturate(0.35) brightness(0.95);
  border-color: rgba(44,36,22,.12);
}
.seed-swatch {
  width: 38px; height: 38px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.25); position: relative;
}
.seed-info {
  position: absolute; top: 4px; right: 4px; width: 18px; height: 18px;
  border-radius: 50%; border: 0; background: rgba(0,0,0,.45);
  color: #fff; font-size: 0.65rem; font-weight: 800; line-height: 18px; padding: 0;
  display: grid; place-items: center; cursor: pointer; z-index: 2;
}
.seed-name { font-size: 0.62rem; font-weight: 700; text-align: center; line-height: 1.15; color: #2c2416; }
.seed-cost { font-size: 0.78rem; font-weight: 800; color: #c47b00; }
.seed-role { font-size: 0.55rem; opacity: .7; text-align: center; line-height: 1.1; color: #3d5c32; }
.seed-cd {
  position: absolute; inset: 0; border-radius: 12px;
  background: rgba(44,36,22,.52); color: #fff8ee;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.95rem;
}

.hint-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 4px;
}
.hint {
  margin: 0; font-size: 0.68rem; opacity: .78; flex: 1; line-height: 1.3;
  text-shadow: 0 1px 4px rgba(0,0,0,.8);
}
.mode-pill {
  flex-shrink: 0; font-size: 0.65rem; font-weight: 800;
  padding: 4px 8px; border-radius: 999px;
  background: rgba(0,0,0,.45); border: 1px solid var(--line);
}
.mode-pill.place { background: rgba(80,140,40,.45); border-color: rgba(180,255,120,.35); color: #d8ffc0; }

/* ===== Overlays ===== */
.overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  padding: 14px; z-index: 20; overflow: auto;
  background: radial-gradient(circle at 50% 18%, rgba(70,120,70,.32), rgba(6,12,8,.94));
}
.card {
  width: min(520px, 100%);
  background: linear-gradient(180deg, rgba(28,48,32,.98), rgba(12,20,14,.98));
  border: 1px solid var(--line); border-radius: 22px;
  padding: 18px 16px 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
.menu-card { width: min(560px, 100%); max-height: min(92vh, 900px); overflow: auto; }
.modal-card.wide { width: min(520px, 100%); }
.eyebrow {
  margin: 0; text-transform: uppercase; letter-spacing: .12em;
  font-size: 0.66rem; opacity: .7;
}
h1 { margin: 8px 0 8px; font-size: clamp(1.5rem, 5.5vw, 2rem); line-height: 1.1; }
h2 { margin: 0 0 10px; font-size: 1.45rem; }
.lede { margin: 0 0 14px; opacity: .9; line-height: 1.45; font-size: 0.92rem; }

.menu-tabs, .almanac-tabs {
  display: flex; gap: 6px; margin-bottom: 12px;
}
.tab, .altab {
  flex: 1; border: 1px solid var(--line); background: rgba(255,255,255,.04);
  color: var(--cream); border-radius: 12px; padding: 10px 8px; font-weight: 800;
  font-size: 0.85rem;
}
.tab.active, .altab.active {
  background: rgba(111,191,115,.22); border-color: rgba(111,191,115,.55);
}

.level-list { display: grid; gap: 8px; }
.stage-head {
  margin: 10px 0 4px; font-size: 0.72rem; font-weight: 800;
  letter-spacing: .08em; text-transform: uppercase; opacity: .65;
}
.stage-head:first-child { margin-top: 0; }
.level-btn {
  width: 100%; text-align: left; border: 1px solid var(--line);
  background: rgba(255,255,255,.04); color: var(--cream);
  border-radius: 14px; padding: 12px 12px; font-weight: 700;
}
.level-btn:disabled { opacity: .4; }
.level-btn:not(:disabled):active,
.level-btn:not(:disabled):hover {
  border-color: var(--moss); background: rgba(111,191,115,.12);
}
.level-btn small {
  display: block; margin-top: 4px; font-weight: 500; opacity: .72; line-height: 1.35;
}
.level-btn .tag {
  display: inline-block; margin-top: 6px; font-size: 0.65rem;
  padding: 2px 8px; border-radius: 999px;
  background: rgba(255,255,255,.08); margin-right: 4px;
}
.level-btn .tag.fog { background: rgba(120,140,180,.25); color: #c5d4f0; }

.how-grid { display: grid; gap: 8px; }
.how-grid.compact { margin-bottom: 12px; }
.how-card {
  background: rgba(255,255,255,.04); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px;
}
.how-card h3 { margin: 0 0 6px; font-size: 0.92rem; }
.how-card p { margin: 0; font-size: 0.8rem; line-height: 1.45; opacity: .9; }
.how-card code {
  background: rgba(0,0,0,.35); padding: 1px 5px; border-radius: 5px; font-size: 0.78rem;
}

.almanac-list { display: grid; gap: 8px; max-height: 48vh; overflow: auto; }
.al-item {
  display: flex; gap: 10px; text-align: left; width: 100%;
  border: 1px solid var(--line); background: rgba(255,255,255,.04);
  border-radius: 14px; padding: 10px; color: var(--cream);
}
.al-swatch {
  width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.18);
}
.al-item strong { display: block; font-size: 0.88rem; }
.al-item .role { font-size: 0.7rem; color: var(--moss); margin: 2px 0; }
.al-item .snip { font-size: 0.72rem; opacity: .8; line-height: 1.35; }

.fineprint { margin: 14px 0 0; font-size: 0.66rem; opacity: .55; line-height: 1.4; }

.modal-actions { display: grid; gap: 8px; }
.btn {
  border: 0; border-radius: 14px; padding: 12px 14px;
  font-weight: 800; font-size: 1rem;
}
.btn.primary { background: linear-gradient(180deg, var(--moss), var(--moss-deep)); color: #fff; }
.btn.secondary { background: rgba(255,255,255,.1); color: var(--cream); }
.btn.ghost { background: transparent; color: rgba(255,255,255,.75); border: 1px solid var(--line); }

.quality-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 10px;
}
.qbtn {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.05);
  color: var(--cream);
  border-radius: 12px;
  padding: 10px 6px;
  font-weight: 800;
  font-size: 0.85rem;
}
.qbtn.active {
  background: rgba(111,191,115,.28);
  border-color: rgba(111,191,115,.7);
  box-shadow: 0 0 0 1px rgba(111,191,115,.3);
}

.hp-bar {
  position: absolute;
  left: 0; top: 0;
  width: 44px; height: 6px;
  border-radius: 4px;
  background: rgba(0,0,0,.55);
  border: 1px solid rgba(255,255,255,.25);
  overflow: hidden;
  pointer-events: none;
}
.hp-fill {
  height: 100%;
  width: 100%;
  background: #66bb6a;
  transition: width 0.08s linear;
}

#fx-dom, #hp-dom {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

@media (min-width: 768px) {
  .seed { width: 88px; min-height: 112px; }
  .seed-name { font-size: 0.7rem; }
  .cam-dock { grid-template-columns: repeat(2, 44px); }
  .cam-btn { width: 44px; height: 44px; }
}
