/* Fonts are self-hosted in /fonts (SIL Open Font License). */
@font-face {
  font-family: 'Inter';
  src: url('fonts/inter.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Fraunces';
  src: url('fonts/fraunces.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* Theme: Café Leblanc — dark wood, amber lamplight, cream booths, stained glass */
:root {
  --bg: #1a1513;
  --bg-2: #211a17;
  --panel: #2a211d;
  --panel-2: #342923;
  --line: #463a33;
  --chalk: #f3e9d8;
  --muted: #bfaa94;
  --dim: #87766a;
  --accent: #f0a64b;
  --accent-2: #ffcb80;
  --board: #2f4a3f;
  --danger: #e8806b;
  --radius: 14px;
  --glass: linear-gradient(90deg, #4fa8a0, #8fc28a, #f0c75a, #f0a64b, #e07a8a, #9b7fd1, #4fa8a0);
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(900px 520px at 88% -8%, rgba(240,166,75,0.10), transparent 62%),
    radial-gradient(700px 460px at 8% 105%, rgba(224,122,90,0.05), transparent 60%),
    repeating-linear-gradient(90deg, rgba(243,233,216,0.012) 0 2px, transparent 2px 64px),
    var(--bg);
  color: var(--chalk);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { font-family: var(--font-display); letter-spacing: 0; margin: 0; font-optical-sizing: auto; }
h1 { font-size: 22px; font-weight: 600; line-height: 1.1; letter-spacing: 0.01em; }
h2 { font-size: 19px; font-weight: 700; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- hero banner ---------- */
.hero {
  position: relative;
  min-height: clamp(210px, 39vw, 420px);
  display: flex; align-items: flex-end;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(700px 320px at 80% -30%, rgba(255,203,128,0.24), transparent 65%),
    radial-gradient(500px 260px at 10% 130%, rgba(224,122,90,0.12), transparent 60%),
    linear-gradient(170deg, #33281f, var(--bg));
}
.hero::before {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; z-index: 2;
  background: var(--glass); opacity: .75;
}
.hero-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;          /* always fills the width; trims a little top/bottom if needed */
  object-position: 50% 40%;   /* keep a bit more of the top (lamps) when trimming */
}
.hero.has-img {
  width: 100%;
  min-height: 0;
  aspect-ratio: var(--ratio, 16 / 9);
  max-height: 47vh;
}
.hero.has-img::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(26,21,19,0.92), rgba(26,21,19,0.25) 55%, rgba(26,21,19,0.1));
}
.hero-text {
  position: relative; z-index: 1;
  width: 100%; max-width: 1180px; margin: 0 auto;
  padding: 20px 16px 16px;
}
#site-title { color: var(--chalk); text-shadow: 0 2px 12px rgba(0,0,0,0.5); }
.tagline { margin: 8px 0 0; color: var(--muted); font-size: 16px; }

/* ---------- layout ---------- */
.wrap {
  max-width: 1180px; margin: 0 auto;
  padding: 22px 16px max(40px, env(safe-area-inset-bottom));
}
.plain-title { margin: 8px 0 22px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr));
  gap: 14px;
}

/* ---------- boxes (16:9 thumbnail cards) ---------- */
.box {
  position: relative; display: block; width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--chalk); text-decoration: none; text-align: left;
  padding: 0; font: inherit; cursor: pointer;
  isolation: isolate;
  transition: border-color .2s, box-shadow .2s, transform .2s;
}
.box:hover { border-color: rgba(240,166,75,0.65); box-shadow: 0 10px 30px rgba(0,0,0,0.45), 0 0 24px rgba(240,166,75,0.18); transform: translateY(-2px); }
.box:active { transform: translateY(0); }

.box .media {
  position: absolute; inset: 0; z-index: -2;
  transition: transform .45s ease;
}
.box:hover .media { transform: scale(1.06); }
.box img.media { width: 100%; height: 100%; object-fit: cover; }

/* fallback art when a box has no image */
.box .art {
  display: flex; align-items: center; justify-content: center;
  padding-bottom: 18%;
  background:
    radial-gradient(90% 75% at 50% -5%, rgba(255,203,128,0.20), transparent 62%),
    repeating-linear-gradient(90deg, rgba(0,0,0,0.05) 0 1px, transparent 1px 38px),
    linear-gradient(170deg, #32271f, var(--bg-2));
}
.box .art svg { width: 24%; max-width: 52px; height: auto; color: var(--chalk); opacity: .82; }
.box .art .letter { font-family: var(--font-display); font-weight: 800; font-size: clamp(40px, 8vw, 60px); color: var(--chalk); opacity: .82; line-height: 1; }

/* dark gradient so the title stays readable */
.box::after {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(to top, rgba(18,14,12,0.92) 0%, rgba(18,14,12,0.55) 32%, rgba(18,14,12,0) 62%);
  pointer-events: none;
}
.box .label {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 10px 12px;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 10px;
}
.box .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--font-display); font-weight: 600; font-size: 17px; line-height: 1.15; display: block; }
.box .label > div { min-width: 0; }
.box .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.box .chev { flex: 0 0 auto; width: 18px; height: 18px; color: var(--muted); transition: color .2s, transform .2s; }
.box:hover .chev { color: var(--accent); transform: translateX(2px); }

.box.off { cursor: default; opacity: .55; }
.box.off:hover { border-color: var(--line); box-shadow: none; transform: none; }
.box.off:hover .media { transform: none; }

/* ---------- downloaders panel ---------- */
.panel {
  width: min(420px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  color: var(--chalk);
  box-shadow: 0 24px 60px rgba(0,0,0,0.55);
}
.panel::backdrop { background: rgba(13,10,9,0.65); backdrop-filter: blur(4px); }
.panel[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.panel-head { border-bottom: 1px solid var(--line); margin-bottom: 4px; display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 20px; }
.close {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--muted); cursor: pointer;
}
.close:hover { color: var(--chalk); border-color: var(--dim); }
.close svg { width: 18px; height: 18px; }
.panel-list { list-style: none; margin: 0; padding: 6px 10px 12px; }
.panel-list a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 12px; border-radius: 11px;
  color: var(--chalk); text-decoration: none; font-weight: 500; font-size: 16px;
}
.panel-list a:hover, .panel-list a:focus-visible { background: rgba(240,166,75,0.12); color: var(--accent-2); }
.panel-list a svg { width: 18px; height: 18px; color: var(--dim); }
.panel-list a:hover svg { color: var(--accent); }
.panel-list li + li { border-top: 1px solid rgba(70,58,51,0.6); }

.note { color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- edit mode ---------- */
.cell { position: relative; }
.tools {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  display: none; gap: 6px;
}
body.editing .tools { display: flex; }
body.editing .box { outline: 2px dashed rgba(240,166,75,0.5); outline-offset: 3px; cursor: default; }
body.editing .box:hover { transform: none; }
.hero-tools { top: max(14px, env(safe-area-inset-top)); right: 16px; }
.tool {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px;
  border-radius: 10px; border: 1px solid rgba(243,233,216,0.18);
  background: rgba(26,21,19,0.78); backdrop-filter: blur(8px);
  color: var(--chalk); font: 600 13px var(--font-body); cursor: pointer;
}
.tool:hover { background: rgba(52,41,35,0.92); border-color: rgba(243,233,216,0.35); }
.tool svg { width: 17px; height: 17px; }
.tool.icon-only { width: 36px; padding: 0; justify-content: center; }

.edit-btn {
  position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 30;
  display: inline-flex; align-items: center; gap: 7px;
  height: 40px; padding: 0 14px;
  border-radius: 12px; border: 1px solid var(--line);
  background: rgba(42,33,29,0.9); backdrop-filter: blur(10px);
  color: var(--muted); font: 600 14px var(--font-body); cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,0.35);
}
.edit-btn:hover { color: var(--chalk); border-color: var(--dim); }
.edit-btn svg { width: 17px; height: 17px; }

.edit-bar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(16px, env(safe-area-inset-bottom)); z-index: 30;
  display: flex; align-items: center; gap: 8px;
  width: min(460px, calc(100% - 32px));
  padding: 8px 8px 8px 16px;
  border-radius: 14px; border: 1px solid var(--line);
  background: rgba(42,33,29,0.94); backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
}
.edit-label { flex: 1; font-weight: 600; color: var(--chalk); font-size: 14px; }
.bar-btn {
  height: 38px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--accent); background: var(--accent); color: #2a1a0e;
  font: 700 14px var(--font-body); cursor: pointer;
}
.bar-btn.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.bar-btn.ghost:hover { color: var(--chalk); border-color: var(--dim); }
body.editing .wrap { padding-bottom: 96px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  top: max(16px, env(safe-area-inset-top)); z-index: 40;
  padding: 10px 16px; border-radius: 12px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--chalk);
  font-weight: 600; font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  max-width: calc(100% - 32px);
}

.login-form { padding: 20px; display: grid; gap: 12px; }
.muted-small { margin: -6px 0 0; color: var(--muted); font-size: 14px; }
.login-form input {
  height: 44px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--chalk); font-size: 16px;
}
.login-form input:focus { outline: none; border-color: var(--muted); }
.login-error { margin: 0; color: var(--danger, #f58a9b); font-size: 14px; }
.login-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* phones: two boxes per row */
@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .box .label { padding: 8px 10px; }
  .box .name { font-size: 15px; }
  .box .sub { font-size: 11px; }
  .box .chev { display: none; }
  .box .art svg { width: 28%; }
  .cell .tools { top: 6px; right: 6px; }
  .cell .tool { width: 32px; height: 32px; padding: 0; justify-content: center; }
  .cell .tool span { display: none; }
}

/* ultra-wide screens (21:9 and wider): allow a taller banner so less is trimmed */
@media (min-aspect-ratio: 2/1) {
  .hero.has-img { max-height: 66vh; }
}
