:root {
  --ink: #142033;
  --navy: #101b2e;
  --muted: #5c6b7e;
  --teal: #0e7a66;
  --teal-deep: #0a5c4d;
  --ice: #e7f3ef;
  --sand: #f4f0ea;
  --paper: #fffcf8;
  --line: #e4ddd3;
  --danger: #8d2f2f;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Source Sans 3", "Segoe UI", sans-serif;
  --shadow: 0 18px 50px rgba(16, 27, 46, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--sand);
  font-size: 16.5px;
  line-height: 1.5;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }
h1, h2, h3 { font-family: var(--serif); font-weight: 560; letter-spacing: -0.03em; color: var(--navy); line-height: 1.15; margin: 0; }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 3px; }
html.boot #gate, html.boot #app { visibility: hidden; }

.btn, .btn-secondary, .btn-danger, .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  padding: 11px 18px;
  border: 1px solid transparent;
  text-decoration: none;
  font-weight: 700;
  line-height: 1;
}
.btn { background: var(--teal); color: white; }
.btn:hover { background: var(--teal-deep); }
.btn:disabled { opacity: 0.65; cursor: wait; }
.btn-secondary, .btn-ghost { background: white; color: var(--navy); border-color: var(--line); }
.btn-secondary:hover, .btn-ghost:hover { border-color: var(--teal); color: var(--teal-deep); }
.btn-danger { background: white; color: var(--danger); border-color: #efd4d4; }
.btn-danger:hover { background: #fff6f6; }

#gate[hidden],
#app[hidden] { display: none; }
#gate {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
}
.gate-copy {
  background: var(--navy);
  color: #f6f3ee;
  padding: 64px 72px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 18px;
}
.gate-copy img { background: white; border-radius: 14px; padding: 10px 14px; width: 220px; }
.gate-copy h1 { color: white; font-size: clamp(48px, 6vw, 76px); max-width: 8ch; }
.gate-copy p { max-width: 38ch; color: #d5ddd8; font-size: 18px; margin: 0; }
.eyebrow { letter-spacing: 0.14em; text-transform: uppercase; font-size: 12px; font-weight: 700; color: #8fd0c2; margin: 0; }
.gate-card {
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 12px;
  padding: 48px;
  background:
    radial-gradient(circle at top right, rgba(14, 122, 102, 0.12), transparent 32%),
    var(--paper);
}
.gate-card h2 { font-size: 40px; }
.gate-card p { margin: 0 0 8px; color: var(--muted); }

#app { min-height: 100vh; display: grid; grid-template-columns: 248px 1fr; }
#app[hidden] { display: none; }
#sidebar {
  background: var(--navy);
  color: #e7eee9;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: grid; gap: 8px; padding: 0 8px; }
.brand img { background: white; border-radius: 12px; padding: 8px 10px; width: 168px; }
.brand span { color: #8fd0c2; font-size: 13px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.nav { display: grid; gap: 4px; }
.nav button {
  text-align: left;
  background: transparent;
  border: 0;
  color: #d7e2dc;
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 600;
}
.nav button:hover { background: rgba(255, 255, 255, 0.06); color: white; }
.nav button[aria-current="page"] { background: rgba(255, 255, 255, 0.1); color: white; box-shadow: inset 3px 0 0 var(--teal); }
.side-foot { margin-top: auto; display: grid; gap: 10px; padding: 0 8px 8px; }
.side-foot p { margin: 0; color: #b7c4be; font-size: 14px; word-break: break-word; }
.side-foot a { color: #d7e2dc; text-underline-offset: 3px; }

.workspace { padding: 36px 40px 96px; }
#main { width: min(980px, 100%); display: grid; gap: 22px; }
.view-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-end; }
.view-head h1 { font-size: clamp(36px, 4vw, 52px); }
.kicker { margin: 0 0 6px; color: var(--teal-deep); font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; font-size: 12px; }
.hint { margin: 8px 0 0; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stat, .panel, .entry, .media-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.stat { padding: 18px 18px 16px; display: grid; gap: 6px; }
.stat strong { font-family: var(--serif); font-size: 34px; color: var(--navy); }
.stat span, .entry small, .media-card small { color: var(--muted); }
.jump { display: flex; flex-wrap: wrap; gap: 8px; }

.toolbar { display: flex; gap: 10px; align-items: center; }
.search {
  flex: 1;
  background: white;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 11px 16px;
}
.list { display: grid; gap: 10px; }
.entry {
  width: 100%;
  text-align: left;
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}
.entry:hover { border-color: #cfe3dc; }
.entry strong { display: block; font-size: 18px; }
.entry small { display: block; margin-top: 2px; }

.panel { padding: 22px; display: grid; gap: 14px; }
.panel h2 { font-size: 28px; }
.field { display: grid; gap: 6px; }
.field span { font-weight: 700; font-size: 14px; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  border-radius: 12px;
  padding: 12px 14px;
}
textarea { min-height: 110px; resize: vertical; }
textarea.editor { min-height: 380px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; line-height: 1.55; }
input:focus, textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 4px rgba(14, 122, 102, 0.14); }
.repeat, .string-row { display: grid; gap: 10px; padding: 14px; border: 1px dashed var(--line); border-radius: 14px; background: #fff; }
.string-row { grid-template-columns: 1fr auto; align-items: center; }
.split-edit { display: grid; grid-template-columns: 1fr 0.8fr; gap: 14px; align-items: start; }
.preview { background: white; border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; min-height: 380px; overflow: auto; }
.preview :first-child { margin-top: 0; }
.preview h1, .preview h2, .preview h3 { margin: 1em 0 0.4em; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.savebar {
  position: sticky;
  bottom: 16px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 12px 14px 12px 18px;
  background: rgba(16, 27, 46, 0.94);
  color: white;
  border-radius: 18px;
  box-shadow: 0 16px 40px rgba(16, 27, 46, 0.2);
}
.savebar p { margin: 0; color: #d5ddd8; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.media-card { overflow: hidden; display: grid; }
.media-card img { height: 120px; width: 100%; object-fit: cover; background: var(--ice); }
.media-card div { padding: 10px 12px 12px; display: grid; gap: 8px; }
.media-card small { word-break: break-all; }

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100% - 36px));
  background: white;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  transform: translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: 160ms ease;
}
#toast.show { opacity: 1; transform: none; }

@media (max-width: 980px) {
  #gate, .split-edit, .stats { grid-template-columns: 1fr; }
  .gate-copy { padding: 36px 24px; min-height: 46vh; }
  .gate-copy h1 { font-size: 48px; }
  .gate-card { padding: 28px 24px 48px; }
}
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { position: sticky; height: auto; z-index: 5; }
  .nav { display: flex; gap: 6px; overflow: auto; }
  .nav button { white-space: nowrap; }
  .side-foot { margin-top: 0; grid-template-columns: 1fr auto auto; align-items: center; }
  .workspace { padding: 22px 16px 88px; }
  .view-head, .savebar, .entry { align-items: stretch; flex-direction: column; }
}
