:root {
  --bg: #f4f3ef; --card: #ffffff; --text: #1d1d1b; --muted: #6b6a66; --line: #dddbd4;
  --accent: #1f4fd1; --accent-text: #ffffff; --danger: #b3261e; --ok: #1e7b34; --warn: #a15c00;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #161615; --card: #22221f; --text: #ecebe6; --muted: #a09f99; --line: #3a3a36; --accent: #6d8fff; --accent-text: #0d0d0c; --danger: #ff8a80; --ok: #7ed492; --warn: #ffb74d; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1rem; margin: 1rem 0 .5rem; }
button, select, input { font: inherit; color: inherit; }
button { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .8rem; cursor: pointer; }
button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: progress; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.link, a.link { background: none; border: none; color: var(--accent); padding: .45rem .3rem; text-decoration: underline; cursor: pointer; }
input[type=number], input[type=password], select { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: .35rem .5rem; }
input[type=number] { width: 6rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); min-height: 1.2em; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; }

.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login form { width: min(360px, 100%); display: grid; gap: 1rem; }
.login label { display: grid; gap: .3rem; }

header { display: flex; align-items: center; gap: 1rem; padding: .8rem 1.2rem; border-bottom: 1px solid var(--line); background: var(--card); flex-wrap: wrap; }
header .badge { margin-left: auto; }
.badge { font-size: .85rem; padding: .25rem .6rem; border-radius: 999px; border: 1px solid var(--line); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.warn { color: var(--warn); border-color: var(--warn); }

main { display: grid; grid-template-columns: 320px 1fr; gap: 1.2rem; padding: 1.2rem; max-width: 1500px; margin: 0 auto; }
@media (max-width: 900px) { main { grid-template-columns: 1fr; padding: 16px; } }

.drop { display: grid; gap: .4rem; text-align: center; padding: 1.4rem 1rem; border: 2px dashed var(--line); border-radius: 12px; cursor: pointer; background: var(--card); }
.drop.over { border-color: var(--accent); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .6rem; }
.thumb { position: relative; border: 2px solid transparent; border-radius: 8px; overflow: hidden; background: var(--card); padding: 0; aspect-ratio: 16 / 10; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.sel { border-color: var(--accent); }
.thumb .tag { position: absolute; left: 4px; bottom: 4px; font-size: .7rem; background: rgba(0,0,0,.65); color: #fff; padding: 1px 5px; border-radius: 4px; }
.thumb .tag.live { background: var(--ok); }

.editor-head { display: flex; align-items: baseline; gap: .8rem; flex-wrap: wrap; }
.editor-head h2 { margin: 0 0 .5rem; overflow-wrap: anywhere; }
.stage { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #888; border-radius: 6px; overflow: hidden; cursor: grab; touch-action: none; outline-offset: 3px; }
.stage:active { cursor: grabbing; }
.stage canvas { width: 100%; height: 100%; display: block; }
.controls, .actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin: .8rem 0; }
.controls label { display: flex; gap: .4rem; align-items: center; }
#zoom { width: 180px; }
.check { display: flex; gap: .4rem; align-items: center; }

.status { margin-top: 1.2rem; }
.status h2 { margin-top: 0; }
.request { padding: .8rem; border-radius: 8px; border: 1px solid var(--line); margin-bottom: .8rem; }
.request.ok { border-color: var(--ok); }
.request.warn { border-color: var(--warn); }
.request.err { border-color: var(--danger); }
.request strong { display: block; margin-bottom: .2rem; }
dl { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: 0; font-size: .9rem; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }
details { margin-top: .8rem; }
summary { cursor: pointer; font-weight: 600; }
.settings { display: grid; gap: .6rem; margin-top: .6rem; }
.history { font-size: .85rem; padding-left: 1.2rem; max-height: 260px; overflow: auto; }
code { background: var(--bg); padding: .1rem .3rem; border-radius: 4px; overflow-wrap: anywhere; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .7rem 1rem; border-radius: 8px; max-width: calc(100% - 32px); }
.toast.err { background: var(--danger); color: #fff; }
