:root {
  --bg: #0b0d12;
  --panel: #12151d;
  --panel-2: #191d28;
  --line: #262b3a;
  --text: #e8eaf0;
  --muted: #8a91a6;
  --accent: #f2c14e;
  --accent-2: #8b5cf6;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }

#app { display: grid; grid-template-columns: 1fr 360px; height: 100vh; }

#stage { position: relative; overflow: hidden; }

#scene { display: block; width: 100%; height: 100%; outline: none; touch-action: none; }

.stage-top {
  position: absolute; inset: 0 0 auto 0; display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; pointer-events: none;
}
.stage-top > * { pointer-events: auto; }
.brand { font-family: Cinzel, serif; font-weight: 800; letter-spacing: .08em; font-size: 20px; text-shadow: 0 2px 12px #000a; }
.brand span { color: var(--accent); }
.brand a { color: var(--muted); font: 600 12px Inter, sans-serif; letter-spacing: .04em; margin-left: 14px; text-decoration: none; border: 1px solid #ffffff22; padding: 5px 10px; border-radius: 999px; background: #0008; }
.brand a:hover { color: var(--text); border-color: var(--accent); }
.caption { position: absolute; left: 20px; bottom: 18px; max-width: 60%; pointer-events: none; text-shadow: 0 2px 10px #000; }
.caption b { display: block; font-family: Cinzel, serif; font-size: 22px; letter-spacing: .06em; }
.caption small { color: var(--muted); font-size: 12px; }
.swatch .era { font-size: 10px; opacity: .7; }
.stage-actions { display: flex; gap: 8px; }
.stage-actions button {
  background: #0008; border: 1px solid #ffffff22; padding: 8px 14px; border-radius: 999px; cursor: pointer;
  backdrop-filter: blur(6px); transition: background .15s, border-color .15s;
}
.stage-actions button:hover { background: #000b; border-color: var(--accent); }

.toss-result {
  position: absolute; left: 50%; bottom: 40px; transform: translateX(-50%);
  background: #000a; border: 1px solid var(--accent); color: var(--accent); padding: 10px 22px; border-radius: 999px;
  font-family: Cinzel, serif; font-weight: 800; letter-spacing: .1em; animation: pop .3s ease-out;
}
@keyframes pop { from { transform: translateX(-50%) scale(.6); opacity: 0; } }

.loader {
  position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 14px; letter-spacing: .1em;
  pointer-events: none; transition: opacity .4s;
}
.loader.hidden { opacity: 0; }

#panel { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; }
.tabs { display: flex; position: sticky; top: 0; z-index: 2; background: var(--panel); border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; padding: 14px 4px; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  cursor: pointer; font-size: 13px; font-weight: 600;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-page { display: none; padding: 8px 18px 28px; }
.tab-page.active { display: block; }
.tab-page h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); margin: 22px 0 10px; }

.row { display: flex; flex-direction: column; gap: 6px; font-size: 13px; margin-bottom: 12px; }
.row.check { flex-direction: row; align-items: center; gap: 8px; cursor: pointer; }
.row.two { flex-direction: row; gap: 10px; }
.row.two label { flex: 1; display: flex; flex-direction: column; gap: 6px; }

input[type="text"], input[type="number"], select, textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; outline: none;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
input[type="color"] { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); padding: 2px; }

.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.swatch {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 4px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line); cursor: pointer; font-size: 11px; color: var(--muted);
}
.swatch i { width: 30px; height: 30px; border-radius: 50%; box-shadow: inset 0 -4px 8px #0006, inset 0 3px 6px #fff6; }
.swatch.active { border-color: var(--accent); color: var(--text); }
.swatches.bg .swatch i { border-radius: 8px; }

.buttons { display: flex; flex-wrap: wrap; gap: 8px; }
button.primary, button.small, .buttons button, .file-btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; cursor: pointer; font-size: 13px;
  transition: border-color .15s, background .15s;
}
button.primary { background: linear-gradient(180deg, #f6d27a, #c9952b); color: #1a1205; border: 0; font-weight: 700; }
button.primary:hover { filter: brightness(1.08); }
.buttons button:not(.primary):hover, .file-btn:hover, button.small:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: progress; }
.file-btn { display: inline-flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.file-btn.wide { display: flex; width: 100%; margin-bottom: 12px; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
button.small { padding: 6px 10px; font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; min-height: 1em; }

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 55vh 1fr; }
  #panel { border-left: 0; border-top: 1px solid var(--line); }
  .stage-actions button { padding: 6px 10px; font-size: 12px; }
}
.swatches.two-col { grid-template-columns: repeat(2, 1fr); }

/* ---------- Живая монета ---------- */
body.live #panel { display: none; }
body.live #btnRandom { display: none; }
body.embed #app { grid-template-columns: 1fr; }
body.embed #liveCard, body.embed .stage-top, body.embed .caption { display: none; }
.live-card { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 22px 20px; display: flex; flex-direction: column; gap: 10px; }
.live-card h2 { font-family: Cinzel, serif; margin: 4px 0 0; font-size: 22px; letter-spacing: .04em; }
.live-card .hint { margin: 0; }
.live-status { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.live-status::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.live-status.live { color: #4ade80; }
.live-status.live::before { box-shadow: 0 0 0 0 #4ade80; animation: pulse 1.6s infinite; }
.live-status.sleep { color: #a5b4fc; }
.live-status.free { color: var(--accent); }
.live-status.bad { color: #f87171; }
@keyframes pulse { 70% { box-shadow: 0 0 0 10px #4ade8000; } 100% { box-shadow: 0 0 0 0 #4ade8000; } }
.live-code { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.live-code small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .14em; }
.live-code b { font: 800 28px/1.1 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .08em; color: var(--accent); }
.live-chronicle { font-family: Cinzel, serif; font-size: 15px; margin: 0; }
.live-qr { width: 150px; background: #fff; border-radius: 10px; }
.live-qr:empty { display: none; }
.live-qr svg { display: block; width: 100%; height: auto; }
.buttons.col { flex-direction: column; }
a.btn { display: block; text-align: center; text-decoration: none; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font-size: 13px; font-weight: 600; }
a.btn.primary { background: var(--accent); color: #1a1405; border-color: var(--accent); }
.live-badge { position: absolute; right: 16px; bottom: 16px; display: flex; gap: 10px; align-items: center; background: #000a; border: 1px solid #ffffff22; border-radius: 999px; padding: 7px 14px; backdrop-filter: blur(6px); }
.live-badge b { font: 800 14px ui-monospace, Menlo, monospace; color: var(--accent); letter-spacing: .06em; }
body:not(.embed) .live-badge { display: none; }
@media (max-width: 860px) { body.live:not(.embed) #app { grid-template-columns: 1fr; grid-template-rows: 60vh auto; height: auto; } }
