/* Stick Toon — app chrome. The comic itself is drawn on canvas. */

:root {
  --bg: #14151a;
  --surface: #1c1e26;
  --surface-2: #23262f;
  --surface-3: #2b2f3a;
  --line: #333846;
  --text: #e7e9f0;
  --text-dim: #9aa1b1;
  --accent: #ffb020;
  --accent-ink: #2a1c00;
  --blue: #4c8dff;
  --danger: #ef5a5a;
  --radius: 10px;
  --sidebar-left: 236px;
  --sidebar-right: 276px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.logo-mark { font-size: 20px; }

.title-input {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 11px;
  font-size: 14px;
  min-width: 170px;
  max-width: 280px;
}
.title-input:focus { outline: 2px solid var(--blue); outline-offset: 1px; }

.grow { flex: 1 1 auto; }

.group {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 3px;
}

button {
  background: transparent;
  border: 0;
  color: var(--text);
  font: inherit;
  padding: 6px 11px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { background: var(--surface-3); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.35; cursor: default; }
button:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

button.icon {
  min-width: 34px;
  padding: 6px 8px;
  text-align: center;
  font-size: 15px;
}
button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
button.primary:hover { background: #ffc14d; }
button.active { background: var(--blue); color: #fff; }
button.danger:hover { background: var(--danger); color: #fff; }

/* ------------------------------------------------------------------ layout */

main {
  display: grid;
  grid-template-columns: var(--sidebar-left) minmax(0, 1fr) var(--sidebar-right);
  min-height: 0;
}

.sidebar {
  background: var(--surface);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px;
}
.sidebar.left { border-right: 1px solid var(--line); }
.sidebar.right { border-left: 1px solid var(--line); }

.sidebar::-webkit-scrollbar { width: 10px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; }

.lib-section { margin-bottom: 18px; }
.lib-section h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-dim);
  margin: 0 0 8px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.lib-section h2 small {
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
  color: #6d7486;
}

.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.btn-grid button {
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 9px 6px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.btn-grid button .em { font-size: 17px; }
.btn-grid button.wide { grid-column: span 2; flex-direction: row; justify-content: center; }

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.chip {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.chip.selected { border-color: var(--accent); background: #33291a; }

.prop-group { margin-bottom: 10px; }
.prop-group > h3 {
  font-size: 11px;
  color: var(--text-dim);
  margin: 0 0 6px;
  font-weight: 600;
}
.prop-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}
.prop-btn {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}
.prop-btn canvas { width: 100%; height: 100%; display: block; }
.prop-btn:hover { border-color: var(--accent); }

/* ------------------------------------------------------------------- stage */

.stage {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  background: #0f1014;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 40%, #1b1d24 0%, #0f1014 70%);
}
#stage { display: block; touch-action: none; }

.stage-hint {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  background: rgba(28, 30, 38, 0.9);
  border: 1px solid var(--line);
  color: var(--text-dim);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  pointer-events: none;
  transition: opacity 0.4s;
}
.stage-hint.hidden { opacity: 0; }

/* --------------------------------------------------------------- filmstrip */

.filmstrip {
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 8px 12px 12px;
}
.strip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.strip-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-dim);
}
.strip-title small { text-transform: none; letter-spacing: 0; color: #6d7486; }
.strip-actions { display: flex; gap: 4px; }
.strip-actions button {
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 12px;
  padding: 5px 10px;
}

.strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.strip::-webkit-scrollbar { height: 8px; }
.strip::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; }

.frame {
  flex: 0 0 auto;
  position: relative;
  border: 2px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  cursor: pointer;
  padding: 0;
  line-height: 0;
}
.frame canvas { display: block; width: 128px; height: 80px; }
.frame.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255, 176, 32, 0.28); }
.frame.playing { border-color: var(--blue); }
.frame .num {
  position: absolute;
  left: 4px;
  top: 3px;
  background: rgba(20, 21, 26, 0.78);
  color: #fff;
  font-size: 10px;
  line-height: 1.4;
  padding: 1px 5px;
  border-radius: 5px;
}
.frame .dur {
  position: absolute;
  right: 4px;
  bottom: 3px;
  background: rgba(20, 21, 26, 0.78);
  color: #cfd3dd;
  font-size: 10px;
  line-height: 1.4;
  padding: 1px 5px;
  border-radius: 5px;
}

/* --------------------------------------------------------------- inspector */

.inspector-empty {
  color: var(--text-dim);
  font-size: 13px;
  padding: 16px 6px;
  text-align: center;
  line-height: 1.7;
}
.inspector-empty kbd { margin: 0 1px; }

.insp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.insp-title { font-weight: 650; font-size: 14px; }
.insp-sub { color: var(--text-dim); font-size: 11px; }

.field { margin-bottom: 12px; }
.field > label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  margin-bottom: 5px;
}
.field > label .val { text-transform: none; letter-spacing: 0; color: var(--text); }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  margin: 0;
}
input[type="number"], textarea, select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 9px;
  font: inherit;
}
textarea { resize: vertical; min-height: 62px; line-height: 1.4; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--blue); outline-offset: 0; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--line);
  padding: 0;
  cursor: pointer;
}
.swatch.selected { border-color: #fff; box-shadow: 0 0 0 2px var(--blue); }
.swatch.none {
  background:
    linear-gradient(45deg, transparent 44%, var(--danger) 44%, var(--danger) 56%, transparent 56%),
    var(--surface-2);
}
.swatch-custom { width: 26px; height: 26px; padding: 0; border: 1px solid var(--line); background: none; border-radius: 6px; cursor: pointer; }

.row { display: flex; gap: 6px; }
.row > * { flex: 1; }

.insp-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.insp-actions button {
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 12px;
}

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

/* ------------------------------------------------------------ modal, toast */

#modalRoot:empty { display: none; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 12, 0.72);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  width: min(560px, 100%);
  max-height: 84vh;
  overflow: auto;
  padding: 20px 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal h3 { margin: 18px 0 6px; font-size: 13px; color: var(--accent); }
.modal p { color: var(--text-dim); margin: 0 0 10px; }
.modal ul { margin: 0; padding-left: 18px; color: var(--text-dim); }
.modal li { margin-bottom: 5px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal-actions button { background: var(--surface-2); border: 1px solid var(--line); }
.modal-actions button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  border-color: transparent;
}
.modal-actions button.primary:hover { background: #ffc14d; }

kbd {
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text);
}

.export-list { display: grid; gap: 8px; }
.export-option {
  display: flex;
  gap: 12px;
  align-items: center;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 12px 14px;
  width: 100%;
}
.export-option .em { font-size: 22px; }
.export-option b { display: block; font-size: 13px; }
.export-option span { color: var(--text-dim); font-size: 12px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  background: var(--surface-3);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
  z-index: 50;
  max-width: 80vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* -------------------------------------------------------------- responsive */

@media (max-width: 1180px) {
  :root { --sidebar-left: 208px; --sidebar-right: 248px; }
  .prop-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 940px) {
  /* Narrow screens stack the three columns and let the page itself scroll,
     so the canvas keeps a usable height instead of being squeezed. */
  html, body { height: auto; overflow: auto; }
  .app { height: auto; min-height: 100%; }

  main { grid-template-columns: 1fr; grid-template-rows: none; }
  .stage { order: 1; }
  .sidebar.right { order: 2; }
  .sidebar.left { order: 3; }

  .sidebar {
    max-height: none;
    overflow: visible;
    border-left: 0;
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  .canvas-wrap { height: 52vh; min-height: 280px; }
  .logo-text { display: none; }
  .title-input { min-width: 120px; flex: 1 1 140px; }
  .prop-grid { grid-template-columns: repeat(6, 1fr); }
}

@media (max-width: 560px) {
  .btn-grid { grid-template-columns: 1fr; }
  .prop-grid { grid-template-columns: repeat(4, 1fr); }
  .insp-actions { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------ story modal */

.story-input {
  width: 100%;
  min-height: 190px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 13px;
  font: inherit;
  line-height: 1.55;
  resize: vertical;
}
.story-input:focus { outline: 2px solid var(--blue); }
.story-input::placeholder { color: #6d7486; }

.story-options { margin-top: 10px; }

.story-note {
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.6;
}
.story-note b { color: var(--text); font-weight: 600; }

/* The story modal needs room for four actions on one line. */
.modal-wide { width: min(690px, 100%); }

.story-actions { justify-content: flex-start; flex-wrap: wrap; }
.story-actions .spacer { flex: 1 1 auto; }
