/* PaliaPal Garden Planner styles. Tokens at the top map to PaliaPal's teal/purple/gold palette. */
:root {
  --bg: #121626; --panel: #1a1f35; --panel-2: #222943; --line: #2f3758; --text: #eef0f7; --muted: #9ea7c6;
  --teal: #2fa7a4; --teal-soft: rgba(47,167,164,.16); --purple: #8d5fc6; --purple-soft: rgba(141,95,198,.18); --gold: #e3a93b;
  --water: #4aa8e0; --weed: #5bbf6a; --harvest: #e3a93b; --quality: #b67cf0; --growth: #f06a8a;
  --soil: #6e4a2e; --soil-empty: #4f3522; --soil-line: #3a2717; --warn: #e0674f;
  --sky-top: #2a2f5e; --sky-bottom: #58407a; --grass: #3f7a4a;
  --radius-lg: 18px; --radius: 12px; --radius-sm: 8px;
  --font-display: 'Fredoka', 'Nunito', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --emoji: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f4fa; --panel: #ffffff; --panel-2: #f1f0f8; --line: #dcdcec; --text: #231f3a; --muted: #625d80;
    --teal-soft: rgba(47,167,164,.12); --purple-soft: rgba(141,95,198,.12);
    --soil: #8a5c38; --soil-empty: #6f4a2c; --soil-line: #54371f;
    --sky-top: #9fd3f0; --sky-bottom: #e8d9f7; --grass: #6fae5b;
  }
}
:root[data-theme="light"] {
  --bg: #f3f4fa; --panel: #ffffff; --panel-2: #f1f0f8; --line: #dcdcec; --text: #231f3a; --muted: #625d80;
  --teal-soft: rgba(47,167,164,.12); --purple-soft: rgba(141,95,198,.12);
  --soil: #8a5c38; --soil-empty: #6f4a2c; --soil-line: #54371f;
  --sky-top: #9fd3f0; --sky-bottom: #e8d9f7; --grass: #6fae5b;
}
*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font-body); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.emoji { font-family: var(--emoji); line-height: 1; }

/* ---------- Header ---------- */
.top { max-width: 1320px; margin: 0 auto; padding: 22px 20px 10px; display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px 28px; justify-content: space-between; }
.embedded-top { justify-content: flex-start; padding-top: 8px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 52px; height: 52px; border-radius: 16px; background: linear-gradient(145deg, var(--teal), var(--purple)); display: grid; place-items: center; font-size: 28px; box-shadow: 0 6px 18px rgba(0,0,0,.25); }
.brand h1 { font-family: var(--font-display); font-weight: 700; font-size: 30px; line-height: 1.05; margin: 0; letter-spacing: -.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 14.5px; }
.modes { display: flex; gap: 6px; background: var(--panel); border: 1px solid var(--line); padding: 5px; border-radius: 999px; flex-wrap: wrap; }
.mode-btn { border: 0; background: transparent; padding: 9px 16px; border-radius: 999px; font-family: var(--font-display); font-weight: 600; font-size: 15px; color: var(--muted); display: flex; align-items: center; gap: 7px; transition: background .2s, color .2s; }
.mode-btn:hover { color: var(--text); }
.mode-btn[aria-selected="true"] { background: var(--purple); color: #fff; }
.mode-btn[data-mode="generate"][aria-selected="true"] { background: var(--teal); }
.mode-btn[data-mode="create"][aria-selected="true"] { background: #c98a1c; }

/* ---------- Layout ---------- */
.layout { max-width: 1320px; margin: 0 auto; padding: 8px 20px 40px; display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; }
@media (max-width: 980px) { .layout { grid-template-columns: 1fr; } }
@media (min-width: 981px) { .stage { position: sticky; top: 12px; } }

.stage { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.stage-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.seg { display: inline-flex; background: var(--panel-2); border-radius: 999px; padding: 3px; border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 999px; font-weight: 700; font-size: 13.5px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.icon-btn { border: 1px solid var(--line); background: var(--panel-2); border-radius: 999px; padding: 5px 11px; font-weight: 700; font-size: 13.5px; display: inline-flex; gap: 6px; align-items: center; }
.icon-btn:disabled { opacity: .4; cursor: default; }
.stage-action { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; background: var(--purple-soft); border-bottom: 1px solid var(--line); font-size: 14px; }
.stage-action[hidden] { display: none; }
.stage-action b { font-family: var(--font-display); font-weight: 600; }
.stage-action .btn { padding: 7px 14px; font-size: 14.5px; }
.stage-hint { margin-left: auto; color: var(--muted); font-size: 13px; }

.viewport { position: relative; height: min(62vh, 620px); min-height: 380px; background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom)); overflow: hidden; touch-action: none; user-select: none; }
.viewport canvas { display: block; width: 100%; height: 100%; }
.viewport.view-2d canvas { display: none; }
.grid2d-wrap { position: absolute; inset: 0; display: none; place-items: center; padding: 18px; }
.viewport.view-2d .grid2d-wrap { display: grid; }
.grid2d { position: relative; display: grid; gap: 3px; padding: 10px; background: var(--grass); border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,.25); touch-action: none; }
.tile { border: 0; padding: 0; border-radius: 6px; background: var(--soil-empty); box-shadow: inset 0 -3px 0 var(--soil-line); position: relative; min-width: 0; min-height: 0; }
.tile.planted { background: var(--soil); }
.tile.warn { box-shadow: inset 0 -3px 0 var(--soil-line), inset 0 0 0 2px var(--warn); }
.tile.ghost-ok { box-shadow: inset 0 0 0 3px #7ee2a8; }
.tile.ghost-bad { box-shadow: inset 0 0 0 3px var(--warn); }
.tile .fert { position: absolute; top: 2px; right: 3px; font-size: calc(var(--cell) * .24); font-family: var(--emoji); pointer-events: none; }
.plot-frame { pointer-events: none; border-radius: 10px; box-shadow: 0 0 0 2px rgba(255,255,255,.18); margin: -3px; }
.crop2d { pointer-events: none; display: grid; place-items: center; position: relative; z-index: 1; }
.crop2d .ce { font-family: var(--emoji); font-size: calc(var(--cell) * var(--span) * .56); line-height: 1; filter: drop-shadow(0 2px 2px rgba(0,0,0,.3)); }
.crop2d .bf { position: absolute; left: 0; right: 0; bottom: 1px; display: flex; justify-content: center; gap: 1px; font-family: var(--emoji); font-size: calc(var(--cell) * .2); line-height: 1; }
.crop2d.pop .ce { animation: pop .45s cubic-bezier(.3,1.6,.5,1); }
@keyframes pop { from { transform: scale(0) rotate(-20deg); } to { transform: scale(1) rotate(0); } }

.tooltip { position: absolute; z-index: 5; pointer-events: none; background: rgba(20,22,40,.92); color: #fff; padding: 8px 11px; border-radius: 10px; font-size: 13px; max-width: 240px; line-height: 1.35; box-shadow: 0 6px 20px rgba(0,0,0,.3); opacity: 0; transition: opacity .12s; }
.tooltip.show { opacity: 1; }
.tooltip b { font-family: var(--font-display); font-weight: 600; }
.particles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 4; }
.particle { position: absolute; font-family: var(--emoji); font-size: 22px; animation: floatUp 1s ease-out forwards; }
@keyframes floatUp { 0% { transform: translate(-50%, -50%) scale(.4); opacity: 0; } 20% { opacity: 1; } 100% { transform: translate(calc(-50% + var(--dx)), calc(-50% - 70px)) scale(1.1); opacity: 0; } }
.toast { position: absolute; left: 50%; top: 16px; transform: translate(-50%, -20px); background: var(--panel); color: var(--text); border: 1px solid var(--line); padding: 9px 16px; border-radius: 999px; font-weight: 700; font-size: 14px; opacity: 0; transition: opacity .25s, transform .25s; z-index: 6; box-shadow: 0 8px 24px rgba(0,0,0,.3); white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.gen-overlay { position: absolute; inset: 0; z-index: 7; display: none; place-items: center; background: rgba(18,22,38,.55); backdrop-filter: blur(3px); }
.gen-overlay.show { display: grid; }
.gen-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 22px 26px; text-align: center; width: min(320px, 86%); }
.gen-emoji { font-size: 44px; font-family: var(--emoji); display: inline-block; animation: wiggle .6s ease-in-out infinite alternate; }
@keyframes wiggle { from { transform: rotate(-10deg) translateY(0); } to { transform: rotate(10deg) translateY(-6px); } }
.gen-msg { font-family: var(--font-display); font-weight: 600; margin: 8px 0 12px; }
.progress { height: 10px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--teal), var(--purple)); border-radius: 999px; transition: width .15s linear; }

/* Coverage */
.coverage { padding: 14px 16px 16px; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 18px; }
.cov-item { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; align-items: center; }
.cov-item .ci { font-family: var(--emoji); font-size: 20px; grid-row: span 2; }
.cov-label { font-size: 13px; font-weight: 700; display: flex; justify-content: space-between; gap: 6px; }
.cov-label span { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.bar { height: 7px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; border-radius: 999px; transition: width .35s ease; }
.cov-summary { grid-column: 1 / -1; font-size: 13.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px 16px; }
.cov-summary strong { color: var(--text); }
.cov-summary .bad strong { color: var(--warn); }

/* ---------- Side panel ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px; }
.panel h2 { font-family: var(--font-display); font-weight: 700; font-size: 21px; margin: 0 0 4px; }
.panel .lede { color: var(--muted); margin: 0 0 14px; font-size: 14px; }
.panel h3 { font-family: var(--font-display); font-weight: 600; font-size: 15.5px; margin: 18px 0 8px; display: flex; align-items: center; gap: 8px; }
.panel h3 small { font-family: var(--font-body); font-weight: 600; color: var(--muted); font-size: 12.5px; margin-left: auto; }
.mode-panel[hidden] { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--panel-2); border-radius: 999px; padding: 5px 12px; font-weight: 700; font-size: 13px; }
.chip[aria-pressed="true"] { background: var(--purple); border-color: var(--purple); color: #fff; }

.size-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 14px; font-weight: 700; }
.size-row select { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 5px 8px; }

.palette-group { margin-bottom: 10px; }
.palette-head { font-size: 12.5px; font-weight: 800; color: var(--muted); margin: 0 0 6px; display: flex; align-items: center; gap: 6px; }
.palette-head .dot { width: 8px; height: 8px; border-radius: 50%; }
.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 6px; }
.palette-wide { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.pal-btn { border: 2px solid transparent; background: var(--panel-2); border-radius: var(--radius); padding: 6px 2px 5px; display: grid; justify-items: center; gap: 2px; font-size: 11px; font-weight: 700; line-height: 1.15; text-align: center; position: relative; transition: transform .12s; }
.pal-btn:hover { transform: translateY(-2px); }
.pal-btn .emoji { font-size: 26px; }
.pal-btn[aria-pressed="true"] { border-color: var(--gold); background: rgba(227,169,59,.14); }
.pal-btn .sz { position: absolute; top: 3px; right: 4px; font-size: 9.5px; color: var(--muted); font-weight: 800; }
.seed-btn[aria-pressed="false"] { opacity: .45; filter: grayscale(.8); }
.seed-btn[aria-pressed="true"] { border-color: var(--teal); background: var(--teal-soft); }
.seed-btn[aria-pressed="true"]::after { content: '✓'; position: absolute; top: 2px; left: 5px; font-size: 11px; color: var(--teal); font-weight: 900; }

.goal-row { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); font-weight: 700; font-size: 14px; }
.goal-row:last-child { border-bottom: 0; }
.goal-row .emoji { font-size: 19px; }
.goal-row .seg button { padding: 4px 10px; font-size: 12.5px; }
.goal-row .seg button[aria-pressed="true"][data-w="2"] { background: var(--teal); color: #fff; }

.btn { border: 0; border-radius: var(--radius); padding: 11px 16px; font-family: var(--font-display); font-weight: 600; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: transform .12s, filter .12s; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--teal); color: #fff; width: 100%; }
.btn-purple { background: var(--purple); color: #fff; }
.btn-ghost { background: var(--panel-2); border: 1px solid var(--line); }
.btn-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }

.card { border: 1px solid var(--line); background: var(--panel-2); border-radius: var(--radius); padding: 12px; display: grid; grid-template-columns: 92px 1fr; gap: 12px; margin-bottom: 10px; cursor: pointer; text-align: left; width: 100%; transition: border-color .15s; }
.card:hover { border-color: var(--purple); }
.card[aria-current="true"] { border-color: var(--purple); box-shadow: 0 0 0 2px var(--purple-soft); }
.mini { display: grid; gap: 1px; background: var(--grass); border-radius: 8px; padding: 4px; align-self: start; aspect-ratio: 1; }
.mini span { font-family: var(--emoji); display: grid; place-items: center; background: var(--soil); border-radius: 2px; line-height: 1; overflow: hidden; }
.card h4 { font-family: var(--font-display); font-weight: 600; margin: 0; font-size: 16px; }
.tag { display: inline-block; font-size: 11.5px; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: var(--purple-soft); color: var(--text); margin: 3px 0 5px; }
.card p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.card .covs { font-size: 12px; margin-top: 5px; font-weight: 700; display: flex; gap: 8px; flex-wrap: wrap; }
.card .covs .emoji { font-size: 12px; }

.saved-item { display: grid; gap: 6px; padding: 7px 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 6px; font-size: 14px; font-weight: 700; }
.saved-main { display: flex; align-items: center; gap: 8px; min-width: 0; }
.saved-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-visibility { flex: 0 0 auto; padding: 2px 7px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; }
.saved-visibility.is-public { border-color: var(--teal); background: var(--teal-soft); color: var(--text); }
.saved-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 3px; }
.saved-item button { border: 0; background: none; padding: 3px 6px; border-radius: 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.saved-item button:hover { color: var(--text); background: var(--panel); }
.saved-item button:disabled { opacity: .5; cursor: wait; }
.saved-error button { border: 0; border-radius: 6px; background: var(--panel-2); color: var(--text); padding: 3px 7px; font-weight: 700; cursor: pointer; }
.text-input { width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 14px; }
.inline-form { display: flex; gap: 6px; }
.inline-form .text-input { flex: 1; min-width: 0; }
.inline-form .btn { padding: 8px 12px; font-size: 14px; }
details.rules { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; font-size: 13.5px; color: var(--muted); }
details.rules summary { cursor: pointer; font-family: var(--font-display); font-weight: 600; color: var(--text); font-size: 15px; }
details.rules ul { padding-left: 18px; margin: 8px 0 0; }
details.rules li { margin-bottom: 4px; }
.result-box { background: var(--teal-soft); border: 1px solid var(--teal); border-radius: var(--radius); padding: 12px; margin-top: 14px; font-size: 14px; }
.result-box[hidden] { display: none; }
.result-box .btn-row { flex-direction: column; }
.result-box strong { font-family: var(--font-display); font-weight: 600; font-size: 16px; }

.asset-img { width: 30px; height: 30px; object-fit: contain; display: block; }
.pal-btn .asset-img { width: 30px; height: 30px; }
.asset-inline { width: 1.25em; height: 1.25em; object-fit: contain; vertical-align: -0.28em; }
.crop2d .ce-img { width: calc(var(--cell) * var(--span) * .78); height: calc(var(--cell) * var(--span) * .78); object-fit: contain; filter: drop-shadow(0 2px 2px rgba(0,0,0,.3)); }
.crop2d.pop .ce-img { animation: pop .45s cubic-bezier(.3,1.6,.5,1); }
.mini .asset-inline { width: 90%; height: 90%; vertical-align: middle; }
.site-credit { max-width: 1320px; margin: 0 auto; padding: 0 20px 28px; color: var(--muted); font-size: 12.5px; text-align: center; }
@media (prefers-reduced-motion: reduce) {
  .particle, .crop2d.pop .ce, .crop2d.pop .ce-img, .gen-emoji { animation: none !important; }
  .particle { display: none; }
}
@media (max-width: 560px) {
  .top { padding: 14px 14px 8px; }
  .layout { padding: 6px 8px 24px; gap: 12px; }
  .brand h1 { font-size: 25px; }
  /* Never size this from the iframe viewport height. The parent iframe grows
     to our document height, so vh here caused a resize feedback loop and a
     several-thousand-pixel purple canvas on phones. */
  .viewport { height: clamp(340px, 88vw, 500px); min-height: 0; }
  .stage { border-radius: 14px; }
  .stage-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    padding: 10px;
  }
  .stage-bar .seg { grid-column: 1 / -1; width: 100%; }
  .stage-bar .seg button { flex: 1; min-height: 42px; font-size: 15px; }
  .stage-bar #toggleBonus { grid-column: 1 / -1; justify-content: center; min-height: 42px; }
  .stage-bar #undoBtn,
  .stage-bar #redoBtn { justify-content: center; min-height: 42px; }
  .grid2d-wrap { padding: 8px; }
  .grid2d { gap: 2px; padding: 7px; border-radius: 12px; }
  .coverage { grid-template-columns: 1fr; padding: 12px; }
  .panel { padding: 14px; border-radius: 14px; }
  .card { grid-template-columns: 72px 1fr; gap: 10px; padding: 10px; }
  .inline-form { flex-wrap: wrap; }
  .inline-form .text-input { flex-basis: 100%; }
  .stage-action { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; background: var(--purple-soft); border-bottom: 1px solid var(--line); font-size: 14px; }
.stage-action[hidden] { display: none; }
.stage-action b { font-family: var(--font-display); font-weight: 600; }
.stage-action .btn { padding: 7px 14px; font-size: 14.5px; }
.stage-hint { display: none; }
  .modes { width: 100%; flex-wrap: nowrap; border-radius: 16px; }
  .mode-btn { flex: 1; flex-direction: column; gap: 2px; padding: 7px 4px; font-size: 12.5px; border-radius: 12px; text-align: center; line-height: 1.15; }
  .mode-btn .emoji { font-size: 18px; }
}
