:root {
  --bg: #1b120a; --bg2: #26180d; --panel: #f1e1bb; --panel2: #e6d0a0; --ink: #2a1a0a; --ink2: #6d3b12;
  --gold: #f1c768; --red: #b3201a; --line: #5a3a14; --muted: #b89c66; --ok: #3d7a3a;
  --f-title: 'Cinzel', Georgia, serif; --f-type: 'Special Elite', 'Courier New', monospace; --f-body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: #f3e6c6; font-family: var(--f-body); }
body { min-height: 100vh; background: radial-gradient(1200px 600px at 50% -10%, #3a2412 0%, var(--bg) 60%); }
a { color: var(--gold); }
button, input, select, textarea { font: inherit; }
h1, h2, h3 { font-family: var(--f-title); letter-spacing: .04em; margin: 0; }

#top { display: flex; align-items: center; justify-content: space-between; padding: 8px 20px; border-bottom: 1px solid #3a2412; background: rgba(20, 12, 5, .85); position: sticky; top: 0; z-index: 50; backdrop-filter: blur(6px); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #f3e6c6; font-family: var(--f-title); font-size: 22px; letter-spacing: .06em; }
.brand b { color: var(--gold); }
#nav { display: flex; gap: 8px; align-items: center; }
#app { padding: 18px 20px 60px; max-width: 1700px; margin: 0 auto; }

.btn { background: #3a2412; color: #f3e6c6; border: 1px solid var(--line); padding: 8px 14px; border-radius: 6px; cursor: pointer; font-size: 14px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: #4b2f18; }
.btn.primary { background: var(--red); border-color: #7a120e; color: #fff; font-weight: 600; }
.btn.primary:hover { background: #cc2a22; }
.btn.gold { background: var(--gold); color: var(--ink); border-color: #a5651a; font-weight: 600; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; background: #3a2412; border: 1px solid var(--line); font-size: 12px; color: var(--muted); }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); background: #f1e1bb; color: var(--ink); padding: 10px 18px; border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: .25s; z-index: 200; max-width: 90vw; font-family: var(--f-type); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------ home */
.hero { text-align: center; padding: 40px 10px 26px; }
.hero h1 { font-size: clamp(30px, 5vw, 56px); color: var(--gold); text-shadow: 0 3px 0 #2a1200, 0 0 30px rgba(241, 199, 104, .25); }
.hero p { max-width: 720px; margin: 14px auto 22px; color: #e8d4a6; font-size: 18px; line-height: 1.5; }
.hero .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin: 26px 0 34px; }
.features div { background: rgba(241, 225, 187, .06); border: 1px solid #3a2412; border-radius: 10px; padding: 14px; font-size: 14px; color: #d8c498; }
.features b { display: block; font-family: var(--f-title); color: var(--gold); margin-bottom: 4px; font-size: 15px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
.card { background: var(--panel); color: var(--ink); border-radius: 8px; overflow: hidden; text-decoration: none; box-shadow: 0 8px 24px rgba(0,0,0,.45); transition: transform .2s; display: block; position: relative; }
.card:hover { transform: translateY(-4px) rotate(-.4deg); }
.card .cover { aspect-ratio: 16/9; background: #3a2412 center/cover; display: flex; align-items: flex-end; }
.card .cover.empty { background: linear-gradient(135deg, #5a3a14, #2a1a0a); align-items: center; justify-content: center; font-size: 48px; }
.card .body { padding: 12px 14px 14px; }
.card h3 { font-size: 18px; }
.card p { margin: 4px 0 0; font-size: 13px; color: var(--ink2); font-family: var(--f-type); }
.card .del { position: absolute; top: 8px; right: 8px; }

/* ------------------------------------------------ dialogs / forms */
dialog { background: var(--panel); color: var(--ink); border: 2px solid var(--line); border-radius: 10px; padding: 20px 22px; max-width: min(640px, 94vw); width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.7); }
dialog::backdrop { background: rgba(10, 5, 0, .7); }
dialog h2 { font-size: 20px; margin-bottom: 10px; color: var(--ink); }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
dialog p.hint { font-size: 13px; color: var(--ink2); margin: 4px 0 8px; }
label.f { display: block; font-family: var(--f-type); font-size: 13px; color: var(--ink2); margin: 10px 0 3px; }
.dark label.f, .ed-main label.f { color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 6px; border: 1px solid #a88a52; background: #fbf3de; color: var(--ink); }
.ed-main input[type=text], .ed-main input[type=number], .ed-main input[type=date], .ed-main select, .ed-main textarea, .ed-right select { background: #2c1b0d; color: #f3e6c6; border-color: #5a3a14; }
textarea { resize: vertical; min-height: 70px; line-height: 1.45; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--gold); outline-offset: 0; }
input[type=range] { accent-color: var(--red); }

/* ------------------------------------------------ viewer */
.viewer { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 18px; align-items: start; }
.vhead { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap; align-items: end; }
.vhead h1 { font-size: clamp(22px, 3vw, 34px); color: var(--gold); }
.vhead p { margin: 4px 0 0; color: #d8c498; font-family: var(--f-type); }
.vhead .acts { display: flex; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { background: #26180d; color: #e8d4a6; border: 0; padding: 8px 14px; cursor: pointer; }
.seg button.on { background: var(--gold); color: var(--ink); font-weight: 700; }
.screen { position: relative; background: #000; border: 3px solid #5a3a14; border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,.7); aspect-ratio: 16/9; overflow: hidden; }
.screen canvas { width: 100%; height: 100%; display: block; }
.bigplay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.25); cursor: pointer; border: 0; color: #fff; }
.bigplay span { width: 96px; height: 96px; border-radius: 50%; background: rgba(179, 32, 26, .92); display: flex; align-items: center; justify-content: center; font-size: 40px; padding-left: 8px; box-shadow: 0 0 0 6px rgba(241, 225, 187, .25); transition: transform .2s; }
.bigplay:hover span { transform: scale(1.08); }
.screen .loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: #140b04; font-family: var(--f-type); color: var(--gold); font-size: 20px; }
.controls { display: flex; align-items: center; gap: 8px; padding: 8px 4px; flex-wrap: wrap; }
.viewer > *, .editor > * { min-width: 0; }
.controls .ib { background: #26180d; border: 1px solid var(--line); color: #f3e6c6; width: 38px; height: 34px; border-radius: 6px; cursor: pointer; font-size: 16px; }
.controls .ib:hover { background: #4b2f18; }
.controls .ib.on { background: var(--gold); color: var(--ink); }
.controls .time { font-family: var(--f-type); font-size: 14px; color: #e8d4a6; min-width: 92px; text-align: center; }
.scrub { position: relative; flex: 1; min-width: 140px; height: 34px; display: flex; align-items: center; }
.scrub input { width: 100%; margin: 0; position: relative; z-index: 2; background: transparent; }
.scrub .ticks { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.scrub .ticks i { position: absolute; top: 9px; width: 2px; height: 16px; background: rgba(241, 199, 104, .55); }
.cc { min-height: 48px; padding: 8px 14px; text-align: center; font-family: var(--f-story, 'IM Fell English'), Georgia, serif; font-style: italic; font-size: 18px; color: #f3e6c6; }
.chapters { display: flex; gap: 8px; overflow-x: auto; padding: 6px 2px 10px; scrollbar-width: thin; }
.chapters button { flex: 0 0 auto; background: #26180d; color: #e8d4a6; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 13px; }
.chapters button.on { background: var(--gold); color: var(--ink); font-weight: 700; }
.side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.panel { background: rgba(241, 225, 187, .07); border: 1px solid #3a2412; border-radius: 10px; padding: 12px; }
.panel h3 { font-size: 15px; color: var(--gold); margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
#map, .mini-map { height: 320px; border-radius: 8px; border: 2px solid #5a3a14; background: #d8c090; }
.nowbar { font-family: var(--f-type); font-size: 14px; color: #f3e6c6; margin-top: 8px; min-height: 40px; }
.nowbar a { font-size: 13px; }
.leaflet-container { font-family: var(--f-body); }
.leaflet-popup-content-wrapper { background: var(--panel); color: var(--ink); border-radius: 8px; }
.leaflet-popup-content img { width: 200px; border-radius: 4px; display: block; margin-bottom: 4px; }
.mk { display: flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--red); color: #fff; font: 700 12px var(--f-title); border: 2px solid #f1e1bb; box-shadow: 0 2px 6px rgba(0,0,0,.5); }
.here { font-size: 26px; filter: drop-shadow(0 2px 3px rgba(0,0,0,.6)); text-align: center; line-height: 30px; }
.comments .list { max-height: 360px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.cm { background: var(--panel); color: var(--ink); border-radius: 6px; padding: 8px 10px; font-size: 14px; line-height: 1.4; }
.cm b { font-family: var(--f-title); }
.cm small { color: var(--ink2); font-family: var(--f-type); }
.cm .about { cursor: pointer; text-decoration: underline; color: var(--red); }
.cm p { margin: 3px 0 0; white-space: pre-wrap; word-break: break-word; }
.comments form { display: flex; flex-direction: column; gap: 6px; }
.comments form label { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.empty { color: var(--muted); font-family: var(--f-type); font-size: 13px; }

/* ------------------------------------------------ editor */
.editor { display: grid; grid-template-columns: 290px minmax(0, 1fr) 460px; gap: 16px; align-items: start; }
.ed-bar { grid-column: 1 / -1; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.ed-bar h1 { font-size: 22px; color: var(--gold); flex: 1; min-width: 200px; }
.save { font-family: var(--f-type); font-size: 13px; color: var(--muted); }
.save.ok { color: #8fd18a; } .save.err { color: #ff8a80; }
.ed-left, .ed-right { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow-y: auto; scrollbar-width: thin; }
.stoplist { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.si { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; background: #2c1b0d; border: 1px solid #4a2f17; border-radius: 8px; padding: 7px 8px; cursor: pointer; }
.si.on { border-color: var(--gold); background: #3a2412; }
.si.drag { opacity: .4; }
.si .n { width: 26px; height: 26px; border-radius: 50%; background: var(--red); display: flex; align-items: center; justify-content: center; font: 700 12px var(--f-title); }
.si .t { font-size: 14px; line-height: 1.2; overflow: hidden; }
.si .t small { display: block; color: var(--muted); font-family: var(--f-type); font-size: 11px; }
.si .m { display: flex; gap: 2px; }
.si .m button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 4px; font-size: 13px; }
.si .m button:hover { color: var(--gold); }
.ed-main .panel h3 { font-size: 17px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; }
.modes { display: flex; gap: 6px; flex-wrap: wrap; }
.modes button { background: #2c1b0d; border: 1px solid #5a3a14; color: #f3e6c6; border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 14px; }
.modes button.on { background: var(--gold); color: var(--ink); border-color: #a5651a; font-weight: 700; }
.mediagrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-top: 10px; }
.mc { background: #2c1b0d; border: 1px solid #4a2f17; border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; }
.mc.hidden { opacity: .45; }
.mc .th { aspect-ratio: 4/3; background: #000 center/cover; position: relative; }
.mc .th .b { position: absolute; left: 4px; bottom: 4px; display: flex; gap: 3px; flex-wrap: wrap; }
.mc .th .b span { background: rgba(0,0,0,.7); border-radius: 4px; padding: 1px 5px; font-size: 10px; color: #f3e6c6; }
.mc .th .b span.warn { color: #ffb86b; }
.mc .th .star { position: absolute; right: 4px; top: 4px; background: rgba(0,0,0,.6); border: 0; border-radius: 50%; width: 26px; height: 26px; cursor: pointer; font-size: 14px; color: #888; }
.mc .th .star.on { color: var(--gold); }
.mc .bd { padding: 6px; display: flex; flex-direction: column; gap: 5px; }
.mc input[type=text] { padding: 4px 6px; font-size: 12px; }
.mc .tools { display: flex; justify-content: space-between; }
.mc .tools button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 4px; }
.mc .tools button:hover { color: var(--gold); }
.drop { border: 2px dashed #5a3a14; border-radius: 10px; padding: 16px; text-align: center; color: var(--muted); font-family: var(--f-type); margin-top: 10px; }
.drop.over { border-color: var(--gold); background: rgba(241, 199, 104, .08); }
.prog { height: 6px; border-radius: 3px; background: #3a2412; overflow: hidden; margin: 6px 0; }
.prog i { display: block; height: 100%; background: var(--gold); width: 0; transition: width .2s; }
.nearby { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.help { font-size: 12px; color: var(--muted); margin: 4px 0 0; line-height: 1.4; }
.ed-right .screen { border-width: 2px; }
.ed-right .controls { flex-wrap: wrap; }
.ed-right .rowb { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.overlay-full { position: fixed; inset: 0; background: rgba(10, 5, 0, .88); z-index: 100; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 14px; text-align: center; padding: 20px; }
.overlay-full .box { background: var(--panel); color: var(--ink); border-radius: 12px; padding: 22px 26px; width: min(520px, 94vw); }
.overlay-full canvas { max-width: 420px; width: 100%; border: 2px solid #5a3a14; }
.tag { font-family: var(--f-type); font-size: 12px; padding: 1px 7px; border-radius: 4px; background: #3a2412; color: var(--muted); }

@media (max-width: 1250px) {
  .editor { grid-template-columns: 270px minmax(0, 1fr); }
  .ed-right { grid-column: 1 / -1; position: static; max-height: none; }
}
@media (max-width: 1000px) {
  .viewer { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  #app { padding: 12px 12px 50px; }
  .editor { grid-template-columns: 1fr; }
  .ed-left, .ed-right { position: static; max-height: none; }
  .row2, .row3 { grid-template-columns: 1fr; }
  .controls .time { min-width: 70px; font-size: 12px; }
}

.pp:fullscreen { display: flex; flex-direction: column; background: #000; justify-content: center; }
.pp:fullscreen .screen { aspect-ratio: auto; flex: 1; border: 0; border-radius: 0; min-height: 0; }
.pp:fullscreen canvas { object-fit: contain; }
