:root {
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  --font-display: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  --font-body: "Trebuchet MS", "Gill Sans", Verdana, sans-serif;
  --font-mono: "Courier New", "Nimbus Mono PS", monospace;

  --paper: #f4ead0;
  --paper-deep: #ece0c2;
  --ink: #26231f;
  --ink-soft: rgba(38, 35, 31, 0.72);
  --line: rgba(38, 35, 31, 0.2);
  --panel: rgba(255, 251, 240, 0.92);
  --panel-strong: #fffaf0;
  --shadow: rgba(64, 47, 20, 0.14);

  --accent: #c65a2e;
  --accent-strong: #a8461f;
  --water: #4a90a4;
  --ok: #4e7c4a;
  --warn: #c65a2e;

  --status-available: #f4c453;
  --status-held: #ec9a3c;
  --status-reserved: #e06b3f;
  --status-sold: #8a8578;
  --status-blocked: #3c382f;

  --radius: 6px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--font-body);
  background: linear-gradient(160deg, var(--paper), var(--paper-deep) 70%);
}

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

button {
  cursor: pointer;
}

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

.skip-link {
  position: absolute;
  top: -48px;
  left: 12px;
  z-index: 100;
  padding: 10px 16px;
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  transition: top 160ms var(--ease-out);
}

.skip-link:focus {
  top: 12px;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  opacity: 0.05;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.86' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.72'/%3E%3C/svg%3E");
}

a {
  color: inherit;
}

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

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 2px solid var(--ink);
  background: var(--panel-strong);
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar__brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.kicker {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.brand-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.4rem;
}

.stamp {
  padding: 2px 8px;
  border: 2px dashed var(--accent);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: var(--accent-strong);
}

.topbar__event {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.event-meta {
  margin: 0;
  font-size: 0.86rem;
  color: var(--ink-soft);
}

.topbar__right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.mode-switch {
  display: inline-flex;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  overflow: hidden;
}

.mode-switch__btn {
  border: none;
  background: var(--panel);
  padding: 8px 14px;
  font-size: 0.86rem;
  font-weight: 600;
}

.mode-switch__btn + .mode-switch__btn {
  border-left: 2px solid var(--ink);
}

.mode-switch__btn.is-active {
  background: var(--ink);
  color: var(--paper);
}

.state-chips {
  display: flex;
  gap: 8px;
}

.chip {
  padding: 4px 10px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background: var(--panel);
}

.chip--warn {
  border-color: var(--warn);
  color: var(--accent-strong);
}

.chip--live {
  border-color: var(--ok);
  color: var(--ok);
}

/* ---------- Layout shells ---------- */

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.workspace {
  display: grid;
  grid-template-columns: 290px minmax(360px, 1fr) 300px;
  gap: 16px;
  align-items: start;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 3px 4px 0 var(--shadow);
  padding: 16px;
}

.panel--tall {
  height: 100%;
}

.panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
}

.panel__note {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--ink-soft);
}

.link-btn {
  border: none;
  background: none;
  padding: 0;
  font-size: 0.78rem;
  text-decoration: underline;
  color: var(--accent-strong);
}

/* ---------- Fields & controls ---------- */

.field {
  display: block;
  margin-bottom: 12px;
}

.field:last-child {
  margin-bottom: 0;
}

.field--inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0;
}

.field__label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.field--inline .field__label {
  margin-bottom: 0;
}

.control {
  width: 100%;
  padding: 8px 10px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: var(--panel-strong);
  font-size: 0.9rem;
}

.control--strong {
  font-weight: 600;
}

.control--file {
  padding: 6px;
  border-style: dashed;
}

textarea.control {
  resize: vertical;
}

.hint {
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: var(--ink-soft);
  line-height: 1.4;
}

.hint code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.map-current {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 0.84rem;
}

.map-current__label {
  color: var(--ink-soft);
}

.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.btn-row--end {
  justify-content: flex-end;
}

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  padding: 9px 14px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: var(--panel-strong);
  font-size: 0.86rem;
  font-weight: 600;
  transition: transform 140ms var(--ease-out), background 140ms var(--ease-out);
}

.btn:hover {
  transform: translateY(-1px);
}

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

.btn--ghost {
  background: transparent;
}

.btn--danger {
  background: var(--warn);
  border-color: var(--accent-strong);
  color: #fff8ec;
}

.btn--danger-ghost {
  background: transparent;
  border-color: var(--warn);
  color: var(--accent-strong);
}

/* ---------- Tool switch ---------- */

.tool-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tool-switch__btn {
  padding: 9px 8px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: var(--panel-strong);
  font-size: 0.82rem;
}

.tool-switch__btn.is-active {
  background: var(--ink);
  color: var(--paper);
}

/* ---------- Filters ---------- */

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 0;
  padding: 0;
  border: none;
}

.checks legend {
  width: 100%;
  margin-bottom: 4px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
}

.check__swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 1px solid var(--ink);
  display: inline-block;
}

/* ---------- Stage / map canvas ---------- */

.stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 3px 4px 0 var(--shadow);
  padding: 16px;
}

.stage__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.stage__count {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.map-frame {
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: repeating-conic-gradient(var(--paper-deep) 0% 25%, var(--panel-strong) 0% 50%) 50% / 22px 22px;
  padding: 8px;
}

.map-surface {
  position: relative;
  width: 100%;
  aspect-ratio: var(--map-ratio, 3 / 4);
  max-height: 68vh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--panel-strong);
  touch-action: none;
}

.map-surface.is-empty {
  display: grid;
  place-items: center;
  min-height: 320px;
}

.map-surface.is-empty::before {
  content: "Nothing published yet";
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--ink-soft);
}

.map-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.spot-layer {
  position: absolute;
  inset: 0;
}

.drop-veil {
  display: none;
}

.spot-marker {
  --spot-color: var(--status-available);
  position: absolute;
  transform: translate(-50%, -50%);
  min-width: 30px;
  height: 24px;
  padding: 0 6px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--spot-color);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--ink);
  box-shadow: 1px 2px 0 var(--shadow);
  cursor: grab;
  touch-action: none;
  transition: transform 120ms var(--ease-out), opacity 120ms var(--ease-out);
}

.spot-marker:active {
  cursor: grabbing;
}

.spot-marker.is-selected {
  transform: translate(-50%, -50%) scale(1.18);
  box-shadow: 0 0 0 3px var(--water);
}

.spot-marker.is-hidden {
  opacity: 0.18;
  pointer-events: none;
}

.spot-marker--view {
  cursor: pointer;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  font-size: 0.8rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 1.5px solid var(--ink);
  display: inline-block;
}

.dot--inline {
  width: 9px;
  height: 9px;
  margin-right: 4px;
  vertical-align: middle;
}

/* ---------- Inspector ---------- */

.inspector {
  display: flex;
}

.empty-state {
  font-size: 0.86rem;
  color: var(--ink-soft);
  line-height: 1.5;
}

.spot-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ---------- Ledger table ---------- */

.ledger {
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
}

.ledger-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.ledger-table th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid var(--ink);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}

.ledger-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.ledger-table tr {
  cursor: pointer;
}

.ledger-table tr:hover td {
  background: rgba(198, 90, 46, 0.06);
}

.ledger-table tr.is-selected td {
  background: rgba(74, 144, 164, 0.14);
}

/* ---------- Public viewer ---------- */

.published-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border: 1.5px solid var(--ok);
  border-radius: var(--radius);
  background: rgba(78, 124, 74, 0.1);
  font-size: 0.84rem;
}

.published-bar__flag {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--ok);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.published-bar #published-status {
  margin: 0;
}

.workspace--viewer {
  margin-top: 16px;
}

.viewer-event-name {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 1.2rem;
}

.result-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}

.result-item button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1.5px solid var(--line);
  border-radius: 4px;
  background: var(--panel-strong);
  font-size: 0.82rem;
  text-align: left;
}

.result-item.is-selected button {
  border-color: var(--water);
  background: rgba(74, 144, 164, 0.12);
}

.result-item__code {
  font-family: var(--font-mono);
  font-weight: 700;
}

.result-item__name {
  flex: 1;
  color: var(--ink-soft);
}

.viewer-detail__title {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 1.2rem;
}

.viewer-detail__list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.viewer-detail__list div {
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}

.viewer-detail__list dt {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.viewer-detail__list dd {
  margin: 2px 0 0;
  font-weight: 600;
}

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

.footer-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(360px, 1.4fr);
  gap: 16px;
}

.reference-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.ref-thumb {
  padding: 3px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: var(--panel-strong);
  aspect-ratio: 1 / 1;
  overflow: hidden;
}

.ref-thumb.is-active {
  border-color: var(--water);
  box-shadow: 0 0 0 2px rgba(74, 144, 164, 0.35);
}

.ref-thumb img,
.reference-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.reference-preview {
  max-height: 280px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: var(--panel-strong);
  object-fit: contain;
  margin-bottom: 8px;
}

.schema-block {
  margin: 0 0 12px;
  padding: 12px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: #fffef8;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.5;
  overflow-x: auto;
}

.live-json summary {
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.demo-footnote {
  margin: 0;
  padding: 12px 16px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  font-size: 0.8rem;
  color: var(--ink-soft);
  text-align: center;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  z-index: 60;
  padding: 10px 18px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.84rem;
  opacity: 0;
  transition: opacity 160ms var(--ease-out), transform 160ms var(--ease-out);
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Responsive ---------- */

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 260px minmax(320px, 1fr) 260px;
  }

  .footer-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 880px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .map-surface {
    max-height: 60vh;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100% - 16px, 640px);
  }

  .reference-strip {
    grid-template-columns: repeat(3, 1fr);
  }

  .mode-switch,
  .state-chips {
    width: 100%;
    justify-content: space-between;
  }
}
