:root {
  --paper: #f3ecdd;
  --paper-edge: #e6dcc6;
  --ink: #2b2b2b;
  --panel-bg: #201f1d;
  --panel-bg-alt: #2a2926;
  --text: #ece7dc;
  --text-dim: #a39d8c;
  --accent: #e0793c;
  --accent-dim: #8a4e2a;
  --border: #3a3835;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--panel-bg);
  color: var(--text);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-body {
  flex: 1;
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 0;
}

.panel {
  background: var(--panel-bg-alt);
  padding: 1rem;
  overflow-y: auto;
  border-color: var(--border);
}

.panel-left { border-right: 1px solid var(--border); }

.panel h2 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 0 0 0.6rem;
}

.panel section {
  margin-bottom: 1.5rem;
}

.slider-row {
  display: block;
  margin-bottom: 0.9rem;
  font-size: 0.8rem;
}

.slider-row span {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.3rem;
  color: var(--text-dim);
}

.slider-row b {
  color: var(--text);
  font-weight: 600;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.choice-buttons {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.8rem;
}

.align-btn {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.4rem 0.3rem;
  border-radius: 5px;
  font-size: 0.72rem;
  cursor: pointer;
}

.align-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1a1a;
  font-weight: 600;
}

.font-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.hint {
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--text-dim);
  margin: 0 0 0.6rem;
  min-height: 2.2em;
}

.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
}

input[type="color"] {
  width: 36px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: none;
  padding: 0;
  cursor: pointer;
}

.canvas-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.canvas-stage {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 0;
}

.canvas-stage:focus-within {
  box-shadow: inset 0 0 0 2px var(--accent-dim);
}

.font-status {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  background: var(--panel-bg-alt);
  padding: 0.3rem 0.6rem;
  border-radius: 5px;
  pointer-events: none;
  z-index: 1;
}

.font-status:empty {
  display: none;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: var(--paper);
}

/*
 * The actual text-editing surface. It sits directly on top of the canvas,
 * fully transparent (both fill and text) except for a visible caret and the
 * browser's own selection highlight — the letters everyone sees are drawn
 * by the canvas underneath. Font size/spacing/line-height/alignment are
 * kept in sync with the canvas layout from JS (see syncTextOverlay in
 * main.js) so clicking into a word and typing lines up with where that
 * word is actually drawn.
 *
 * Deliberately NOT set to Comico here: browsers size the native caret and
 * selection highlight off a font's own ascender/descender metrics rather
 * than the CSS line-height, and Comico's are unusually generous (its
 * ascender+descender adds up to ~1.46x its em-size). A normal system font
 * gives the browser more ordinary metrics to work with for that native
 * chrome, and still gives reasonable width-matching for click-to-position
 * via the font-size/letter-spacing we sync — though caret/selection height
 * still isn't pixel-perfect against the canvas text in every browser, since
 * that native rendering isn't something CSS gets full control over. Typing,
 * clicking, and selecting all work correctly regardless.
 */
.canvas-text-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: transparent;
  caret-color: var(--ink);
  font-family: system-ui, sans-serif;
  white-space: pre;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  cursor: text;
}

/* Invisible like the text itself — the overlay has no native scrollbar to
   show, but staying scrollable keeps the caret auto-scrolled into view when
   typing a line past the visible width, same as a normal text input. */
.canvas-text-input::-webkit-scrollbar {
  display: none;
}

/* Comico's license doesn't permit letting visitors generate their own text
   with it (see FONTS in main.js) — when it's selected the overlay becomes
   read-only, showing a fixed phrase. No text-beam cursor, since there's
   nothing to edit here. */
.canvas-text-input:read-only {
  cursor: default;
}

.canvas-text-input::placeholder {
  color: var(--text-dim);
  opacity: 0.5;
}

@media (max-width: 900px) {
  .app-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .panel-left { border: none; border-top: 1px solid var(--border); }
}
