/* Topometric — shell styles shared by every tool.
   Tool-specific styles live next to the tool and are loaded with it. */

:root {
  --sidebar-w: 260px;
  --page-px: 40px;
  --content-w: 960px;

  --bg: #0b0b0b;
  --sidebar-bg: #0b0b0b;
  --surface: #141414;
  --panel: #1c1c1c;
  --panel-2: #171717;
  --field: #262626;
  --active: #262626;
  --hover: rgba(255, 255, 255, .06);
  --stroke: rgba(255, 255, 255, .08);
  --stroke-strong: rgba(255, 255, 255, .16);
  --muted: #9a9a9a;
  --muted-2: #6b6b6b;
  --text: #f3f3f3;
  --text-dim: #c5c5c5;
  --accent: #f3f3f3;
  --accent-hover: #ffffff;
  --accent-soft: rgba(255, 255, 255, .1);
  --link: #7ab7ff;
  --warn: #f59e0b;
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .12);
  --ring: #7ab7ff;

  --ch-r: #f87171;
  --ch-g: #4ade80;
  --ch-b: #60a5fa;
  --ch-a: #d4d4d4;

  --radius: 10px;
  --font: ui-sans-serif, -apple-system, "Segoe UI Variable Text", "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0
}

html,
body {
  height: 100%
}

body {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
  font: 400 14px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}

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

[hidden] {
  display: none !important
}

:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px
}

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

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round
}

/* ── Buttons ── */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--stroke-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s
}

.btn:hover:not(:disabled) {
  background: var(--hover);
  border-color: var(--stroke-strong);
  color: var(--text)
}

.btn:disabled {
  opacity: .4;
  cursor: default
}

.btn[aria-pressed="true"] {
  background: var(--active);
  border-color: transparent;
  color: var(--text)
}

.btn-icon {
  width: 36px;
  padding: 0
}

.btn-ghost {
  background: transparent;
  border-color: transparent
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0b0b
}

.btn-primary:hover:not(:disabled) {
  background: #d4d4d4;
  border-color: #d4d4d4;
  color: #0b0b0b
}

.btn-danger {
  color: var(--danger)
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: rgba(248, 113, 113, .4);
  color: var(--danger)
}

/* ── Sidebar ── */
.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  background: var(--sidebar-bg);
  user-select: none
}

.sidebar-top {
  position: relative;
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  padding: 0 12px 0 20px
}

.sidebar-brand {
  display: flex;
  align-items: center;
  height: 36px;
  color: var(--text);
  text-decoration: none;
  transition: opacity .15s
}

.brand-short {
  display: none
}

.sidebar-toggle {
  color: var(--muted);
  transition: opacity .15s, background .15s, color .15s
}

.sidebar-toggle:hover:not(:disabled) {
  color: var(--text)
}

/* Collapsed sidebar: icons only and the short brand; hovering it reveals the expand button */
@media (min-width: 769px) {
  body {
    transition: grid-template-columns .2s ease
  }

  .sidebar-collapsed {
    --sidebar-w: 68px
  }

  .sidebar-collapsed .sidebar {
    overflow-x: hidden
  }

  .sidebar-collapsed .sidebar-top {
    justify-content: center;
    padding: 0
  }

  .sidebar-collapsed .brand-full,
  .sidebar-collapsed .nav-label,
  .sidebar-collapsed .footer-label {
    display: none
  }

  .sidebar-collapsed .brand-short {
    display: inline
  }

  .sidebar-collapsed .sidebar-toggle {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0
  }

  .sidebar-collapsed .sidebar-top:hover .sidebar-toggle,
  .sidebar-collapsed .sidebar-toggle:focus-visible {
    opacity: 1
  }

  .sidebar-collapsed .sidebar-top:hover .sidebar-brand,
  .sidebar-collapsed .sidebar-top:has(.sidebar-toggle:focus-visible) .sidebar-brand {
    opacity: 0
  }

  .sidebar-collapsed .sidebar-nav a,
  .sidebar-collapsed .sidebar-footer a {
    justify-content: center;
    padding: 0
  }
}

.sidebar .icon {
  width: 18px;
  height: 18px
}

.brand-name {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -.3px
}

.sidebar-nav {
  list-style: none;
  display: grid;
  gap: 2px;
  padding: 8px
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  text-decoration: none;
  transition: background .15s
}

.sidebar-nav a:hover {
  background: var(--hover)
}

.sidebar-nav a[aria-current="page"] {
  background: var(--active);
  font-weight: 500
}

.nav-label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis
}

.nav-label-short {
  display: none
}

.sidebar-footer {
  margin-top: auto;
  padding: 8px
}

.sidebar-footer a {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
  transition: background .15s, color .15s
}

.sidebar-footer a:hover {
  background: var(--hover);
  color: var(--text)
}

/* ── Main & pages ── */
.main {
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #34353f transparent;
}

.page {
  display: none
}

.page.is-active {
  display: block
}

.container {
  width: min(100%, var(--content-w));
  margin-inline: auto
}

.page-header {
  padding: 32px var(--page-px) 12px
}

.page-header h1 {
  font-size: 28px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -.4px
}

.page-header p {
  margin-top: 4px;
  color: var(--muted)
}

.page-body {
  padding: 24px var(--page-px) 64px
}

.page-status {
  padding: 48px var(--page-px);
  color: var(--muted);
  text-align: center
}

.page-status.error {
  color: var(--danger)
}

/* ── Toast ── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 32px);
  padding: 10px 20px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: var(--field);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity .2s, transform .2s;
  pointer-events: none
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto
}

.toast-action {
  appearance: none;
  padding: 0;
  border: 0;
  background: none;
  color: var(--link);
  font-weight: 600;
  cursor: pointer
}

.toast-action:hover {
  text-decoration: underline
}

/* ── Responsive ── */
@media (max-width: 1100px) {
  :root {
    --page-px: 24px
  }
}

/* Narrow screens: the sidebar becomes a top bar */
@media (max-width: 768px) {
  :root {
    --page-px: 16px
  }

  body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr)
  }

  .sidebar {
    flex-direction: row;
    align-items: center;
    gap: 4px;
    height: auto;
    padding: 0 8px 0 var(--page-px);
    overflow: visible;
    border-bottom: 1px solid var(--stroke)
  }

  .sidebar-top {
    height: 56px;
    padding: 0;
    margin-right: auto
  }

  .sidebar-toggle {
    display: none
  }

  .brand-name {
    font-size: 17px
  }

  .sidebar-nav {
    display: flex;
    padding: 0
  }

  .sidebar-nav a {
    height: 32px;
    padding: 0 10px
  }

  .sidebar-nav .icon,
  .nav-label,
  .sidebar-footer .footer-label {
    display: none
  }

  .nav-label-short {
    display: inline
  }

  .sidebar-footer {
    margin: 0;
    padding: 0;
    border: 0
  }

  .sidebar-footer a {
    width: 36px;
    padding: 0;
    justify-content: center
  }

  .page-header {
    padding-block: 24px 8px
  }

  .page-header h1 {
    font-size: 22px
  }
}

/* Very narrow: short labels don't fit, icons come back */
@media (max-width: 480px) {
  .sidebar-nav .icon {
    display: block
  }

  .nav-label-short {
    display: none
  }
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important
  }
}

.sprite {
  position: absolute;
  width: 0;
  height: 0
}

/* ── Brand typing (sidebar expand/collapse) ── */
.brand-full {
  white-space: nowrap
}

.brand-full.is-typing::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: .9em;
  margin-left: 2px;
  vertical-align: -1px;
  background: currentColor;
  animation: caret .6s steps(1) infinite
}

@keyframes caret {
  50% {
    opacity: 0
  }
}

/* ── Controls (src/core/controls.js) ── */
.ctl {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 32px
}

.ctl-label {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: none
}

.ctl-value {
  min-width: 40px;
  color: var(--text-dim);
  font: 12px var(--mono);
  text-align: right
}

.range {
  --p: 50%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  margin: 0;
  border-radius: 999px;
  background: linear-gradient(to right, var(--text-dim) var(--p), var(--field) var(--p));
  cursor: pointer
}

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 0 0 3px var(--surface);
  transition: transform .1s
}

.range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 0 0 3px var(--surface)
}

.range:active::-webkit-slider-thumb {
  transform: scale(1.2)
}

.range:focus-visible {
  outline-offset: 6px
}

.ctl-color .ctl-label {
  cursor: pointer
}

.swatch {
  width: 44px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--stroke-strong);
  border-radius: 999px;
  background: var(--c, #000);
  cursor: pointer;
  transition: border-color .15s
}

.swatch:hover,
.swatch[aria-expanded="true"] {
  border-color: var(--text-dim)
}

.ctl-seg {
  grid-template-columns: 96px minmax(0, 1fr)
}

.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--stroke-strong);
  border-radius: 999px
}

.seg button {
  flex: 1;
  height: 26px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: 500 12px var(--font);
  white-space: nowrap;
  cursor: pointer
}

.seg button:hover {
  color: var(--text)
}

.seg button[aria-pressed="true"] {
  background: var(--active);
  color: var(--text)
}

.ctl-toggle {
  grid-template-columns: 96px auto
}

.switch {
  position: relative;
  width: 36px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--field);
  cursor: pointer;
  transition: background .15s
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .15s, background .15s
}

.switch[aria-checked="true"] {
  background: var(--text-dim)
}

.switch[aria-checked="true"]::after {
  background: var(--bg);
  transform: translateX(16px)
}

/* ── Color picker (src/core/color-picker.js) ── */
.cp {
  position: fixed;
  z-index: 200;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  width: 248px;
  padding: 16px;
  border: 1px solid var(--stroke);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 24px 64px rgba(0, 0, 0, .6)
}

.cp-wheel {
  position: relative;
  justify-self: center;
  width: 184px;
  height: 184px;
  margin-bottom: 4px;
  border-radius: 50%;
  cursor: crosshair;
  touch-action: none
}

.cp-wheel:focus-visible {
  outline-offset: 4px
}

.cp-wheel canvas {
  display: block;
  width: 100%;
  height: 100%
}

.cp-marker {
  position: absolute;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .5);
  pointer-events: none
}

.cp-strip {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) 38px;
  gap: 10px;
  align-items: center
}

.cp-strip-label {
  color: var(--muted);
  font: 600 11px var(--mono)
}

.cp-strip-value {
  color: var(--text-dim);
  font: 11px var(--mono);
  text-align: right
}

.cp-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 12px;
  margin: 0;
  border-radius: 999px;
  background: var(--track, var(--field));
  cursor: pointer
}

.cp-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: transparent;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .5)
}

.cp-range::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: transparent;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .6)
}

.cp-range::-moz-range-track {
  background: transparent
}

.cp-foot {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px
}

.cp-compare {
  display: flex;
  flex: none;
  width: 56px;
  height: 32px;
  overflow: hidden;
  border: 1px solid var(--stroke-strong);
  border-radius: 999px
}

.cp-new,
.cp-old {
  flex: 1
}

.cp-old {
  padding: 0;
  border: 0;
  cursor: pointer
}

.cp-hex {
  flex: 1;
  width: 0;
  min-width: 0;
  height: 32px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--field);
  font: 600 12px var(--mono);
  letter-spacing: .5px;
  text-transform: uppercase
}

.cp-hex:focus {
  outline: none;
  border-color: var(--stroke-strong)
}

.cp-hex.is-invalid {
  border-color: var(--danger)
}

.cp-pick {
  flex: none;
  width: 32px;
  height: 32px
}

/* ── Viewer tools (Kuwahator, Tile Maker): a zoomable image view with a settings panel ── */
.vw-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  align-items: start
}

.vw-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--stroke);
  border-radius: 18px;
  background: var(--surface)
}

.vw-stage {
  position: sticky;
  top: 20px
}

.vw-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px
}

/* ── Viewer bar ── */
.vw-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center
}

.vw-open {
  height: 34px;
  font-size: 13px
}

.vw-open .icon {
  width: 16px;
  height: 16px
}

.vw-group {
  display: flex;
  gap: 2px;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--stroke-strong);
  border-radius: 999px
}

.vw-group button,
.vw-toggle {
  height: 26px;
  min-width: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: 600 12px var(--mono);
  cursor: pointer
}

.vw-group button:hover:not(:disabled),
.vw-toggle:hover {
  color: var(--text)
}

.vw-group button[aria-pressed="true"],
.vw-toggle[aria-pressed="true"] {
  background: var(--active);
  color: var(--text)
}

.vw-group button:disabled {
  opacity: .35;
  cursor: default
}

.vw-group output {
  min-width: 52px;
  padding: 0 8px 0 4px;
  color: var(--text-dim);
  font: 12px var(--mono);
  text-align: right
}

.vw-toggle {
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--stroke-strong)
}

.vw-toggle[aria-pressed="true"] {
  border-color: transparent
}

.vw-chips {
  margin-left: auto
}

/* ── View ── */
.vw-view {
  position: relative;
  height: max(360px, calc(100vh - 250px));
  overflow: hidden;
  border-radius: 12px;
  background: #0e0e0e;
  touch-action: none;
  user-select: none
}

.vw-view canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab
}

.vw-view canvas.is-panning {
  cursor: grabbing
}

.vw-view.is-dragover {
  outline: 2px dashed var(--text-dim);
  outline-offset: -6px
}

.vw-msg {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center
}

/* Filtering progress: a thin line along the top edge */
.vw-progress {
  --p: 0;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--text-dim);
  opacity: 0;
  transform: scaleX(var(--p));
  transform-origin: left;
  transition: opacity .3s;
  pointer-events: none
}

.vw-progress.is-on {
  opacity: .8;
  transition-delay: .15s
}

/* Before / after divider */
.vw-split {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 1px solid rgba(255, 255, 255, .7);
  pointer-events: none
}

.vw-split[hidden] {
  display: none
}

.vw-split-label {
  position: absolute;
  top: 10px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font: 600 11px var(--mono);
  white-space: nowrap
}

.vw-split-label.is-before {
  right: 10px
}

.vw-split-label.is-after {
  left: 10px
}

.vw-split-knob {
  position: absolute;
  top: 50%;
  left: 0;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23fff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpath d='m9 6-6 6 6 6M15 6l6 6-6 6'/%3E%3C/svg%3E") no-repeat center;
  cursor: ew-resize;
  pointer-events: auto;
  touch-action: none
}

.vw-hint,
.vw-tip {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5
}

.vw-hint {
  text-align: center
}

/* ── Panel ── */
.vw-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600
}

.vw-reset {
  height: 28px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px
}

.vw-save {
  display: flex;
  gap: 8px
}

.vw-name {
  display: flex;
  flex: 1;
  align-items: center;
  min-width: 0;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--stroke-strong);
  border-radius: 999px;
  background: var(--field);
  font: 13px var(--mono)
}

.vw-name input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: none;
  font: inherit
}

.vw-name span {
  color: var(--muted)
}

.vw-name:focus-within {
  border-color: var(--ring)
}

.vw-format {
  display: block;
  flex: none;
  min-height: 0
}

.vw-format .seg button {
  font-family: var(--mono)
}

.vw-dl .icon {
  width: 16px;
  height: 16px
}

@media (max-width: 1000px) {
  .vw-layout {
    grid-template-columns: minmax(0, 1fr)
  }

  .vw-stage {
    position: static
  }

  .vw-view {
    height: min(70vh, 640px)
  }
}

@media (max-width: 480px) {
  .vw-card {
    padding: 12px
  }

  .vw-card .ctl {
    grid-template-columns: 84px minmax(0, 1fr) auto
  }

  .vw-card .ctl-seg {
    grid-template-columns: 84px minmax(0, 1fr)
  }

  .vw-chips {
    margin-left: 0
  }
}
