:root { --star-off: #8884; --star-on: #f5b301; }
[data-theme="blue"]      { --bg:#0b1b3a; --card:#13294f; --text:#eaf1ff; --muted:#9db4dd; --accent:#3b82f6; --accent-text:#fff; --border:#24406f; }
[data-theme="green"]     { --bg:#0b2a1a; --card:#12392a; --text:#e8fff1; --muted:#9dcfb2; --accent:#22c55e; --accent-text:#052e14; --border:#1f5a3f; }
[data-theme="lightgrey"] { --bg:#e5e7eb; --card:#f9fafb; --text:#1f2937; --muted:#6b7280; --accent:#4b5563; --accent-text:#fff; --border:#cfd3d9; --star-off:#0002; }
[data-theme="coal"]      { --bg:#1b1c1f; --card:#26282c; --text:#e6e7ea; --muted:#9a9da4; --accent:#8b93a1; --accent-text:#111; --border:#3a3d43; }

* { box-sizing: border-box; }
body { margin:0; background:var(--bg); color:var(--text); font:16px system-ui, sans-serif; transition: background .3s; }
header { display:flex; flex-wrap:wrap; gap:.5rem; align-items:center; padding:.75rem 1rem; background:var(--card); border-bottom:1px solid var(--border); position:sticky; top:0; z-index:5; }
header h1 { margin:0; font-size:1.25rem; flex:1 1 auto; }
input, select, textarea, button { font:inherit; color:var(--text); background:var(--bg); border:1px solid var(--border); border-radius:8px; padding:.5rem .7rem; }
button { cursor:pointer; }
button.primary { background:var(--accent); color:var(--accent-text); border-color:transparent; font-weight:600; }
button.danger { background:#b91c1c; color:#fff; border-color:transparent; }
button.ghost { background:transparent; }
main { padding:1rem; max-width:1200px; margin:auto; }
#grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(250px,1fr)); gap:1rem; }
.card { background:var(--card); border:1px solid var(--border); border-radius:12px; overflow:hidden; display:flex; flex-direction:column; }
.poster { aspect-ratio:2/3; background:var(--bg) center/cover; display:grid; place-items:center; font-size:3rem; color:var(--muted); }
.card .body { padding:.8rem; display:flex; flex-direction:column; gap:.4rem; }
.card h3 { margin:0; font-size:1.05rem; }
.meta { color:var(--muted); font-size:.85rem; display:flex; gap:.5rem; flex-wrap:wrap; align-items:center; }
.badge { border:1px solid var(--muted); border-radius:4px; padding:0 .3rem; font-size:.75rem; }
.cat { display:flex; justify-content:space-between; align-items:center; font-size:.85rem; }
.overall { font-weight:700; }
.review { color:var(--muted); font-size:.85rem; white-space:pre-wrap; }
a { color:var(--accent); }
.stars { position:relative; display:inline-block; font-size:1.1rem; letter-spacing:2px; line-height:1; color:var(--star-off); }
.stars::before { content:"★★★★★"; }
.stars > i { position:absolute; inset:0 auto 0 0; overflow:hidden; white-space:nowrap; color:var(--star-on); }
.stars > i::before { content:"★★★★★"; }
.stars.lg { font-size:1.4rem; }

dialog { background:var(--card); color:var(--text); border:1px solid var(--border); border-radius:14px; padding:1.2rem; width:min(92vw,420px); }
dialog::backdrop { background:#0008; }
dialog form, dialog h3 { margin-top:.6rem; }
dialog input { width:100%; margin:.3rem 0; }
.row { display:flex; justify-content:space-between; gap:.5rem; margin-top:.8rem; }
.err { color:#f87171; min-height:1.2em; margin:.3rem 0; }
.muted { color:var(--muted); font-size:.9rem; }
#swatches { display:flex; gap:.5rem; flex-wrap:wrap; }
#swatches button { border-left:1.4rem solid var(--c); }
#swatches button.on { outline:2px solid var(--accent); }

#panel { position:fixed; top:0; right:0; bottom:0; width:min(100vw,440px); background:var(--card); border-left:1px solid var(--border); padding:1rem; overflow-y:auto; z-index:10; box-shadow:-8px 0 24px #0006; }
.panelHead { display:flex; justify-content:space-between; align-items:center; }
#list { list-style:none; padding:0; margin:.8rem 0; display:flex; flex-direction:column; gap:.3rem; max-height:30vh; overflow:auto; }
#list li { padding:.45rem .6rem; border:1px solid var(--border); border-radius:8px; cursor:pointer; }
#list li.on { border-color:var(--accent); background:var(--bg); }
#form label { display:block; margin:.5rem 0; color:var(--muted); font-size:.85rem; }
#form input:not([type=file]), #form select, #form textarea { width:100%; margin-top:.2rem; }
.two { display:grid; grid-template-columns:1fr 1fr; gap:.5rem; }
.starRow { display:flex; justify-content:space-between; align-items:center; margin:.5rem 0; }
.starInput { display:flex; align-items:center; gap:.4rem; }
.starInput .stars { font-size:1.9rem; cursor:pointer; touch-action:none; }
.starInput output { min-width:2.2em; text-align:right; }
#preview { max-width:100px; border-radius:8px; margin:.3rem 0; }

/* ---- Rotten Tomatoes-style layout ---- */
header { background:#0a0a0a; border-bottom:3px solid var(--accent); padding:.6rem 1.2rem; }
header h1 { font-family:Impact, 'Arial Narrow Bold', sans-serif; letter-spacing:.04em; font-size:1.6rem; font-weight:400; color:#fff; }
header h1 b { color:var(--accent); font-weight:400; }
.logo { color:#fa320a; }
header input, header select, header button { background:#222; color:#fff; border-color:#444; border-radius:20px; }
header input[type=search] { min-width:200px; }
main { max-width:1300px; }
#grid { grid-template-columns:repeat(auto-fill,minmax(200px,1fr)); gap:1.2rem; }
.card { border-radius:6px; border:1px solid var(--border); box-shadow:0 1px 4px #0004; transition:transform .15s; }
.card:hover { transform:translateY(-3px); }
.poster { aspect-ratio:2/3; }
.meters { display:grid; grid-template-columns:repeat(3,1fr); gap:.3rem; padding:.5rem 0; border-bottom:1px solid var(--border); }
.meter { display:flex; flex-direction:column; align-items:center; gap:1px; text-align:center; }
.meter .ico { font-size:1.6rem; line-height:1; height:1.8rem; }
.meter .ico svg { width:1.8rem; height:1.8rem; }
.meter .val { font-size:1.15rem; font-weight:800; }
.meter .lbl { font-size:.65rem; text-transform:uppercase; letter-spacing:.05em; color:var(--muted); }
.meter .bar { width:90%; height:4px; background:var(--star-off); border-radius:2px; overflow:hidden; }
.meter .bar i { display:block; height:100%; }
.meter.shadow { color:#8b5cf6; } .meter.shadow .bar i { background:#8b5cf6; }
.meter.kids .bar i { background:linear-gradient(90deg,#ef4444,#f97316,#facc15,#22c55e,#3b82f6); }
.meter.kids .val, .meter.shadow .val { color:var(--text); }
.meter.score .val { color:#f5b301; }
.cat { font-size:.78rem; }
.card h3 { font-size:1rem; }
.pctRow { margin:.6rem 0; color:var(--muted); font-size:.85rem; display:grid; grid-template-columns:1fr auto; gap:.2rem .5rem; }
.pctRow input { grid-column:1; padding:0; border:0; background:none; width:100%; }
.pctRow output { color:var(--text); font-weight:700; }

.meters.emo { grid-template-columns:repeat(5,1fr); padding-top:.3rem; }
.meter.emo .ico { font-size:1.3rem; height:1.5rem; }
.meter.emo .val { font-size:.8rem; }
.meter.emo .lbl { font-size:.5rem; letter-spacing:0; }
.meter.emo .bar i { background:var(--accent); }

.ratings { border-top:1px solid var(--border); padding-top:.4rem; }
.ratings summary { cursor:pointer; display:flex; justify-content:space-between; align-items:center; font-size:.8rem; font-weight:700; text-transform:uppercase; letter-spacing:.04em; color:var(--muted); list-style:none; }
.ratings summary::-webkit-details-marker { display:none; }
.ratings summary::before { content:"▸"; margin-right:.4rem; transition:transform .15s; display:inline-block; }
.ratings[open] summary::before { transform:rotate(90deg); }
.ratings summary .avg { margin-left:auto; }
.ratings .cat { margin-top:.35rem; }

#layout { display:grid; grid-template-columns:minmax(0,1fr) 300px; gap:1.2rem; align-items:start; }
#recent { position:sticky; top:4.5rem; background:var(--card); border:1px solid var(--border); border-radius:8px; padding:.8rem; }
#recent h2 { margin:0 0 .6rem; font-size:.9rem; text-transform:uppercase; letter-spacing:.06em; color:var(--muted); border-bottom:2px solid var(--accent); padding-bottom:.4rem; }
#recentList { list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:.5rem; }
#recentList li { display:flex; align-items:center; gap:.6rem; }
#recentList .thumb { width:38px; aspect-ratio:2/3; flex:none; border-radius:4px; background:var(--bg) center/cover; display:grid; place-items:center; font-size:1rem; }
#recentList .info { display:flex; flex-direction:column; min-width:0; flex:1; }
#recentList strong { font-size:.88rem; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
#recentList .info span { font-size:.72rem; color:var(--muted); }
#recentList .pct { font-size:.8rem; font-weight:700; color:#f5b301; white-space:nowrap; }
@media (max-width:900px) { #layout { grid-template-columns:1fr; } #recent { position:static; order:-1; } }

/* ---- Mobile tidy-up ---- */
@media (max-width:700px) {
  header { gap:.4rem; padding:.5rem .7rem; }
  header h1 { flex:1 1 100%; font-size:1.3rem; }
  header input[type=search] { flex:1 1 100%; min-width:0; order:3; }
  header select { flex:1 1 0; min-width:0; order:4; padding:.4rem .5rem; font-size:.85rem; }
  header #editBtn, header #settingsBtn { order:2; }
  header h1 { order:1; flex:1 1 auto; }
  main { padding:.6rem; }
  #grid { grid-template-columns:repeat(2,minmax(0,1fr)); gap:.6rem; }
  .card .body { padding:.5rem; gap:.3rem; }
  .card h3 { font-size:.9rem; }
  .meta { font-size:.72rem; gap:.3rem; }
  .meters { gap:.15rem; }
  .meter .ico { font-size:1.3rem; height:1.4rem; }
  .meter .ico svg { width:1.4rem; height:1.4rem; }
  .meter .val { font-size:.9rem; }
  .meter .lbl { font-size:.55rem; }
  .meters.emo { grid-template-columns:repeat(5,1fr); }
  .meter.emo .ico { font-size:1.2rem; height:1.4rem; }
  .meter.emo .val { font-size:.7rem; }
  .meter.emo .lbl { display:none; }
  .ratings summary { font-size:.7rem; }
  .ratings .cat { font-size:.7rem; }
  .stars { font-size:.9rem; letter-spacing:1px; }
  .review { font-size:.78rem; }
  #recent { padding:.6rem; }
  #recentList { flex-direction:row; overflow-x:auto; gap:.8rem; padding-bottom:.3rem; }
  #recentList li { flex:0 0 220px; }
  .starInput .stars { font-size:2.3rem; }
  .starRow { flex-wrap:wrap; gap:.3rem; }
  button, select, input { min-height:40px; }
}
@media (max-width:360px) { #grid { grid-template-columns:1fr; } }
