/* The look, in the shape shadcn/ui uses and the work board adopted: colour roles
 * held as HSL channels, one radius, a handful of parts (button, input, card,
 * chip) that every screen is built from.
 *
 * Colours are stored as bare channels ("240 10% 3.9%") and always used through
 * `hsl(var(--token))`, so any colour can take an alpha at the point of use.
 *
 * Self-contained, like every web-project: no shared tokens, no web font.
 */

:root {
  color-scheme: light dark;

  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --success: 142 71% 35%;
  --warning: 32 95% 44%;
  --destructive: 0 72% 45%;
  --destructive-foreground: 0 0% 98%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 240 10% 3.9%;
  --highlight: 42 90% 50%;

  --radius: 0.625rem;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --shadow-sm: 0 1px 2px 0 hsl(var(--foreground) / 0.05);
  --shadow: 0 1px 3px 0 hsl(var(--foreground) / 0.07), 0 1px 2px -1px hsl(var(--foreground) / 0.07);
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: 240 10% 3.9%;
    --foreground: 0 0% 98%;
    --card: 240 7% 6.5%;
    --muted: 240 4% 12%;
    --muted-foreground: 240 5% 64.9%;
    --accent: 240 4% 14%;
    --accent-foreground: 0 0% 98%;
    --primary: 0 0% 98%;
    --primary-foreground: 240 5.9% 10%;
    --success: 142 60% 45%;
    --warning: 32 95% 55%;
    --destructive: 0 70% 58%;
    --destructive-foreground: 240 10% 3.9%;
    --border: 240 4% 16%;
    --input: 240 4% 18%;
    --ring: 240 5% 70%;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.4);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.5), 0 1px 2px -1px rgb(0 0 0 / 0.4);
  }
}

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

/* A `hidden` attribute must win over any `display` a class sets, or a hidden
 * flex row stays on screen. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: var(--font);
  font-size: 0.9375rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 76rem;
  margin: 0 auto;
  padding: 1rem 1.25rem 4rem;
}

/* -------------------------------------------------------------------------- */
/* Type                                                                       */
/* -------------------------------------------------------------------------- */

h1,
h2,
h3 {
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin: 0;
}

h1 {
  font-size: 1.75rem;
  font-weight: 650;
}

h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

h3 {
  font-size: 0.9375rem;
  font-weight: 600;
}

p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  text-decoration-color: hsl(var(--muted-foreground) / 0.6);
}

a:hover {
  text-decoration-color: currentColor;
}

code,
.mono {
  font-family: var(--mono);
  font-size: 0.85em;
}

.muted {
  color: hsl(var(--muted-foreground));
}

.tagline,
.lead,
.field-help {
  color: hsl(var(--muted-foreground));
}

.lead {
  margin-top: 0.35rem;
}

.field-help {
  font-size: 0.8125rem;
  line-height: 1.5;
  margin-top: 0.35rem;
}

/* -------------------------------------------------------------------------- */
/* Masthead and screens                                                       */
/* -------------------------------------------------------------------------- */

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0 1.25rem;
}

.masthead-title {
  max-width: 40rem;
}

.views {
  display: inline-flex;
  padding: 0.25rem;
  gap: 0.25rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) + 0.25rem);
  background: hsl(var(--muted) / 0.6);
}

.view-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: hsl(var(--muted-foreground));
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.view-tab:hover {
  color: hsl(var(--foreground));
}

.view-tab:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 1px;
}

.view-tab[aria-current="page"] {
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  box-shadow: var(--shadow-sm);
}

.view-tab:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.view {
  display: grid;
  gap: 1rem;
}

/* -------------------------------------------------------------------------- */
/* Cards, panels, fields                                                      */
/* -------------------------------------------------------------------------- */

.card,
.panel {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 1.25rem 1.25rem 0;
}

.card-content {
  padding: 1.25rem;
  display: grid;
  gap: 1rem;
}

.card-quiet summary {
  padding: 0.9rem 1.25rem;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}

.card-quiet summary::before {
  content: "▸ ";
  color: hsl(var(--muted-foreground));
}

.card-quiet[open] summary::before {
  content: "▾ ";
}

.card-quiet .card-content {
  padding-top: 0;
  color: hsl(var(--muted-foreground));
}

.panel {
  padding: 1rem;
  display: grid;
  gap: 0.6rem;
}

.field {
  display: grid;
  gap: 0.35rem;
}

.field-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: hsl(var(--foreground));
}

.field-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.field-row .input {
  flex: 1;
}

.field-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
}

.input,
.select {
  width: 100%;
  font: inherit;
  color: hsl(var(--foreground));
  background: hsl(var(--background));
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 0.2rem);
  padding: 0.5rem 0.75rem;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

textarea.input {
  resize: vertical;
  min-height: 4.5rem;
}

.input:hover,
.select:hover {
  border-color: hsl(var(--ring) / 0.5);
}

.input:focus,
.select:focus-visible {
  outline: none;
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.15);
}

.input-small {
  width: 5.5rem;
  flex: 0 0 auto;
}

.times {
  color: hsl(var(--muted-foreground));
}

.input-code {
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.45;
  min-height: 12rem;
  white-space: pre;
  overflow: auto;
}

/* A collapsed field: the summary line carries the label and the one-line state. */
.details-field {
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 0.2rem);
}

.details-field summary {
  list-style: none;
  cursor: pointer;
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  align-items: baseline;
}

.details-field summary::before {
  content: "▸";
  color: hsl(var(--muted-foreground));
}

.details-field[open] summary::before {
  content: "▾";
}

.details-field summary .field-help {
  margin-top: 0;
  flex: 1 1 12rem;
}

.details-field summary:hover {
  background: hsl(var(--accent) / 0.6);
}

.details-field summary:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: -2px;
}

.details-body {
  padding: 0 0.75rem 0.75rem;
  display: grid;
  gap: 0.6rem;
}

.status-list {
  color: hsl(var(--destructive));
  font-size: 0.8125rem;
}

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

.style-control {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.style-control .select {
  width: auto;
  padding: 0.4rem 0.6rem;
  font-size: 0.875rem;
}

.check {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.875rem;
}

.check input {
  width: 1rem;
  height: 1rem;
  accent-color: hsl(var(--primary));
}

/* -------------------------------------------------------------------------- */
/* Buttons and chips                                                          */
/* -------------------------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 0.95rem;
  border-radius: calc(var(--radius) - 0.2rem);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, transform 80ms ease;
}

.button:active {
  transform: translateY(1px);
}

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

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.button-primary {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

.button-primary:hover {
  background: hsl(var(--primary) / 0.88);
}

.button-outline {
  background: hsl(var(--background));
  border-color: hsl(var(--border));
  color: hsl(var(--foreground));
}

.button-outline:hover {
  background: hsl(var(--accent));
}

.button-danger {
  background: transparent;
  border-color: hsl(var(--destructive) / 0.5);
  color: hsl(var(--destructive));
}

.button-danger:hover {
  background: hsl(var(--destructive) / 0.1);
}

.button-icon {
  width: 2.25rem;
  padding: 0.5rem 0;
  font-size: 1.1rem;
}

.file-button {
  position: relative;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.actions-tight {
  margin-top: 0.25rem;
}

.step-action {
  margin-top: 0.5rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip {
  font: inherit;
  font-size: 0.8125rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.chip:hover {
  background: hsl(var(--accent));
}

.chip:active {
  background: hsl(var(--accent) / 0.7);
}

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

.chip[aria-pressed="true"] {
  background: hsl(var(--primary));
  border-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

/* -------------------------------------------------------------------------- */
/* Steps and status                                                           */
/* -------------------------------------------------------------------------- */

.steps {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
  display: grid;
  gap: 1.25rem;
}

.steps > li {
  counter-increment: step;
  position: relative;
  padding-left: 2.5rem;
  display: grid;
  gap: 0.5rem;
}

.steps > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 0.8125rem;
  font-weight: 600;
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}

.status {
  font-size: 0.875rem;
  min-height: 1.4em;
  color: hsl(var(--muted-foreground));
}

.status[data-tone="ok"] {
  color: hsl(var(--success));
}

.status[data-tone="warn"] {
  color: hsl(var(--warning));
}

.status[data-tone="error"] {
  color: hsl(var(--destructive));
}

.plain-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.875rem;
  display: grid;
  gap: 0.2rem;
}

/* -------------------------------------------------------------------------- */
/* The map screen                                                             */
/* -------------------------------------------------------------------------- */

.map-layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1fr) 20rem;
  align-items: start;
}

.map-column {
  display: grid;
  gap: 0.6rem;
  min-width: 0;
}

.map-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.map-title {
  min-width: 0;
  flex: 1 1 16rem;
}

.world-summary {
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
}

.toolbar-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.canvas-wrap {
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  overflow: hidden;
  background: #0b0b0d;
  box-shadow: var(--shadow);
}

.map-canvas {
  display: block;
  width: 100%;
  height: min(70vh, 44rem);
  cursor: grab;
  touch-action: none;
}

.map-canvas.is-dragging {
  cursor: grabbing;
}

.progress {
  height: 0.35rem;
  border-radius: 999px;
  background: hsl(var(--muted));
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: hsl(var(--highlight));
  transition: width 120ms linear;
}

.map-sidebar {
  display: grid;
  gap: 0.75rem;
  min-width: 0;
}

.inspector-head {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.inspector-tile {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border-radius: calc(var(--radius) - 0.2rem);
  background: #0b0b0d;
  flex: 0 0 auto;
}

.inspector-tile canvas {
  width: 2.5rem;
  height: 2.5rem;
  image-rendering: pixelated;
}

.inspector-label {
  font-weight: 600;
}

.inspector-text {
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
  margin-top: 0.5rem;
}

.properties {
  margin: 0.5rem 0 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.75rem;
  font-size: 0.8125rem;
}

.properties dt {
  color: hsl(var(--muted-foreground));
}

.properties dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.legend {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.3rem;
}

.legend li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.8125rem;
  padding: 0.25rem 0.35rem;
  border-radius: calc(var(--radius) - 0.3rem);
}

.legend li:hover {
  background: hsl(var(--accent));
}

.legend .tile-thumb {
  width: 1.5rem;
  height: 1.5rem;
  image-rendering: pixelated;
  border-radius: 3px;
  background: #0b0b0d;
}

.legend .legend-flags {
  color: hsl(var(--muted-foreground));
  font-size: 0.75rem;
}

.legend .legend-count {
  color: hsl(var(--muted-foreground));
  font-variant-numeric: tabular-nums;
}

.log {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.15rem;
  max-height: 14rem;
  overflow: auto;
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

.log li[data-tone="warn"] {
  color: hsl(var(--warning));
}

.log li[data-tone="error"] {
  color: hsl(var(--destructive));
}

/* -------------------------------------------------------------------------- */
/* Footer                                                                     */
/* -------------------------------------------------------------------------- */

.footer {
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid hsl(var(--border));
  display: grid;
  gap: 0.35rem;
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
}

/* -------------------------------------------------------------------------- */
/* Small screens and quiet motion                                             */
/* -------------------------------------------------------------------------- */

@media (max-width: 60rem) {
  .map-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .map-canvas {
    height: min(60vh, 30rem);
  }
}

@media (max-width: 30rem) {
  .page {
    padding: 0.75rem 1rem 3rem;
  }

  h1 {
    font-size: 1.5rem;
  }

  .views {
    width: 100%;
    justify-content: space-between;
  }

  .view-tab {
    flex: 1;
    padding: 0.4rem 0.5rem;
    font-size: 0.8125rem;
  }

  .card-header,
  .card-content {
    padding: 1rem;
  }

  .map-canvas {
    height: 60vw;
  }
}

@media (prefers-reduced-motion: reduce) {
  .button,
  .chip,
  .view-tab,
  .input,
  .select,
  .progress-bar {
    transition-duration: 0ms;
  }
}
