:root {
  --bg: #faf9f5;
  --surface: #ffffff;
  --border: #e3e0d8;
  --text: #181816;
  --muted: #6b6963;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --tag-bg: #f1efe9;
  --ok-bg: #ecfdf3;
  --ok-border: #abefc6;
  --ok-text: #065f46;
  --err-bg: #fef2f2;
  --err-border: #fecaca;
  --err-text: #991b1b;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --warn-text: #92400e;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151513;
    --surface: #1d1d1a;
    --border: #2e2d29;
    --text: #eceae4;
    --muted: #98958d;
    --accent: #ea580c;
    --accent-ink: #ffffff;
    --tag-bg: #252420;
    --ok-bg: #052e16;
    --ok-border: #166534;
    --ok-text: #bbf7d0;
    --err-bg: #450a0a;
    --err-border: #991b1b;
    --err-text: #fecaca;
    --warn-bg: #451a03;
    --warn-border: #92400e;
    --warn-text: #fde68a;
  }
}

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

html,
body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 28px 18px 64px;
  overflow-x: hidden;
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
}

.site-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.site-subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.site-nav {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-shrink: 0;
}

.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 12px;
}

.nav-link:hover {
  color: var(--text);
  text-decoration: underline;
}

/* Controls & tag filter */

.controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.controls-top {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.search-input,
input[type="text"],
input[type="password"] {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 8px 11px;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.search-input:focus,
input[type="text"]:focus,
input[type="password"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary:hover:not(:disabled) {
  opacity: 0.9;
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-ghost {
  padding: 6px 10px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

.btn-ghost:hover {
  border-color: var(--muted);
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

.tag-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-chip {
  padding: 4px 9px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  background: var(--tag-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
}

.tag-chip:hover {
  border-color: var(--muted);
}

.tag-chip.is-active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.tag-chip .count {
  opacity: 0.65;
  margin-left: 2px;
}

/* 777 Slot machine panel (single-column 3D drum) */

.slot-panel {
  background: var(--surface);
  border: 2px solid var(--text);
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 24px;
  overflow: hidden;
}

.slot-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.slot-head-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.slot-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--sans);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 5px 7px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 3px;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}

.slot-head-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.slot-scope {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-cabinet {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.drum-window {
  box-sizing: content-box;
  position: relative;
  flex: 1;
  min-width: 0;
  height: 220px;
  overflow: hidden;
  border: 2px solid var(--text);
  border-radius: 4px;
  background: var(--bg);
  perspective: 420px;
}

.drum-window::before,
.drum-window::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 54px;
  pointer-events: none;
  z-index: 3;
}

.drum-window::before {
  top: 0;
  background: linear-gradient(to bottom, var(--bg) 5%, transparent 100%);
}

.drum-window::after {
  bottom: 0;
  background: linear-gradient(to top, var(--bg) 5%, transparent 100%);
}

.drum-payline {
  position: absolute;
  left: 0;
  right: 0;
  top: 88px;
  height: 44px;
  border-top: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  pointer-events: none;
  z-index: 2;
}

.drum-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 88px;
  height: 44px;
  max-width: 100%;
  transform-style: preserve-3d;
  transform: translateZ(-104px);
}

.drum-cell {
  position: absolute;
  inset: 0;
  max-width: 100%;
  padding: 0 18px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  backface-visibility: hidden;
  will-change: transform, opacity;
  color: var(--muted);
}

@media (max-width: 520px) {
  .slot-panel {
    padding: 12px;
  }

  .slot-cabinet {
    gap: 10px;
  }

  .drum-cell {
    padding: 0 10px;
  }

  .drum-url {
    font-size: 13px;
  }
}

.drum-cell.is-front {
  color: var(--text);
}

.drum-url {
  display: block;
  max-width: 100%;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drum-cell.is-front .drum-url {
  font-weight: 700;
}

/* Pull-down lever (symmetric 8px top & bottom padding inside 154px inner height) */

.lever-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  user-select: none;
}

.lever-track {
  position: relative;
  width: 48px;
  height: 156px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 24px;
}

.lever-track.is-armed {
  border-color: var(--accent);
}

.lever-slot {
  position: absolute;
  left: 50%;
  top: 23px;
  bottom: 23px;
  width: 6px;
  transform: translateX(-50%);
  background: var(--border);
  border-radius: 3px;
}

.lever-arm {
  position: absolute;
  left: 50%;
  top: 23px;
  width: 6px;
  height: 108px;
  transform: translateX(-50%);
  background: var(--muted);
  border-radius: 3px;
  pointer-events: none;
}

.lever-knob {
  position: absolute;
  left: 50%;
  top: 8px;
  width: 30px;
  height: 30px;
  margin-left: -15px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: grab;
  touch-action: none;
  padding: 0;
}

.lever-knob:active {
  cursor: grabbing;
}

.lever-knob.is-spring,
.lever-arm.is-spring {
  transition: transform 0.24s cubic-bezier(0.22, 1.35, 0.36, 1),
    height 0.24s cubic-bezier(0.22, 1.35, 0.36, 1),
    top 0.24s cubic-bezier(0.22, 1.35, 0.36, 1);
}

.lever-hint {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.lever-track.is-armed + .lever-hint {
  color: var(--accent);
}

.slot-quip {
  margin: 12px 0 0;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
}

.slot-winner-card {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  background: var(--bg);
  padding: 12px 14px;
  border-radius: 3px;
}

.winner-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.winner-head > div {
  min-width: 0;
  overflow-wrap: anywhere;
}

.jackpot-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--sans);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 4px 6px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 3px;
  flex-shrink: 0;
}

.winner-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
}

.winner-domain {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.winner-desc {
  margin: 8px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.winner-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.winner-tag-pill {
  padding: 1px 6px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  background: var(--tag-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
}

.slot-progress {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin: 12px 0 8px;
}

.slot-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
}

.slot-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.slot-status {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.slot-btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Directory list */

.link-list,
.admin-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.link-row,
.admin-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.link-row[hidden] {
  display: none;
}

.link-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.link-title {
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  min-width: 0;
  overflow-wrap: anywhere;
}

.link-title:hover {
  color: var(--accent);
  text-decoration: underline;
}

.link-domain {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  min-width: 0;
  overflow-wrap: anywhere;
}

.link-desc {
  margin: 3px 0 0;
  font-size: 14px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.link-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.inline-tag {
  padding: 1px 6px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  background: var(--tag-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
}

.inline-tag:hover {
  color: var(--text);
  border-color: var(--muted);
}

.empty-state,
.empty-filter {
  padding: 28px 0;
  color: var(--muted);
}

/* Admin */

.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 24px;
}

.section-title {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 700;
}

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

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 600px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
}

.field span {
  color: var(--muted);
}

.tag-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tag-picker-label {
  font-size: 12px;
  color: var(--muted);
}

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

.admin-row-head > div:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.admin-tags {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  margin-left: 6px;
}

.inline-form {
  display: inline;
}

.btn-danger-link {
  background: none;
  border: none;
  padding: 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--err-text);
  cursor: pointer;
}

.btn-danger-link:hover {
  text-decoration: underline;
}

.edit-details {
  margin-top: 6px;
}

.edit-details summary {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

.edit-form {
  margin-top: 10px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.notice {
  padding: 10px 12px;
  border-radius: 4px;
  border: 1px solid;
  margin-bottom: 16px;
  font-size: 14px;
}

.notice-ok {
  background: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok-text);
}

.notice-err {
  background: var(--err-bg);
  border-color: var(--err-border);
  color: var(--err-text);
}

.notice-warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn-text);
}

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