:root {
  --surface: #15171b;
  --panel: #1c1f24;
  --raised: #262a31;
  --border: #33383f;
  --text: #e3e6ea;
  --muted: #8d949e;
  --accent: #5b9dff;
  --accent-text: #0d1420;
  --danger: #ff6b6b;
  --ok: #69db7c;
  --radius: 6px;
  color-scheme: dark;
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) 360px;
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
}

h1, h2, h3 {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

button, input, textarea {
  font: inherit;
  color: inherit;
}

button {
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 9px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  border-color: var(--muted);
}

button.on, .segmented button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

textarea, input[type="text"] {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  resize: vertical;
}

textarea:focus, input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

/* Character list */

#characters {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 12px 8px;
  overflow-y: auto;
}

#character-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

#character-list button {
  width: 100%;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 4px;
  text-align: left;
  background: transparent;
  border-color: transparent;
}

#character-list button.current {
  background: var(--raised);
  border-color: var(--border);
}

#character-list img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  background: #2b2f36;
  border-radius: 4px;
}

#character-list .name {
  font-weight: 600;
}

#character-list .meta {
  color: var(--muted);
  font-size: 11px;
}

.badge {
  background: var(--danger);
  color: #1a0b0b;
  border-radius: 9px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
}

/* Stage */

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

#toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.spacer {
  flex: 1;
}

.segmented {
  display: inline-flex;
}

.segmented button {
  border-radius: 0;
  margin-left: -1px;
}

.segmented button:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
  margin-left: 0;
}

.segmented button:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
}

#viewport {
  position: relative;
  overflow: hidden;
  min-height: 0;
}

#viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#viewport.brushing canvas {
  cursor: none;
}

#labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.label {
  position: absolute;
  left: 0;
  top: 0;
  min-width: 22px;
  height: 22px;
  padding: 0 4px;
  border-radius: 11px;
  border: 2px solid #fff;
  color: #101216;
  font-weight: 700;
  font-size: 11px;
  display: grid;
  place-items: center;
  margin: -11px 0 0 -11px;
}

.label.saved {
  border-style: dashed;
}

#brush-cursor {
  position: absolute;
  left: 0;
  top: 0;
  border: 2px solid;
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.5);
}

#brush-cursor.erasing {
  border-style: dashed;
}

#stats, #hint {
  position: absolute;
  left: 10px;
  padding: 4px 8px;
  border-radius: var(--radius);
  background: rgb(10 12 15 / 0.65);
  color: #cfd4da;
  font-size: 12px;
  pointer-events: none;
}

#stats {
  top: 10px;
  font-variant-numeric: tabular-nums;
}

#hint {
  bottom: 10px;
  right: 10px;
  left: 10px;
  width: fit-content;
  max-width: calc(100% - 20px);
}

#loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  justify-items: center;
  background: rgb(10 12 15 / 0.4);
}

#loading .bar {
  width: 240px;
  height: 6px;
  border-radius: 3px;
  background: var(--raised);
  overflow: hidden;
}

#loading .bar div {
  height: 100%;
  width: 0;
  background: var(--accent);
}

#shown-banner {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 4px 4px 4px 10px;
  border-radius: var(--radius);
  background: rgb(10 12 15 / 0.75);
}

#pinned {
  position: absolute;
  right: 10px;
  bottom: 44px;
  width: 260px;
  height: 320px;
  min-width: 80px;
  min-height: 80px;
  resize: both;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgb(10 12 15 / 0.75);
  direction: rtl;
}

#pinned img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  direction: ltr;
}

#pinned .close {
  position: absolute;
  top: 4px;
  left: 4px;
  padding: 0 6px;
}

[hidden] {
  display: none !important;
}

/* Side panel */

#panel {
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

#panel section {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.thumbs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.thumbs button {
  padding: 0;
  overflow: hidden;
  background: #2b2f36;
  display: grid;
}

.thumbs img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
}

.thumbs span {
  font-size: 11px;
  color: var(--muted);
  padding: 2px 4px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
}

#details {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

#details dt {
  color: var(--muted);
}

#details dd {
  margin: 0;
}

#details .heading {
  grid-column: 1 / -1;
  margin-top: 6px;
  color: var(--text);
  font-weight: 600;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.swatch {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid rgb(255 255 255 / 0.25);
  display: inline-block;
}

#feedback {
  display: grid;
  gap: 8px;
}

#clip-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: grid;
  gap: 4px;
}

#clip-list button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

#clip-list .length {
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
}

.animation-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

#animation-readout {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

#animation-time {
  width: 100%;
}

#animation-markers {
  position: relative;
  height: 20px;
}

#animation-markers button {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  padding: 0 5px;
  font-size: 11px;
  line-height: 17px;
}

.brush-bar, .group-bar, .send-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.brush-bar label {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.brush-bar input[type="range"] {
  flex: 1;
  min-width: 0;
}

#groups, #history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.group {
  border: 1px solid var(--border);
  border-left: 4px solid var(--group-color);
  border-radius: var(--radius);
  padding: 6px;
  display: grid;
  gap: 6px;
  background: var(--surface);
}

.group.active {
  border-color: var(--group-color);
  box-shadow: 0 0 0 1px var(--group-color);
}

.group-head {
  display: flex;
  align-items: center;
  gap: 6px;
}

.group-head input {
  flex: 1;
  min-width: 0;
}

.group-head .count {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.group-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.group-actions button {
  padding: 2px 7px;
  font-size: 12px;
}

.empty {
  color: var(--muted);
  font-size: 12px;
}

.check, .file {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.file input {
  min-width: 0;
  flex: 1;
}

#send-status.error {
  color: var(--danger);
}

#send-status.ok {
  color: var(--ok);
}

.entry {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  display: grid;
  gap: 6px;
  background: var(--surface);
}

.entry-head {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.entry-head strong {
  color: var(--text);
}

.status {
  margin-left: auto;
  border-radius: 9px;
  padding: 0 7px;
  font-size: 11px;
  font-weight: 600;
}

.status.open {
  background: #4a3b12;
  color: #ffd43b;
}

.status.answered {
  background: #173a22;
  color: var(--ok);
}

.entry p {
  margin: 0;
  white-space: pre-wrap;
}

.entry ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 3px;
}

.entry li {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 6px;
  align-items: start;
}

.entry li .swatch {
  width: 12px;
  height: 12px;
  margin-top: 3px;
}

.entry .images {
  display: flex;
  gap: 6px;
}

.entry .images button {
  padding: 0;
  width: 72px;
  height: 54px;
  overflow: hidden;
}

.entry .images img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reply {
  border-left: 3px solid var(--ok);
  padding-left: 8px;
  white-space: pre-wrap;
}

/* Lightbox */

#lightbox {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgb(5 6 8 / 0.92);
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

#lightbox .stage {
  position: relative;
  overflow: hidden;
  cursor: grab;
}

#lightbox .stage img {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  user-select: none;
  -webkit-user-drag: none;
  image-rendering: auto;
}

.lightbox-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--panel);
}

.lightbox-bar .caption {
  flex: 1;
  text-align: center;
  color: var(--muted);
}

#lightbox.single .prev, #lightbox.single .next {
  visibility: hidden;
}

@media (max-width: 1100px) {
  body {
    grid-template-columns: 160px minmax(0, 1fr) 300px;
  }
}

.swatch-button {
  min-width: 24px;
  padding: 2px 6px;
  border: none;
  color: #101216;
  font-weight: 700;
}
