:root {
  --bg: #f6f3ee;
  --panel: #fffdf9;
  --ink: #1f1d1a;
  --muted: #6b655c;
  --line: #e2dbcf;
  --accent: #1f3a5f;
  --accent-ink: #ffffff;
  --button: #efe9df;
  --button-hover: #e5ddd0;
  --table: #2b2723;
  --panel-w: 320px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --panel: #1f1d1a;
    --ink: #eee9e1;
    --muted: #a39b8f;
    --line: #34302b;
    --accent: #7fa6d6;
    --accent-ink: #10151c;
    --button: #2b2824;
    --button-hover: #36322d;
    --table: #0f0e0d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 650;
  font-size: 16px;
  white-space: nowrap;
}

/* Edwardian Script ITC ships with Windows/Office; Pinyon Script is a close web fallback. */
.brand-name {
  font-family: "Edwardian Script ITC", "Pinyon Script", cursive;
  font-weight: 400;
  font-size: 68px;
  line-height: 1;
  letter-spacing: 0.01em;
}

/* Calibri ships with Windows/Office; Carlito is its metric-compatible open equivalent. */
.brand-version {
  font-family: Calibri, Carlito, sans-serif;
  font-weight: 400;
  font-size: 12px;
  color: var(--muted, #888);
  align-self: flex-end;
  margin-bottom: 10px;
  margin-left: 20px;
}

.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

button, .button {
  font: inherit;
  color: var(--ink);
  background: var(--button);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  touch-action: manipulation;
}
button:hover, .button:hover { background: var(--button-hover); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

.layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

.stage {
  flex: 1;
  position: relative;
  min-width: 0;
  background: var(--table);
}

#bath {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.status {
  position: absolute;
  left: 10px;
  bottom: 8px;
  color: #d8d0c4;
  font-size: 12px;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}

.replay-bar {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 14px;
  background: rgba(20, 18, 16, 0.85);
  color: #f2ede6;
  border-radius: 999px;
}
.replay-bar[hidden] { display: none; }
.replay-bar button { padding: 4px 10px; border-radius: 999px; }

.panel {
  width: var(--panel-w);
  flex: 0 0 var(--panel-w);
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 4px 14px 24px;
}

.panel section { padding: 10px 0 12px; border-bottom: 1px solid var(--line); }
.panel section:last-child { border-bottom: 0; }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 4px 0 8px; }

.tool-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tool-list button { font-size: 13px; }

.fields { display: grid; gap: 8px; margin: 8px 0; }
.fields.two { grid-template-columns: 1fr 1fr; }
.fields label { display: grid; gap: 3px; font-size: 12.5px; color: var(--muted); }
.fields label.check { display: flex; align-items: center; gap: 6px; color: var(--ink); }
.fields output { float: right; color: var(--ink); font-variant-numeric: tabular-nums; }
.fields label > span.lbl { display: flex; justify-content: space-between; }
.fields input[type="number"], .fields select, .fields input[type="text"] {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 7px;
  width: 100%;
}
.fields input[type="color"] { width: 100%; height: 30px; border: 1px solid var(--line); border-radius: 6px; padding: 2px; background: var(--bg); }
.fields input[type="range"] { width: 100%; }

.row-buttons { display: flex; flex-wrap: wrap; gap: 6px; }

.palette { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--line);
  padding: 0;
  cursor: pointer;
}
.swatch.selected { outline: 3px solid var(--accent); outline-offset: 2px; }

.hint { color: var(--muted); font-size: 12.5px; margin: 4px 0 8px; }
details summary { cursor: pointer; font-weight: 600; }
details p { color: var(--muted); font-size: 12.5px; }

.panel-toggle { display: none; }

@media (max-width: 820px) {
  .panel-toggle { display: inline-flex; }
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  .topbar .actions { width: 100%; justify-content: flex-start; }
  .brand-name { font-size: 34px; }
  .brand-logo { width: 36px; height: 36px; }
  .brand-version { margin-left: 8px; margin-bottom: 5px; }
  .layout { flex-direction: column; }
  .panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 62vh;
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -8px 30px rgba(0,0,0,0.3);
    transform: translateY(105%);
    transition: transform 0.2s ease;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    z-index: 5;
  }
  .panel.open { transform: none; }
}

.brand-logo {
  border-radius: 8px;
  object-fit: cover;
  flex: none;
}
