/* Living Garden — shared styles (mobile-first). CSP allows only same-origin styles + inline width bars. */
:root {
  --bg: #eef6e9; --ink: #1f2d22; --muted: #5d6f60; --card: #ffffffee; --line: #cfe0c8;
  --leaf: #2f6b46; --leaf-2: #3f8f5a; --sun: #f2b84b; --danger: #b8402f; --sky: #bfe3f2;
  --radius: 14px; --shadow: 0 6px 24px #1f2d2222;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { line-height: 1.4; -webkit-tap-highlight-color: transparent; }
h1, h2, h3 { line-height: 1.2; margin: .4em 0; }
a, .link { color: var(--leaf); }
[hidden] { display: none !important; }
input, select, button, textarea { font: inherit; }
input, select, textarea { width: 100%; padding: .55em .7em; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
input[type=checkbox], input[type=radio] { width: auto; }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4em; min-height: 44px; padding: .5em 1em; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); cursor: pointer; font-weight: 600; }
.btn:hover { border-color: var(--leaf-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--leaf); border-color: var(--leaf); color: #fff; }
.btn.primary:hover { background: var(--leaf-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { min-height: 34px; padding: .25em .7em; font-size: .9em; }
.btn.big { min-height: 56px; font-size: 1.1em; width: 100%; }
.link { background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }
.icon-btn { min-width: 44px; min-height: 44px; border: 0; border-radius: 50%; background: transparent; cursor: pointer; font-size: 1.2em; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1em; margin: .75em 0; box-shadow: var(--shadow); }
.muted, .hint { color: var(--muted); }
.hint { font-size: .88em; }
.warning { background: #fff4d6; border: 1px solid var(--sun); border-radius: 10px; padding: .6em .8em; }
.form-error { color: var(--danger); min-height: 1.2em; margin: .3em 0; }
.form { display: grid; gap: .7em; }
.field, label { display: grid; gap: .25em; font-size: .95em; }
.check { display: flex; align-items: center; gap: .5em; }
.inline { display: flex; gap: .5em; align-items: end; flex-wrap: wrap; }
.inline > * { flex: 1 1 8em; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .6em; }
.list { display: grid; gap: .5em; margin: .5em 0; }
.list > * { display: flex; justify-content: space-between; align-items: center; gap: .5em; padding: .5em .6em; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(7em, 1fr)); gap: .5em; margin: .5em 0; }
.stats > * { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: .4em .6em; }

.pill { display: inline-block; padding: .1em .6em; border-radius: 999px; background: #e4efe0; font-size: .85em; font-weight: 600; }
.pill.xp { background: #fff1c9; color: #6b4a00; }
.pill.warn { background: #ffe0d9; color: var(--danger); }
.meter { height: 10px; border-radius: 999px; background: #dbe8d5; overflow: hidden; }
.meter > i { display: block; height: 100%; background: linear-gradient(90deg, var(--leaf-2), var(--sun)); transition: width .4s; }
.dot { display: inline-block; width: .65em; height: .65em; border-radius: 50%; }
.dot.on { background: #3fb35f; }
.dot.off { background: var(--danger); }

.tabs { display: flex; gap: .3em; margin-bottom: .7em; }
.tab { flex: 1; min-height: 40px; border: 1px solid var(--line); background: #fff; border-radius: 10px; cursor: pointer; font-weight: 600; }
.tab.on { background: var(--leaf); color: #fff; border-color: var(--leaf); }
.shop-row { display: flex; justify-content: space-between; align-items: center; gap: .6em; padding: .55em 0; border-bottom: 1px dashed var(--line); }
.shop-row:last-child { border-bottom: 0; }
.choice { display: inline-flex; align-items: center; gap: .4em; padding: .4em .7em; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; }
.claim-code { font: 700 1.6em/1.2 ui-monospace, monospace; letter-spacing: .15em; text-align: center; padding: .4em; border: 2px dashed var(--leaf); border-radius: 12px; background: #fff; user-select: all; }

/* Toasts */
#toasts > :nth-last-child(n+4) { display: none; }
#toasts { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; gap: .4em; z-index: 50; width: min(92vw, 420px); pointer-events: none; }
.toast { padding: .6em .9em; border-radius: 12px; background: #1f2d22ee; color: #fff; box-shadow: var(--shadow); transition: opacity .4s, transform .4s; }
.toast-good { background: #2f6b46ee; }
.toast-error { background: #b8402fee; }
.toast.out { opacity: 0; transform: translateY(8px); }

/* Play page: fullscreen scene with HUD, mission banner and bottom bar */
.page-play { overflow: hidden; background: var(--sky); }
.page-play #app { position: fixed; inset: 0; }
#scene { position: absolute; inset: 0; }
#scene canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.hud { position: absolute; top: env(safe-area-inset-top); left: 0; right: 0; display: flex; flex-wrap: wrap; align-items: center; gap: .4em .6em; padding: .6em .8em; background: linear-gradient(#ffffffd9, #ffffff00); }
.brand { font-weight: 800; color: var(--leaf); margin-right: auto; white-space: nowrap; }
.hud .stats { display: flex; flex-wrap: wrap; gap: .3em; margin: 0; }
.hud .stats > .pill { padding: .15em .6em; border: 0; border-radius: 999px; background: #e4efe0; }
.hud .stats > .pill.xp { background: #fff1c9; }
.hud .stats > .pill.warn { background: #ffe0d9; }
.mission { position: absolute; top: calc(56px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(94vw, 480px); display: grid; gap: .3em; padding: .6em .8em; border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
.mission.phase-idle { display: none; }
.mission.phase-alert { border: 2px solid var(--sun); }
.mission.phase-active { border: 2px solid var(--leaf-2); }
.fallback { position: absolute; inset: 70px 1em 90px; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6em; align-content: start; }
.fallback > * { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .7em; }
.bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: .4em; justify-content: space-around; padding: .5em .5em calc(.5em + env(safe-area-inset-bottom)); background: #ffffffe6; border-top: 1px solid var(--line); }
.tap-hint { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(4.2em + env(safe-area-inset-bottom)); margin: 0; width: min(560px, 92vw); padding: .45em .8em; border-radius: 12px; background: #ffffffee; border: 1px solid var(--line); font-size: .88em; text-align: center; pointer-events: none; }
.bar .btn { flex: 1; min-width: 0; padding: .4em .3em; font-size: .9em; }

/* Bottom sheet */
.backdrop { position: fixed; inset: 0; z-index: 40; background: #1f2d2255; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; max-height: 88vh; display: flex; flex-direction: column; background: #fbfdf9; border-radius: 18px 18px 0 0; box-shadow: var(--shadow); padding-bottom: env(safe-area-inset-bottom); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: .6em .9em; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 1.15em; margin: 0; }
.sheet-body { overflow: auto; padding: .8em 1em 1.2em; }
@media (max-width: 520px) {
  .hud { flex-wrap: nowrap; gap: .3em; padding: .4em .5em; font-size: .85em; }
  .brand { display: none; }
  .hud .stats { flex-wrap: nowrap; margin-right: auto; }
  .hud .icon-btn { min-width: 36px; min-height: 36px; }
  .mission { top: calc(48px + env(safe-area-inset-top)); font-size: .9em; padding: .5em .7em; }
  .mission .btn.primary { min-height: 40px; }
  .toast { padding: .45em .7em; font-size: .9em; }
}
@media (min-width: 760px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: 18px; }
  .bar { left: 50%; right: auto; transform: translateX(-50%); bottom: 1em; border-radius: 16px; border: 1px solid var(--line); width: min(620px, 90vw); padding: .5em; }
}

/* Sandbox & admin pages: plain document layout */
.page-sandbox #app, .page-admin #app { max-width: 1100px; margin: 0 auto; padding: 1em; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .8em; display: grid; gap: .6em; margin: .75em 0; background: #fff; }
.quick { display: flex; flex-wrap: wrap; gap: .4em; }
.sandbox-log { font: .9em/1.5 ui-monospace, monospace; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: .6em 1.8em; max-height: 40vh; overflow: auto; }

.admin-login { max-width: 420px; margin: 10vh auto; }
.admin-filters { display: flex; flex-wrap: wrap; gap: .6em; align-items: end; }
.admin-filters > * { flex: 1 1 10em; }
.admin-exp { display: flex; flex-wrap: wrap; gap: .5em; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6em; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .7em .8em; min-width: 0; overflow-wrap: anywhere; }
.tile-label { color: var(--muted); font-size: .82em; }
.tile strong, .tile b { display: block; font-size: 1.4em; font-variant-numeric: tabular-nums; }
.series { display: grid; gap: .3em; }
.series-row { display: grid; grid-template-columns: 7em 1fr 6em; gap: .5em; align-items: center; font-variant-numeric: tabular-nums; font-size: .9em; }
.series svg { width: 100%; height: 14px; }
.series svg rect { fill: var(--leaf-2); }
.scroll { overflow: auto; max-width: 100%; }
.journal { border-collapse: collapse; width: 100%; font-size: .85em; font-variant-numeric: tabular-nums; }
.journal th, .journal td { text-align: left; padding: .35em .5em; border-bottom: 1px solid var(--line); white-space: nowrap; }
.journal th { position: sticky; top: 0; background: #f3f8f0; }
.d-applied { background: #eaf6e6; }
.d-ignored { color: var(--muted); }
.d-disabled { background: #fff4d6; }
.d-suppressed { background: #fbe9e5; }
.reasons { columns: 2 16em; font-size: .9em; }
.kill { display: flex; flex-wrap: wrap; align-items: center; gap: .6em; padding: .8em; border: 2px solid var(--line); border-radius: var(--radius); background: #fff; }
.kill.on { border-color: var(--danger); background: #fbe9e5; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.garden-cover { display: block; width: 100%; height: auto; max-height: 180px; object-fit: cover; border-radius: 16px; }
