/* ============================================================
   Sign To Erebor — stylesheet (Shire edition)
   Layout plan:
   .page                 fluid container, max 1500px
     .topbar             brand + theme toggle + global actions
     .event-card         title, meta chips, join/identity row
     .layout             grid: calendar (1fr) + sidebar (300px)
       .calendar         auto-fill grid of .month cards (min 400px)
         .month .grid    7 cols of minmax(0,1fr); cell height from
                         aspect-ratio only — cells can never overflow
       .side             sticky column of info cards
   Themes: html[data-theme=dark]  — evening at Bag End
           html[data-theme=light] — morning parchment
   ============================================================ */

* { box-sizing: border-box; margin: 0; }

@font-face {
  font-family: 'IM Fell English';
  src: url('fonts/imfell-regular.woff2') format('woff2');
  font-display: swap;
}
@font-face {
  font-family: 'IM Fell English';
  font-style: italic;
  src: url('fonts/imfell-italic.woff2') format('woff2');
  font-display: swap;
}

:root, :root[data-theme="dark"] {
  --bg: #1a150e;
  --bg-glow: #2a2315;
  --bg-raised: #14100a;
  --card: #251e12;
  --border: #453a23;
  --text: #ede3cb;
  --muted: #a3977c;
  --gold: #d9a94a;
  --gold-soft: rgba(217, 169, 74, 0.18);
  --green: 140 45% 42%;
  --door-hi: #7fa85e;
  --door-lo: #567f3d;
  --door-text: #1a2410;
  --badge-bg: rgba(0, 0, 0, 0.4);
  --overlay: rgba(12, 9, 4, 0.72);
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --radius-sm: 10px;
  --font-display: 'IM Fell English', 'Palatino Linotype', Palatino, Georgia, serif;
  /* Shire hills at dusk with the Party Tree and Erebor far on the horizon */
  --scenery: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 180' preserveAspectRatio='none'%3E%3Cpolygon points='1120,180 1240,30 1360,180' fill='%23262019'/%3E%3Cpolygon points='1206,72 1240,30 1274,72' fill='%233a332b'/%3E%3Cpath d='M0,180 L0,118 Q360,58 720,128 T1440,108 L1440,180 Z' fill='%23232e18'/%3E%3Crect x='356' y='72' width='7' height='20' fill='%23463b26'/%3E%3Ccircle cx='360' cy='62' r='16' fill='%232c3a1c'/%3E%3Ccircle cx='347' cy='69' r='11' fill='%2326331a'/%3E%3Ccircle cx='373' cy='69' r='11' fill='%2326331a'/%3E%3Cpath d='M0,180 L0,150 Q480,92 960,158 T1440,138 L1440,180 Z' fill='%231b2612'/%3E%3C/svg%3E");
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E");
  --grain-opacity: 0.05;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f1e9d2;
  --bg-glow: #f9f3e1;
  --bg-raised: #e8ddc0;
  --card: #f9f3e0;
  --border: #d1c199;
  --text: #3a2f1b;
  --muted: #80735a;
  --gold: #a4732a;
  --gold-soft: rgba(164, 115, 42, 0.16);
  --green: 140 45% 38%;
  --door-hi: #6b9a4e;
  --door-lo: #4c7536;
  --door-text: #f7f2e0;
  --badge-bg: rgba(58, 47, 27, 0.14);
  --overlay: rgba(58, 47, 27, 0.45);
  --shadow: 0 4px 16px rgba(122, 94, 44, 0.18);
  /* the same landscape at midday */
  --scenery: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 180' preserveAspectRatio='none'%3E%3Cpolygon points='1120,180 1240,30 1360,180' fill='%23d8d0b6'/%3E%3Cpolygon points='1206,72 1240,30 1274,72' fill='%23eae4d0'/%3E%3Cpath d='M0,180 L0,118 Q360,58 720,128 T1440,108 L1440,180 Z' fill='%23d3ddb0'/%3E%3Crect x='356' y='72' width='7' height='20' fill='%238a744f'/%3E%3Ccircle cx='360' cy='62' r='16' fill='%23a9bd84'/%3E%3Ccircle cx='347' cy='69' r='11' fill='%239db377'/%3E%3Ccircle cx='373' cy='69' r='11' fill='%239db377'/%3E%3Cpath d='M0,180 L0,150 Q480,92 960,158 T1440,138 L1440,180 Z' fill='%23c3d29c'/%3E%3C/svg%3E");
  --grain-opacity: 0.06;
  color-scheme: light;
}

html {
  background: var(--bg);
  font-size: clamp(15px, 0.35vw + 13.5px, 18px);
}

body {
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", "Iowan Old Style", Georgia, serif;
  background: radial-gradient(1200px 600px at 50% -100px, var(--bg-glow), var(--bg));
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* film grain over everything; scenery pinned to the viewport bottom */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: var(--grain);
  opacity: var(--grain-opacity);
  pointer-events: none;
  z-index: 99;
}
body::after {
  content: '';
  position: fixed;
  inset: auto 0 0 0;
  height: 180px;
  background: var(--scenery) bottom center / 100% 100% no-repeat;
  pointer-events: none;
  z-index: 0;
}

a { color: var(--gold); }

.page {
  position: relative;
  z-index: 1;
  max-width: 1500px;
  margin: 0 auto;
  padding: 20px clamp(16px, 3vw, 48px) 120px;
}
.page.narrow { max-width: 580px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  min-width: 0;
  box-shadow: var(--shadow);
}

/* ---------- buttons ---------- */

button { font: inherit; cursor: pointer; }

.primary {
  padding: 10px 22px;
  font-weight: 700;
  color: var(--door-text);
  background: linear-gradient(180deg, var(--door-hi), var(--door-lo));
  border: 1px solid var(--door-lo);
  border-radius: 999px;
}
.primary:hover { filter: brightness(1.08); }
.primary::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
  margin-right: 10px;
  vertical-align: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.ghost {
  padding: 7px 16px;
  color: var(--gold);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.88rem;
}
.ghost:hover { border-color: var(--gold); background: var(--gold-soft); }
.ghost.small { padding: 4px 14px; font-size: 0.8rem; }
a.ghost { text-decoration: none; display: inline-flex; align-items: center; }

/* ---------- guide (collapsible, breaks out of the narrow column) ---------- */

.guide { max-width: 1150px; margin: 44px auto 0; }
.guide summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: fit-content;
  margin: 0 auto;
  padding: 10px 26px;
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--gold);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  user-select: none;
}
.guide summary::-webkit-details-marker { display: none; }
.guide summary:hover { border-color: var(--gold); }
.guide summary::after {
  content: '❯';
  font-size: 0.85rem;
  color: var(--muted);
  transform: rotate(90deg);
  transition: transform 0.2s;
}
.guide[open] summary::after { transform: rotate(-90deg); }

.guide-body { margin-top: 26px; }
.guide-body > p {
  max-width: 720px;
  margin: 0 auto;
  text-align: center;
  font-size: 0.95rem;
}
.steps {
  list-style: none;
  padding: 0;
  margin-top: 30px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr));
  gap: 30px 36px;
  align-items: start;
}
.steps h3 {
  font-family: var(--font-display);
  font-weight: normal;
  font-size: 1.15rem;
  color: var(--gold);
}
.steps p { font-size: 0.9rem; color: var(--muted); margin: 4px 0 10px; }
.steps img {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

:root[data-theme="dark"] .only-light { display: none; }
:root[data-theme="light"] .only-dark { display: none; }

button:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

button.link {
  font-size: 0.88rem;
  color: var(--gold);
  background: none;
  border: none;
  padding: 0;
  text-decoration: underline;
}

/* ---------- forms ---------- */

form label { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 12px; }
input, select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
input:focus, select:focus { outline: 2px solid var(--gold); outline-offset: -1px; border-color: transparent; }

.row { display: flex; gap: 12px; }
.row > label { flex: 1; }

fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px 2px; margin-bottom: 12px; }
legend { font-size: 0.85rem; color: var(--muted); padding: 0 6px; }
label.radio { display: flex; gap: 10px; align-items: baseline; color: var(--text); cursor: pointer; }
label.radio input { width: auto; display: inline; margin: 0; }
label.radio b { color: var(--gold); font-weight: 600; }

.hint { font-size: 0.83rem; color: var(--muted); margin-top: 10px; }
.loading { color: var(--muted); text-align: center; padding: 60px 0; font-style: italic; }

/* ---------- create page ---------- */

.hero { text-align: center; padding: 24px 0 28px; }
.hero-door { width: 94px; height: 94px; margin-bottom: 12px; }
.hero-door .frame-outer { fill: none; stroke: var(--border); stroke-width: 7; }
.hero-door .frame { fill: none; stroke: var(--gold); stroke-width: 2.5; }
.hero-door .panel { fill: var(--door-lo); }
.hero-door .planks line { stroke: rgba(0, 0, 0, 0.28); stroke-width: 2; }
.hero-door .sheen { fill: rgba(255, 255, 255, 0.07); }
.hero-door .knob { fill: var(--gold); }
.hero h1 {
  font-family: var(--font-display);
  font-weight: normal;
  font-size: 2.6rem;
  letter-spacing: 0.04em;
  color: var(--gold);
  text-shadow: 0 2px 18px var(--gold-soft);
}
.tagline { color: var(--muted); margin-top: 8px; font-style: italic; }
.tagline::before { content: '❧  '; }
.tagline::after { content: '  ☙'; }

.create-col { max-width: 580px; margin: 0 auto; }
.create-col .primary { width: 100%; padding: 12px; }

.fancy-rule {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--gold);
  margin: 4px 0 20px;
  opacity: 0.8;
  font-size: 0.9rem;
}
.fancy-rule::before, .fancy-rule::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--border);
}

.colophon {
  text-align: center;
  color: var(--muted);
  font-style: italic;
  font-size: 0.8rem;
  margin-top: 48px;
  opacity: 0.85;
}
.page.narrow .primary { width: 100%; padding: 12px; }

/* ---------- event page shell ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.topbar.solo { justify-content: flex-end; margin-bottom: 0; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-decoration: none;
}
.brand .mark { width: 22px; height: 13px; fill: currentColor; flex-shrink: 0; }

.event-card { margin-bottom: 20px; display: flex; flex-direction: column; gap: 12px; }
.event-card h1 {
  font-family: var(--font-display);
  font-weight: normal;
  font-size: 1.9rem;
  line-height: 1.2;
}
.event-card h1::first-letter { text-transform: uppercase; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-size: 0.82rem;
  color: var(--muted);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 13px;
  white-space: nowrap;
}

.identity { border-top: 1px dashed var(--border); padding-top: 12px; }
.identity p { font-size: 0.95rem; }
.join-row { align-items: stretch; max-width: 680px; flex-wrap: wrap; }
.join-row input { margin: 0; flex: 1 1 180px; }
.join-row .primary { flex-shrink: 0; }
.identity.attention { animation: shake 0.4s; }
.identity.attention input { border-color: var(--gold); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.calendar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(400px, 100%), 1fr));
  gap: 20px;
  align-items: start;
  min-width: 0;
}

.side { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 16px; }
.side h3 {
  font-size: 0.76rem;
  margin-bottom: 10px;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 700;
}

/* ---------- calendar ---------- */

.month h3 {
  font-family: var(--font-display);
  font-weight: normal;
  font-size: 1.2rem;
  margin-bottom: 12px;
  color: var(--gold);
  font-style: italic;
}

.grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
}
.wd { font-size: 0.72rem; color: var(--muted); text-align: center; padding-bottom: 2px; }
.wd:nth-child(6), .wd:nth-child(7) { color: var(--gold); opacity: 0.8; }

.day {
  position: relative;
  aspect-ratio: 1 / 0.85;
  min-width: 0;
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  font-size: 0.85rem;
  user-select: none;
}
.day .num { position: absolute; top: 3px; left: 7px; }
.day.pad { visibility: hidden; }
.day.off { color: var(--border); }
.day.active {
  cursor: pointer;
  touch-action: none;
  background:
    linear-gradient(hsl(var(--green) / calc(var(--heat, 0) * 0.85)), hsl(var(--green) / calc(var(--heat, 0) * 0.85))),
    var(--bg-raised);
  border: 1px solid var(--border);
}
.day.active:hover { border-color: var(--gold); }
.day.mine { box-shadow: inset 0 0 0 2px var(--gold); background-color: var(--gold-soft); }
.my-mark {
  position: absolute;
  left: 6px;
  bottom: 3px;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 700;
}
.day .badge {
  position: absolute;
  right: 4px;
  bottom: 3px;
  font-size: 0.68rem;
  color: var(--text);
  background: var(--badge-bg);
  border-radius: 10px;
  padding: 0 6px;
}

.legend-bar {
  height: 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: linear-gradient(90deg, var(--bg-raised), hsl(var(--green) / 0.85));
}
.legend-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 5px;
  font-style: italic;
}

/* ---------- day modal ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
.modal { width: 400px; max-width: 100%; max-height: 85vh; display: flex; flex-direction: column; }
.modal header { display: flex; align-items: center; gap: 12px; }
.modal h3 { flex: 1; font-family: var(--font-display); font-weight: normal; font-size: 1.15rem; color: var(--gold); }
.modal .close { color: var(--muted); background: none; border: none; font-size: 1.1rem; }
.modal .close:hover { color: var(--text); }
.modal .hint { margin: 6px 0 10px; }

.slots { overflow-y: auto; display: flex; flex-direction: column; gap: 3px; }
.slot-row { display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 8px; align-items: center; }
.slot-row .t { font-size: 0.8rem; color: var(--muted); text-align: right; }
.slot {
  position: relative;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  touch-action: none;
  background:
    linear-gradient(hsl(var(--green) / calc(var(--heat, 0) * 0.85)), hsl(var(--green) / calc(var(--heat, 0) * 0.85))),
    var(--bg-raised);
}
.slot:hover { border-color: var(--gold); }
.slot.mine { box-shadow: inset 0 0 0 2px var(--gold); background-color: var(--gold-soft); }
.slot .cnt {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.75rem;
  color: var(--muted);
  pointer-events: none;
}
.slot.mine .cnt { color: var(--text); }

/* ---------- side lists ---------- */

.best, .company { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.best li, .company li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.88rem;
  padding: 4px 12px;
  background: var(--bg-raised);
  border-radius: 8px;
}
.best li {
  background-image: linear-gradient(hsl(var(--green) / 0.35), hsl(var(--green) / 0.35));
  background-repeat: no-repeat;
  background-size: var(--w, 0) 100%;
}
.best b, .company b { color: var(--gold); font-weight: 700; }
.company li.me { border: 1px solid var(--gold); }
.company li span { font-style: italic; }
.lock { width: 0.7em; height: 0.8em; vertical-align: -1px; margin-left: 2px; }
.lock rect { fill: var(--muted); }
.lock path { stroke: var(--muted); stroke-width: 1.6; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--card);
  border: 1px solid var(--gold);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 20;
  animation: toast-in 0.25s;
  box-shadow: var(--shadow);
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- journey strip (there and back again) ---------- */

.journey {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 4px 6px 0;
}
.j-end { display: flex; color: var(--muted); }
.j-door .hero-door { width: 30px; height: 30px; margin: 0; }
.j-door .hero-door .frame-outer { stroke-width: 9; }
.j-peak .mark { width: 30px; height: 18px; fill: currentColor; }
.j-track { position: relative; border-top: 2px dashed var(--border); height: 2px; }
.j-walker {
  position: absolute;
  top: -6px;
  left: var(--p, 0%);
  transform: translateX(-50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2.5px solid var(--gold);
  background: transparent;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  transition: left 0.6s ease;
}
.j-label {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  font-style: italic;
}

/* ---------- lost / expired plan ---------- */

.lost { text-align: center; }
.lost-mark { display: inline-block; color: var(--muted); }
.lost-mark .mark { width: 52px; height: 30px; fill: currentColor; }
.lost h2 {
  font-family: var(--font-display);
  font-weight: normal;
  font-size: 1.35rem;
  color: var(--gold);
  margin: 6px 0 4px;
}

/* ---------- fireworks ---------- */

.fireworks { position: fixed; inset: 0; pointer-events: none; z-index: 60; }
.fireworks span {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  opacity: 0;
  animation: fw 1.5s ease-out forwards;
}
@keyframes fw {
  0% { opacity: 1; transform: translate(0, 0); }
  70% { opacity: 0.9; }
  100% { opacity: 0; transform: translate(var(--dx, 0), var(--dy, 0)); }
}
