:root {
  color-scheme: light;
  --bg: #f4f0e8;
  --surface: rgba(255, 252, 246, 0.9);
  --surface-strong: #fffaf2;
  --border: #d7c9b1;
  --text: #261c12;
  --muted: #6d5c4b;
  --accent: #b6561e;
  --accent-soft: #f3d8c6;
  --shadow: 0 18px 50px rgba(60, 36, 16, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(233, 179, 96, 0.35), transparent 30%),
    linear-gradient(180deg, #f8f3eb 0%, var(--bg) 100%);
}

code,
input,
button,
table {
  font-family: "SFMono-Regular", "SF Mono", Consolas, "Liberation Mono", monospace;
}

.page {
  padding: 24px;
}

.header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 12px;
  color: var(--accent);
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.5rem);
  line-height: 0.95;
}

.subtitle,
.meta,
.search span {
  color: var(--muted);
}

.subtitle {
  margin: 10px 0 0;
  max-width: 60ch;
}

.meta {
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.controls {
  margin-bottom: 16px;
  display: flex;
  gap: 16px;
  align-items: start;
  justify-content: space-between;
  flex-wrap: wrap;
}

.search {
  display: inline-flex;
  flex-direction: column;
  gap: 8px;
}

.search input {
  width: min(420px, calc(100vw - 48px));
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  font-size: 14px;
}

.column-manager {
  width: min(340px, 100%);
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.column-manager summary {
  cursor: pointer;
  font-weight: 700;
}

.column-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0 8px;
}

.column-actions button {
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
}

.column-help {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
}

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

.column-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.5);
}

.column-item[draggable="true"] {
  cursor: grab;
}

.column-item.dragging {
  opacity: 0.45;
}

.column-item input {
  margin: 0;
}

.column-name {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.drag-handle {
  color: var(--muted);
  user-select: none;
}

.table-shell {
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid rgba(215, 201, 177, 0.75);
  background: rgba(246, 235, 223, 0.7);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-strong);
  font-size: 12px;
  color: var(--muted);
}

.table-scroll {
  overflow: auto;
  max-height: calc(100vh - 220px);
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f6ebdf;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(215, 201, 177, 0.75);
  border-right: 1px solid rgba(215, 201, 177, 0.45);
  vertical-align: top;
  text-align: left;
}

th:last-child,
td:last-child {
  border-right: 0;
}

tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.36);
}

tbody tr:hover {
  background: rgba(243, 216, 198, 0.55);
}

th button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

th button:hover {
  color: var(--accent);
}

.sort-indicator {
  color: var(--accent);
  min-width: 1ch;
}

td {
  max-width: 340px;
  white-space: pre-wrap;
  word-break: break-word;
}

.cell-link {
  color: var(--accent);
}

.title-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.title-note {
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 24px;
}

@media (max-width: 720px) {
  .page {
    padding: 16px;
  }

  .header {
    flex-direction: column;
    align-items: start;
  }

  .table-scroll {
    max-height: calc(100vh - 260px);
  }

  .controls {
    flex-direction: column;
  }

  .search input,
  .column-manager {
    width: 100%;
  }
}
