:root {
  --bg: #f4e8cf;
  --surface: #fbf3e1;
  --text: #2b2118;
  --muted: #6b5c49;
  --line: rgba(43, 33, 24, 0.14);
  --accent: #b5562a;
  --accent-dark: #5c2712;
  --accent-soft: #f7d6bd;
  --green: #3f4626;
  --green-soft: #e2e5c2;
  --danger: #9c3f2e;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; display: flex; min-height: 100vh; }
a { color: var(--accent-dark); }
code { font-size: 0.85em; }

.sidebar {
  width: 230px; flex: none; padding: 22px 16px; border-right: 1px solid var(--line);
  background: var(--surface); position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
}
.brand { font-weight: 800; font-size: 22px; color: var(--accent-dark); }
.brand span { display: block; font-size: 12px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
nav a {
  display: block; padding: 9px 12px; border-radius: 10px; text-decoration: none;
  color: var(--text); font-weight: 600; margin-bottom: 4px;
}
nav a.active { background: var(--accent-dark); color: var(--bg); }
.sidebar-foot { margin-top: auto; font-size: 12px; color: var(--muted); line-height: 1.5; }

main { flex: 1; padding: 26px 32px 80px; max-width: 1180px; }
h1 { margin: 0 0 4px; font-size: 26px; }
h2 { font-size: 17px; margin: 26px 0 10px; }
.subtitle { color: var(--muted); margin: 0 0 20px; }

.banner { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-weight: 600; white-space: pre-wrap; }
.banner.error { background: #f6d3cb; color: #6d1f12; }
.banner.ok { background: var(--green-soft); color: var(--green); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }

button, .button {
  font: inherit; font-weight: 700; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); padding: 8px 14px; border-radius: 999px; cursor: pointer;
}
button.primary { background: var(--accent-dark); border-color: var(--accent-dark); color: var(--bg); }
button.danger { color: var(--danger); border-color: rgba(156, 63, 46, .35); }
button.small { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  font: inherit; color: var(--text); background: #fffaf0; border: 1px solid var(--line);
  border-radius: 10px; padding: 7px 10px; width: 100%;
}
textarea { min-height: 64px; resize: vertical; line-height: 1.4; }
label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.three { grid-template-columns: repeat(3, 1fr); }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

.list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.item { cursor: pointer; overflow: hidden; padding: 0; }
.item:hover { border-color: var(--accent); }
.item .thumb { height: 120px; background: #d8c8a8 center/cover no-repeat; }
.item .body { padding: 10px 12px; }
.item .title { font-weight: 700; margin-bottom: 6px; }
.meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-dark); }
.pill.hidden { background: #e4d5b4; color: var(--muted); }
.pill.green { background: var(--green-soft); color: var(--green); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button.active { background: var(--accent); border-color: var(--accent); color: white; }

.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.page { padding: 8px; }
.page .preview { height: 96px; border-radius: 10px; background: #d8c8a8 center/cover no-repeat; margin-bottom: 6px; display: grid; place-items: center; font-size: 11px; color: var(--muted); text-align: center; }
.page .actions { display: flex; gap: 4px; flex-wrap: wrap; }

.level { margin-bottom: 14px; }
.level-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.level-head input[type=number] { width: 90px; }
.level-texts { display: grid; gap: 6px; }
.level-texts .row { display: grid; grid-template-columns: 70px 1fr; gap: 8px; align-items: start; font-size: 12px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); padding: 6px; }
td { padding: 6px; vertical-align: top; border-top: 1px solid var(--line); }
td.narrow { width: 1%; white-space: nowrap; }
.card-img { width: 64px; height: 64px; border-radius: 10px; background: #d8c8a8 center/cover no-repeat; }

.toggle { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; cursor: pointer; }
.toggle input { width: auto; }

pre.log { background: #2b2118; color: #f4e8cf; padding: 14px; border-radius: var(--radius); white-space: pre-wrap; max-height: 460px; overflow: auto; font-size: 12px; }
.muted { color: var(--muted); }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* Tables scroll inside their card instead of squeezing the inputs. */
main { min-width: 0; }
.card:has(> table) { overflow-x: auto; }
table { min-width: 980px; }
td input, td select { min-width: 72px; }

@media (max-width: 760px) {
  body { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--line); padding: 14px 16px; gap: 10px; }
  nav { display: flex; gap: 4px; flex-wrap: wrap; }
  nav a { margin: 0; }
  .sidebar-foot { display: none; }
  main { padding: 18px 16px 60px; }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
}
