:root {
  --bg: #14161b;
  --panel: #1b1e25;
  --panel-2: #20232b;
  --border: #2c303a;
  --text: #eef0f3;
  --text-dim: #9aa1ad;
  --accent: #ff7a45;
  --accent-ink: #1b1206;
  --rail-w: 64px;
  --radius: 12px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
}

h3,
.options-header,
.brand-title {
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
}

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

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ---------------------------------------------------------------- toolbar */

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 16px;
  height: 58px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: 4px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  flex: 0 0 auto;
  display: inline-block;
}

.brand-title {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.1;
}

.brand-subtitle {
  color: var(--text-dim);
  font-size: 10.5px;
  line-height: 1.1;
}

.toolbar .sep {
  width: 1px;
  align-self: stretch;
  margin: 10px 8px;
  background: var(--border);
}

.toolbar .spacer {
  flex: 1 1 auto;
}

.tb-btn {
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 8px 11px;
  cursor: pointer;
  color: var(--text-dim);
  white-space: nowrap;
}

.tb-btn:hover {
  background: var(--panel-2);
  color: var(--text);
}

.tb-cta {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  padding: 9px 16px;
}

.tb-cta:hover {
  background: var(--accent);
  filter: brightness(1.08);
  color: var(--accent-ink);
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 14px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  white-space: nowrap;
}

.pill-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 11.5px;
}

.pill-btn:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

.layer-toggle {
  display: flex;
  gap: 2px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.layer-toggle label {
  display: block;
  position: relative;
}

.layer-toggle input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.layer-toggle span {
  display: block;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12px;
}

.layer-toggle input:checked + span {
  background: var(--accent);
  color: var(--accent-ink);
}

/* ------------------------------------------------------------------ body */

.body {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  position: relative;
}

/* ------------------------------------------------------------- tool rail */

.tool-rail {
  width: var(--rail-w);
  flex: 0 0 auto;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 0;
  z-index: 6;
}

.rail-btn {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-dim);
}

.rail-btn:hover {
  background: var(--panel-2);
}

.rail-btn input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.rail-btn .icon {
  font-size: 18px;
  line-height: 1;
}

.rail-btn input:checked ~ .icon {
  color: var(--accent-ink);
}

.rail-btn:has(input:checked) {
  background: var(--accent);
  color: var(--accent-ink);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* -------------------------------------------------------------- canvas */

.canvas-wrap {
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
  background-color: #191c22;
  background-image: linear-gradient(60deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(-60deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-size: 64px 37px;
  overflow: hidden;
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
}

/* ------------------------------------------------------------ floating panels */

.floating-panel {
  position: absolute;
  background: rgba(27, 30, 37, 0.94);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
  padding: 14px;
  z-index: 5;
}

.options-float {
  top: 16px;
  left: 16px;
  width: 246px;
  max-height: calc(100% - 32px);
  overflow-y: auto;
}

.legend-float {
  left: 16px;
  bottom: 16px;
  width: 220px;
  max-height: 40%;
  overflow-y: auto;
}

.options-header {
  font-weight: 600;
  font-size: 12.5px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-label {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 10px 0 4px;
}

.icon-btn {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}

/* ----------------------------------------------------------- tool options */

.swatch-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
}

.swatch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 7px;
  border-radius: 8px;
  cursor: pointer;
}

.swatch-row:hover {
  background: var(--panel-2);
}

.swatch-row.selected {
  background: rgba(255, 122, 69, 0.14);
  outline: 1px solid var(--accent);
}

.swatch {
  width: 22px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  flex: 0 0 auto;
}

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

.btn-row button,
.popover-body button,
#options-paint button,
#options-arrow button {
  flex: 1 1 auto;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

.btn-row button:hover {
  border-color: var(--text-dim);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 6px 0;
  color: var(--text-dim);
}

.row input[type="number"],
.row input[type="text"] {
  width: 56px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 4px 6px;
}

.hint {
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.5;
  margin: 8px 0 0;
}

.dir-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.dir-grid label {
  display: block;
  position: relative;
}

.dir-grid input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.dir-grid span {
  display: block;
  text-align: center;
  padding: 7px 0;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text-dim);
}

.dir-grid input:checked + span {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 700;
}

/* ----------------------------------------------------------------- legend */

.legend {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-swatch {
  width: 13px;
  height: 10px;
  border-radius: 2px;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.legend-heading {
  color: var(--text-dim);
  margin-top: 8px;
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.04em;
}

.legend-muted {
  color: var(--text-dim);
}

/* ------------------------------------------------------------ sprite drawer */

.sprite-drawer {
  position: static;
  width: 230px;
  flex: 0 0 auto;
  margin: 16px 16px 16px 0;
  display: flex;
  flex-direction: column;
  max-height: calc(100% - 32px);
}

.sprite-list {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 4px 0 8px;
}

.sprite-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 8px;
  cursor: pointer;
}

.sprite-row:hover {
  background: var(--panel-2);
}

.sprite-row.selected {
  background: rgba(255, 122, 69, 0.14);
  outline: 1px solid var(--accent);
}

.sprite-row img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex: 0 0 auto;
  background: var(--panel-2);
  border-radius: 6px;
}

.sprite-row .name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sprite-row .remove {
  flex: 0 0 auto;
  border: none;
  background: none;
  cursor: pointer;
  color: #ff8a8a;
  font-weight: bold;
}

/* ------------------------------------------------------------- status bar */

.status-bar {
  flex: 0 0 auto;
  padding: 5px 14px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11.5px;
}

/* ---------------------------------------------------------------- popovers */

.popover {
  position: fixed;
  background: var(--accent);
  padding: 1px;
  border-radius: 12px;
  z-index: 50;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
}

.popover-body {
  background: var(--panel);
  color: var(--text);
  border-radius: 11px;
  min-width: 220px;
  padding: 12px 14px;
}

.popover-body h4 {
  margin: 0 0 8px;
  font-size: 13px;
  font-family: "Space Grotesk", sans-serif;
}

.popover-body input[type="number"],
.popover-body input[type="text"] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 4px 6px;
  width: 70px;
}

.popover-buttons {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.popover-buttons button {
  flex: 1 1 auto;
  padding: 6px 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

.popover-buttons button:last-child:not(:only-child) {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 700;
}

.type-pick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  cursor: pointer;
  border-radius: 8px;
}

.type-pick-row:hover {
  background: var(--panel-2);
}

.type-pick-row.selected {
  background: rgba(255, 122, 69, 0.14);
  outline: 1px solid var(--accent);
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  max-width: 92vw;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal img,
.modal canvas {
  max-width: 100%;
  max-height: 78vh;
  display: block;
  border-radius: 6px;
}

.modal .modal-caption {
  color: var(--text-dim);
  text-align: center;
  font-size: 12px;
}

.modal .modal-close {
  align-self: flex-end;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
}
