:root {
  --bg: #0d1424;
  --panel: #151f35;
  --panel-2: #1c2842;
  --line: #2a3a5c;
  --text: #eef2f8;
  --muted: #93a0b8;
  --red: #c8102e;
  --red-hover: #e0193a;
  --blue: #4f7fd9;
  --idea: #93a0b8;
  --ready: #2fbf71;
  --posted: #4f7fd9;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
body.noscroll { overflow: hidden; }

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.1rem; }
a { color: #8fb3ff; }
img { max-width: 100%; display: block; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

input, textarea, select {
  width: 100%;
  font: inherit;
  font-size: 16px; /* stops iOS zooming on focus */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--blue); outline-offset: -1px; }

.btn {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  min-height: 42px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: #3d5180; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--red-hover); }
.btn.danger { color: #ff8a9b; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 0.85rem; }
.btn.icon { width: 42px; padding: 0; font-size: 1.3rem; }
.btn.block { width: 100%; }
.link { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 8px; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--idea); flex: none; }
.dot.ready { background: var(--ready); }
.dot.posted { background: var(--posted); }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 520px);
  background: #22314f;
  border: 1px solid var(--line);
  padding: 12px 16px;
  border-radius: var(--radius);
  z-index: 100;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}
#toast.error { background: #4a1420; border-color: var(--red); }

/* ---------- Login ---------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 22px;
  display: grid;
  gap: 14px;
}
.login-card label { display: grid; gap: 6px; font-weight: 600; font-size: 0.9rem; }
.login-logo { width: 56px; }
.form-error { color: #ff8a9b; margin: 0; }

/* ---------- Shell ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: rgba(13, 20, 36, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: 0.02em; }
.brand img { width: 28px; }
.tabs { display: flex; gap: 2px; margin-right: auto; }
.tab {
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 10px 10px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.tab.active { color: var(--text); border-bottom-color: var(--red); }

main#main { max-width: 1180px; margin: 0 auto; padding: 16px 16px calc(40px + env(safe-area-inset-bottom)); }
.page-title { margin-bottom: 6px; }

/* ---------- Calendar ---------- */

.cal-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav h1 { min-width: 9.5em; text-align: center; }
.stats { display: flex; gap: 14px; color: var(--muted); font-size: 0.85rem; }
.stats span { display: flex; align-items: center; gap: 6px; }

.suggest-bar { display: flex; gap: 8px; margin-bottom: 8px; }
.suggest-bar .focus-input { flex: 1; }

.grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 8px;
}
.weekday { padding: 6px 8px; font-size: 0.75rem; color: var(--muted); background: var(--panel); border-bottom: 1px solid var(--line); }
.cell {
  min-height: 112px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  overflow: hidden;
}
.cell:nth-child(7n) { border-right: 0; }
.cell.blank { background: var(--bg); cursor: default; }
.cell.past { opacity: 0.65; }
.cell:hover:not(.blank) { background: var(--panel-2); }
.cell.selected { outline: 2px solid var(--red); outline-offset: -2px; }
.cell .num { font-size: 0.8rem; font-weight: 700; color: var(--muted); }
.cell.today .num { color: #fff; background: var(--red); border-radius: 999px; padding: 0 7px; align-self: flex-start; }
.cell img { width: 100%; height: 48px; object-fit: cover; border-radius: 4px; }
.post-line {
  display: flex;
  gap: 5px;
  align-items: baseline;
  font-size: 0.75rem;
  line-height: 1.25;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.post-line .dot { margin-right: 4px; transform: translateY(-1px); }

.agenda { display: none; }

/* ---------- Day panel ---------- */

.day-panel { margin-top: 24px; display: grid; gap: 16px; scroll-margin-top: 70px; }
.day-head { display: flex; align-items: center; gap: 12px; }
.day-head .back { display: none; }

.new-post { background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); padding: 12px; display: grid; gap: 10px; }

.post {
  display: grid;
  grid-template-columns: minmax(0, 380px) minmax(0, 1fr);
  gap: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.image-col, .text-col { display: grid; gap: 12px; align-content: start; }
.image-frame {
  aspect-ratio: 4 / 5;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  display: grid;
  place-items: center;
}
.image-frame img { width: 100%; height: 100%; object-fit: contain; }
.placeholder { color: var(--muted); }
.busy { display: grid; justify-items: center; gap: 12px; color: var(--muted); padding: 20px; text-align: center; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--line); border-top-color: var(--red); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.change { display: flex; gap: 8px; }
.change input { flex: 1; }
.image-col .row select { width: auto; flex: 1; }

.versions .strip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; }
.version { flex: none; width: 64px; height: 80px; padding: 0; border: 2px solid transparent; border-radius: 6px; overflow: hidden; background: none; cursor: pointer; }
.version img { width: 100%; height: 100%; object-fit: cover; }
.version.current { border-color: var(--red); }

.status-picker { display: flex; gap: 6px; }
.pill { font: inherit; font-size: 0.85rem; font-weight: 600; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: none; color: var(--muted); cursor: pointer; }
.pill.active.idea { background: #3a4660; color: #fff; border-color: #3a4660; }
.pill.active.ready { background: var(--ready); color: #04210f; border-color: var(--ready); }
.pill.active.posted { background: var(--posted); color: #fff; border-color: var(--posted); }

.field { display: grid; gap: 6px; }
.field > span { font-size: 0.8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.sources ul { margin: 6px 0 0; padding-left: 18px; font-size: 0.88rem; }
.sources li { margin-bottom: 4px; word-break: break-word; }

.date-btn { position: relative; display: inline-flex; align-items: center; }
.date-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.empty { color: var(--muted); padding: 20px 0; }

/* ---------- Library ---------- */

.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-top: 16px; }
.lib-item { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.lib-item img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; }
.lib-item figcaption { padding: 10px; display: grid; gap: 6px; font-size: 0.85rem; }
.lib-item figcaption > span:not(.row) { color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- Settings ---------- */

.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-top: 16px; align-items: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 12px; }
.team { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.team li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.add-user { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.add-user select, .add-user button { grid-column: span 1; }
.notice { background: #102a1c; border: 1px solid var(--ready); border-radius: 8px; padding: 12px; display: grid; gap: 8px; }
.notice code { white-space: pre-wrap; font-size: 0.9rem; user-select: all; }

/* ---------- Phones ---------- */

@media (max-width: 760px) {
  .topbar { padding-left: 12px; padding-right: 12px; gap: 6px; }
  .brand span { display: none; }
  .tab { padding: 10px 8px; }
  main#main { padding: 12px 12px calc(40px + env(safe-area-inset-bottom)); }

  .month-nav h1 { min-width: 0; font-size: 1.15rem; flex: 1; }
  .month-nav { width: 100%; }
  .suggest-bar { flex-direction: column; }

  .grid { display: none; }
  .agenda { display: grid; gap: 6px; margin-top: 8px; }
  .agenda-row {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 52px;
    gap: 10px;
    align-items: center;
    text-align: left;
    font: inherit;
    color: inherit;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 8px 10px;
    min-height: 68px;
    cursor: pointer;
  }
  .agenda-row.past { opacity: 0.6; }
  .agenda-row.today { border-color: var(--red); }
  .agenda-date { display: grid; justify-items: center; line-height: 1.1; }
  .agenda-date small { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; }
  .agenda-date b { font-size: 1.25rem; }
  .agenda-body { display: grid; gap: 4px; font-size: 0.88rem; min-width: 0; }
  .agenda-body .post-line { font-size: 0.88rem; }
  .agenda-row img, .thumb-empty { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; }
  .thumb-empty { background: var(--bg); }

  /* The selected day opens as a full-screen sheet. */
  .day-panel {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 50;
    margin: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--bg);
    padding: calc(10px + env(safe-area-inset-top)) 12px calc(40px + env(safe-area-inset-bottom));
    align-content: start;
  }
  .day-panel.open { display: grid; }
  .day-head { position: sticky; top: calc(-10px - env(safe-area-inset-top)); background: var(--bg); padding: 6px 0; z-index: 2; }
  .day-head .back { display: inline-block; }

  .post { grid-template-columns: 1fr; padding: 12px; gap: 14px; }
  .change { flex-direction: column; }
  .add-user { grid-template-columns: 1fr; }
  .settings { grid-template-columns: 1fr; }
}
.show-past { justify-self: center; }
