:root {
  color-scheme: light;
  --paper: #f7f7f2;
  --paper-strong: #ffffff;
  --ink: #151412;
  --muted: #66645d;
  --line: #d8d5ca;
  --line-strong: #aaa597;
  --teal: #007f78;
  --teal-soft: #dcefeb;
  --rust: #b84c34;
  --rust-soft: #f3ddd5;
  --brass: #9b742b;
  --blue: #315c9f;
  --shadow: 0 18px 44px rgba(21, 20, 18, 0.12);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  width: 100%;
  background: var(--paper);
}

body {
  min-height: 100%;
  width: 100%;
  margin: 0;
  color: var(--ink);
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(247, 247, 242, 0.8)),
    repeating-linear-gradient(90deg, rgba(21, 20, 18, 0.025) 0 1px, transparent 1px 32px);
}

button,
input,
select {
  font: inherit;
}

a {
  color: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  max-width: calc(100vw - 28px);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  gap: 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 800;
  letter-spacing: 0;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--ink);
  border-radius: 50%;
  font-size: 0.92rem;
}

.topnav {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
}

.topnav a,
.text-link {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.topnav a {
  min-width: 0;
  padding: 9px 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.topnav a:hover,
.text-link:hover {
  border-color: currentColor;
}

.app {
  padding: 10px 0 48px;
}

.app:focus {
  outline: none;
}

.view {
  display: grid;
  min-width: 0;
  gap: 22px;
}

.wave-grid {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
  align-items: stretch;
  gap: 22px;
  min-height: calc(100vh - 126px);
}

.object-stage,
.panel,
.field-panel,
.admin-panel,
.share-unit,
.record-row {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
}

.object-stage {
  display: grid;
  align-content: center;
  min-height: 560px;
  overflow: hidden;
}

.object-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1.12;
  padding: clamp(16px, 5vw, 58px);
  background:
    linear-gradient(145deg, rgba(0, 127, 120, 0.09), transparent 42%),
    linear-gradient(315deg, rgba(184, 76, 52, 0.12), transparent 38%),
    #efeee8;
}

.object-frame img {
  display: block;
  width: min(92%, 760px);
  max-height: 88%;
  object-fit: contain;
  mix-blend-mode: multiply;
  filter: contrast(1.03) saturate(0.96);
}

.field-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  background: rgba(247, 247, 242, 0.9);
}

.field-strip span {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
}

.signal-line {
  flex: 1;
  height: 6px;
  min-width: 80px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--paper-strong);
}

.signal-line i {
  display: block;
  width: 46%;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--brass));
}

.panel {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(18px, 3vw, 30px);
}

.wave-grid > .panel {
  min-height: 560px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.title {
  margin: 0;
  font-size: clamp(2.2rem, 5vw, 5rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.subcopy {
  max-width: 54ch;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
}

.status-row,
.meta-row,
.action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.status-pill,
.id-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-strong);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.status-pill.live {
  border-color: rgba(0, 127, 120, 0.35);
  background: var(--teal-soft);
  color: #075d58;
}

.status-pill.frozen,
.status-pill.warn {
  border-color: rgba(184, 76, 52, 0.35);
  background: var(--rust-soft);
  color: #8a321f;
}

.id-pill {
  border-color: rgba(155, 116, 43, 0.42);
  color: var(--brass);
}

.id-link {
  cursor: pointer;
  text-decoration: none;
}

.id-link:hover {
  border-color: var(--brass);
  background: #fbf4e6;
}

.wave-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 24px 0;
}

.wave-tab,
.option-tile,
.primary-button,
.secondary-button,
.link-button,
.danger-button,
.select-control {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-strong);
  color: var(--ink);
}

.wave-tab {
  min-height: 48px;
  padding: 8px;
  cursor: pointer;
  text-align: left;
}

.wave-tab strong,
.wave-tab span {
  display: block;
}

.wave-tab strong {
  font-size: 0.83rem;
}

.wave-tab span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.72rem;
}

.wave-tab.active {
  border-color: var(--ink);
  box-shadow: inset 0 -3px 0 var(--teal);
}

.wave-tab[disabled] {
  cursor: not-allowed;
  opacity: 0.48;
}

.options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.option-tile {
  display: grid;
  min-height: 118px;
  padding: 15px;
  cursor: pointer;
  text-align: left;
}

.option-tile strong {
  align-self: end;
  font-size: clamp(1.4rem, 4vw, 2.35rem);
  line-height: 1;
  letter-spacing: 0;
}

.option-tile span {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.option-tile[aria-pressed="true"] {
  border-color: var(--teal);
  background: linear-gradient(180deg, #fff, var(--teal-soft));
  box-shadow: inset 0 -4px 0 var(--teal);
}

.commit-wrap {
  margin-top: 12px;
}

.commit-button {
  position: relative;
  width: 100%;
  min-height: 58px;
  overflow: hidden;
  border: 1px solid var(--rust);
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

.commit-button:disabled {
  border-color: var(--line);
  background: #d5d2c8;
  color: #77746b;
  cursor: not-allowed;
}

.commit-button .fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--hold-progress, 0%);
  background: var(--rust);
  transition: width 80ms linear;
}

.commit-button span {
  position: relative;
  z-index: 1;
}

.small-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.section-grid {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(0, 0.9fr) minmax(360px, 1.1fr);
  gap: 18px;
}

.field-panel,
.admin-panel,
.share-unit {
  padding: clamp(16px, 3vw, 24px);
}

.field-panel h2,
.inline-field h2,
.admin-panel h2,
.share-unit h2,
.panel h2 {
  margin: 0 0 14px;
  font-size: clamp(1.35rem, 3vw, 2rem);
  line-height: 1.08;
  letter-spacing: 0;
}

.inline-field,
.record-summary {
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.record-summary h2 {
  margin: 0 0 14px;
  font-size: clamp(1.35rem, 3vw, 2rem);
  line-height: 1.08;
}

.field-bars {
  display: grid;
  gap: 12px;
}

.field-bar {
  display: grid;
  gap: 7px;
}

.field-bar header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

.bar-track {
  height: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #eceae2;
}

.bar-fill {
  width: max(4%, var(--bar-width));
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--brass));
}

.bar-fill.alt {
  background: linear-gradient(90deg, var(--rust), var(--blue));
}

.record-list {
  display: grid;
  gap: 10px;
}

.record-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.55fr) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  box-shadow: none;
}

.record-row strong,
.record-row span {
  min-width: 0;
}

.record-row span {
  color: var(--muted);
  font-size: 0.9rem;
}

.action-row {
  margin-top: 18px;
}

.primary-button,
.secondary-button,
.link-button,
.danger-button,
.select-control {
  min-height: 42px;
  padding: 10px 13px;
}

.primary-button,
.danger-button {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

.danger-button {
  border-color: var(--rust);
  background: var(--rust);
}

.secondary-button,
.link-button {
  cursor: pointer;
}

.link-button {
  text-decoration: none;
}

.select-control {
  min-width: 160px;
}

.share-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 16px;
  align-items: end;
}

.share-preview {
  display: grid;
  gap: 10px;
}

.share-object {
  width: 100%;
  aspect-ratio: 1.6;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #efeee8;
}

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

.qr-matrix {
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  gap: 2px;
  width: 160px;
  height: 160px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-strong);
}

.qr-matrix i {
  background: transparent;
}

.qr-matrix i.on {
  background: var(--ink);
}

.qr-matrix i.finder {
  background: var(--teal);
}

.share-link {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.admin-controls {
  display: grid;
  gap: 12px;
}

.control-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.audit-list {
  display: grid;
  gap: 8px;
  max-height: 340px;
  overflow: auto;
  padding-right: 4px;
}

.audit-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}

.empty-state {
  padding: 20px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(360px, calc(100% - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
}

@media (max-width: 880px) {
  .app-shell {
    width: min(100% - 20px, 680px);
  }

  .topbar {
    min-height: 60px;
  }

  .topnav {
    gap: 2px;
  }

  .topnav a {
    padding: 8px 6px;
    font-size: 0.82rem;
  }

  .wave-grid,
  .section-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .wave-grid {
    min-height: auto;
  }

  .object-stage,
  .panel {
    min-height: auto;
  }

  .object-frame {
    aspect-ratio: 1.45;
    padding: 10px;
  }

  .object-frame img {
    width: min(82%, 540px);
  }

  .panel {
    padding: 18px;
  }

  .title {
    font-size: clamp(2rem, 14vw, 4rem);
  }

  .wave-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 18px 0;
  }

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

  .option-tile {
    min-height: 92px;
  }

  .record-row {
    grid-template-columns: 1fr;
  }

  .share-layout {
    grid-template-columns: 1fr;
  }

  .qr-matrix {
    width: 150px;
    height: 150px;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(calc(100% - 20px), 370px);
    max-width: none;
    margin-right: 10px;
    margin-left: 10px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 8px;
    padding: 12px 0 8px;
  }

  .topnav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-content: space-between;
    width: 100%;
    gap: 0;
  }

  .topnav a {
    padding: 6px 0;
    text-align: left;
  }

  .topnav a:nth-child(2) {
    text-align: center;
  }

  .topnav a:nth-child(3) {
    text-align: right;
  }

  .object-frame {
    aspect-ratio: 2.6;
    padding: 4px;
  }

  .object-frame img {
    width: min(56%, 300px);
  }

  .field-strip {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    padding: 10px 16px;
  }

  .signal-line {
    min-width: 0;
  }

  .field-strip span:last-child {
    grid-column: 1 / -1;
  }

  .title {
    font-size: clamp(2.1rem, 12vw, 3.1rem);
  }

  .options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .option-tile {
    min-height: 86px;
    padding: 12px;
  }

  .option-tile strong {
    font-size: clamp(1.25rem, 8vw, 1.85rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}
