/* TKS Bina design system: near-black ground, gold accent, Rajdhani display, Inter body, DM Mono figures */
:root {
  --bg: #0a0a0a; --bg2: #121212; --bg3: #1a1a1a; --line: #2a2a2a; --line2: #3a3a3a;
  --ink: #ece9e2; --muted: #9a958a; --gold: #c9a84c; --gold2: #e0c374; --danger: #e06b5a;
  --f-disp: "Rajdhani", "Arial Narrow", system-ui, sans-serif;
  --f-body: "Inter", system-ui, -apple-system, sans-serif;
  --f-mono: "DM Mono", ui-monospace, Menlo, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--f-body); -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.screen { position: fixed; inset: 0; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
.brand { display: flex; align-items: center; gap: 10px; font: 700 22px/1 var(--f-disp); letter-spacing: .04em; text-transform: uppercase; }
.brand .mark { background: var(--gold); color: #0a0a0a; padding: 4px 7px 2px; border-radius: 3px; letter-spacing: .08em; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 6px; padding: 10px 16px; border: 1px solid var(--line2); background: var(--bg3); font-weight: 500; text-decoration: none; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #0a0a0a; font-weight: 600; }
.btn.gold:hover { background: var(--gold2); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 13px; }

/* PIN */
#pin { display: grid; place-items: center; }
.pin-card { display: grid; gap: 12px; width: min(320px, calc(100% - 32px)); }
.pin-card label { color: var(--muted); font-size: 13px; }
.pin-card input { background: var(--bg2); border: 1px solid var(--line2); border-radius: 6px; padding: 14px; font: 500 24px var(--f-mono); letter-spacing: .4em; text-align: center; }
.err { color: var(--danger); margin: 0; font-size: 13px; }

/* HOME */
#home { overflow-y: auto; }
.home-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 2; }
.home-body { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }
.new-row { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 760px) { .new-row { grid-template-columns: 1fr; } }
.new-card { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 18px; display: grid; gap: 14px; text-align: left; }
.new-card h2 { margin: 0; font: 600 22px var(--f-disp); letter-spacing: .02em; }
.new-card p { margin: 0; color: var(--muted); }
.new-card.sample { border-color: #4a3f22; background: linear-gradient(160deg, #17140b, var(--bg2)); align-content: start; }
.fields { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 10px; }
@media (max-width: 760px) { .fields { grid-template-columns: 1fr 1fr; } .fields label:first-child { grid-column: 1 / -1; } }
.fields label, .prop label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
input[type=text], input:not([type]), input[type=number], select, textarea { background: var(--bg); border: 1px solid var(--line2); border-radius: 6px; padding: 8px 10px; min-width: 0; width: 100%; }
input[type=number] { font-family: var(--f-mono); }
input[type=color] { width: 38px; height: 34px; padding: 2px; border: 1px solid var(--line2); border-radius: 6px; background: var(--bg); }
.sec { font: 600 15px var(--f-disp); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 32px 0 12px; }
.proj-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.proj { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: grid; }
.proj .thumb { aspect-ratio: 16/10; background: #111 center/cover no-repeat; border: 0; padding: 0; width: 100%; max-width: 100%; }
.proj .meta { padding: 10px 12px; display: grid; gap: 2px; }
.proj .meta b { font: 600 17px var(--f-disp); }
.proj .meta span { color: var(--muted); font: 12px var(--f-mono); }
.proj .acts { display: flex; gap: 6px; padding: 0 12px 12px; flex-wrap: wrap; }
.empty { color: var(--muted); padding: 30px; border: 1px dashed var(--line2); border-radius: 10px; text-align: center; }

/* EDITOR */
#editor { display: grid; grid-template-rows: auto 1fr; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--bg); min-width: 0; flex-wrap: wrap; }
.icon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 6px; border: 1px solid transparent; background: transparent; flex: none; }
.icon:hover { background: var(--bg3); }
.proj-name { flex: 1 1 140px; max-width: 280px; background: transparent !important; border: 1px solid transparent !important; font: 600 20px var(--f-disp) !important; letter-spacing: .02em; }
.proj-name:hover, .proj-name:focus { border-color: var(--line2) !important; }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 7px 14px; font: 600 15px var(--f-disp); letter-spacing: .06em; }
.seg button[aria-pressed=true] { background: var(--gold); color: #0a0a0a; }
.tb-right { display: flex; align-items: center; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.chip { border: 1px solid var(--line2); background: transparent; border-radius: 99px; padding: 5px 11px; font-size: 12.5px; }
.chip[aria-pressed=true] { border-color: var(--gold); color: var(--gold); }
.save { font: 12px var(--f-mono); color: var(--muted); min-width: 74px; text-align: right; }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: 40px; background: var(--bg2); border: 1px solid var(--line2); border-radius: 8px; padding: 6px; display: grid; min-width: 220px; z-index: 20; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.menu button { text-align: left; background: transparent; border: 0; padding: 9px 10px; border-radius: 5px; }
.menu button:hover { background: var(--bg3); }

.work { display: grid; grid-template-columns: 76px 1fr 320px; min-height: 0; }
.tools { display: flex; flex-direction: column; gap: 4px; padding: 8px 6px; border-right: 1px solid var(--line); background: var(--bg); overflow-y: auto; }
.tools button { display: grid; justify-items: center; gap: 3px; padding: 9px 2px; border-radius: 7px; border: 1px solid transparent; background: transparent; color: var(--muted); font-size: 11px; line-height: 1.15; text-align: center; }
.tools button svg { width: 22px; height: 22px; }
.tools button[aria-pressed=true] { color: var(--gold); border-color: #4a3f22; background: #17140b; }
#stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #1b1d1f; touch-action: none; }
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.hint { position: absolute; left: 12px; bottom: 12px; right: 12px; pointer-events: none; font: 12px var(--f-mono); color: #f2efe6; display: flex; }
.hint span { background: rgba(10,10,10,.72); padding: 5px 9px; border-radius: 5px; }
.walkpad { position: absolute; right: 16px; bottom: 46px; display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(2, 52px); gap: 6px; }
.walkpad button { border-radius: 10px; border: 1px solid var(--line2); background: rgba(10,10,10,.7); font-size: 18px; touch-action: none; }
.walkpad [data-mv=f] { grid-column: 2; } .walkpad [data-mv=l] { grid-column: 1; grid-row: 2; } .walkpad [data-mv=b] { grid-column: 2; grid-row: 2; } .walkpad [data-mv=r] { grid-column: 3; grid-row: 2; }
.zoompad { position: absolute; right: 14px; top: 14px; display: grid; gap: 6px; }
.zoompad button { width: 42px; height: 42px; border-radius: 8px; border: 1px solid var(--line2); background: rgba(10,10,10,.75); font-size: 22px; }

.panel { border-left: 1px solid var(--line); background: var(--bg); overflow-y: auto; padding: 14px; display: grid; align-content: start; gap: 14px; min-width: 0; }
.panel h3 { margin: 0; font: 600 20px var(--f-disp); letter-spacing: .02em; }
.panel h4 { margin: 4px 0 0; font: 600 13px var(--f-disp); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.panel p { margin: 0; color: var(--muted); font-size: 13px; }
.prop { display: grid; gap: 10px; }
.row { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.row > * { flex: 1 1 0; min-width: 0; }
.row > .fit { flex: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.dim { font: 12px var(--f-mono); color: var(--gold); }
.matrow { display: grid; grid-template-columns: 38px 1fr 110px; gap: 8px; align-items: center; }
.matrow span { font-size: 13px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatches button { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--bg); outline: 1px solid var(--line2); padding: 0; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--line2); background: transparent; border-radius: 99px; padding: 5px 10px; font-size: 12.5px; }
.tabs button[aria-pressed=true] { background: var(--gold); border-color: var(--gold); color: #0a0a0a; }
.lib { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lib button { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 6px; display: grid; gap: 4px; text-align: left; font-size: 12.5px; line-height: 1.25; }
.lib button:hover { border-color: var(--gold); }
.lib img { width: 100%; aspect-ratio: 4/3; object-fit: contain; background: #202224; border-radius: 5px; }
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.presets button { background: var(--bg2); border: 1px solid var(--line); border-radius: 7px; padding: 9px; text-align: left; font-size: 13px; }
.presets button[aria-pressed=true] { border-color: var(--gold); color: var(--gold); }
.drop { border: 1.5px dashed var(--line2); border-radius: 10px; padding: 18px; text-align: center; color: var(--muted); display: grid; gap: 8px; place-items: center; cursor: pointer; }
.drop img { max-width: 100%; max-height: 220px; border-radius: 6px; }
.ai-result { display: grid; gap: 8px; background: var(--bg2); border: 1px solid #4a3f22; border-radius: 10px; padding: 10px; }
.ai-result img { width: 100%; border-radius: 6px; background: #202224; }
.spin { width: 16px; height: 16px; border: 2px solid var(--line2); border-top-color: var(--gold); border-radius: 50%; animation: sp 0.9s linear infinite; display: inline-block; vertical-align: -3px; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 3s; } }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--bg2); border: 1px solid var(--gold); color: var(--ink); padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: calc(100% - 32px); }
.confirm { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* phones / portrait: panel becomes bottom sheet */
@media (max-width: 900px) {
  .work { grid-template-columns: 1fr; grid-template-rows: 1fr auto auto; }
  .tools { flex-direction: row; border-right: 0; border-top: 1px solid var(--line); order: 3; overflow-x: auto; padding: 4px; }
  .tools button { min-width: 64px; }
  #stage { order: 1; }
  .panel { order: 2; border-left: 0; border-top: 1px solid var(--line); max-height: 42vh; }
  .chip { padding: 4px 8px; }
  .save { min-width: 0; }
}
@media (max-width: 520px) {
  .save { display: none; }
  .proj-name { font-size: 17px !important; flex-basis: 100px; }
  .topbar { gap: 4px; }
  .seg button { padding: 6px 10px; }
  .panel { max-height: 38vh; }
  .hint { font-size: 11px; }
}

.cct .btn[aria-pressed=true] { border-color: var(--gold); color: var(--gold); }
.cct .btn i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; box-shadow: 0 0 0 1px #0008; }

.sync { font: 500 12px var(--f-mono); color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.sync:empty { display: none; }
.sync::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--line2); }
.sync[data-s=on]::before { background: #6fbf73; }
.sync[data-s=offline]::before, .sync[data-s=error]::before { background: var(--gold); }
.home-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }
