/* ============================== */
/* DESIGN TOKENS */
:root {
  --page-bg: #090909;
  --surface-1: #121212;
  --surface-2: #181818;
  --surface-3: #222222;
  --surface-hover: #2a2a2a;
  --border: #2d2d2d;
  --border-strong: #404040;
  --text: #ededed;
  --text-muted: #a0a0a0;
  --text-dim: #707070;
  --accent: #00e385;
  --accent-strong: #00b86f;
  --accent-dark: #008f55;
  --accent-glow: rgba(0, 227, 133, 0.12);
  --grade-low: #ff4d4d;
  --grade-mid: #bfd730;
  --grade-high: #00e385;
  --danger: #c34242;
  --danger-strong: #e15454;
  --font-xs: 12px;
  --font-sm: 14px;
  --font-md: 16px;
  --font-lg: 20px;
  --mono: "Atkinson Hyperlegible Mono";
  --radius-sm: 4px;
  --radius-lg: 6px;
  --radius-pill: 999px;
  --icon-size: 18px;
  --icon-size-sm: 16px;
  --row-min: 46px;
  --handle-track: 36px;
  --rank-track: 40px;
  --grade-track: 88px;
  --list-field-w: 240px;
  --space-2: 2px;
  --space-3: 4px;
  --space-4: 6px;
  --space-5: 8px;
  --space-6: 12px;
  --transition: 160ms ease;
}

/* ============================== */
/* RESET */
*,
*::before,
*::after {
  box-sizing: border-box;
}
* {
  margin: 0;
  padding: 0;
}
[hidden] {
  display: none !important;
}
html {
  min-width: 320px;
  color-scheme: dark;
}
body {
  min-height: 100dvh;
  padding: var(--space-6);
  background: var(--page-bg);
  color: var(--text);
  font-family: "Atkinson Hyperlegible Next";
  font-weight: 600;
  font-size: var(--font-md);
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
body.modal-open {
  overflow: hidden;
}
button,
input,
select,
textarea {
  color: inherit;
  font: inherit;
}
button {
  border: 0;
}
.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;
}

/* ============================== */
/* LUCIDE ICONS */
.icon {
  display: inline-block;
  width: var(--icon-size);
  height: var(--icon-size);
  flex: 0 0 auto;
  background: currentColor;
  -webkit-mask: var(--icon-mask, none) center / contain no-repeat;
  mask: var(--icon-mask, none) center / contain no-repeat;
}

/* ============================== */
/* APP SHELL */
.container {
  width: min(100%, 900px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.workspace {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.panel {
  min-width: 0;
  padding: var(--space-5);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.app-title {
  font-size: var(--font-lg);
  font-weight: 800;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.scale-note {
  padding: 0 var(--space-3);
  color: var(--text-dim);
  font-size: var(--font-sm);
}

/* ============================== */
/* CONTROLS */
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  flex-wrap: wrap;
  padding: var(--space-5);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.controls-bar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  min-width: 0;
}
.controls-sep {
  width: 1px;
  height: 22px;
  flex: 0 0 auto;
  background: var(--border);
}
.list-tools {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.control-group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.btn {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: linear-gradient(to bottom, var(--surface-3), #1b1b1b);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  transition:
    transform var(--transition),
    opacity var(--transition);
}
.btn:hover:not(:disabled) {
  border-color: var(--accent-dark);
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
}
.btn:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}
.btn--primary {
  border-color: var(--accent-dark);
  background: linear-gradient(to bottom, var(--accent), var(--accent-strong));
  color: #04150d;
}
.btn--primary:hover:not(:disabled) {
  border-color: var(--accent);
}
.btn--danger {
  border-color: #8d3030;
  background: linear-gradient(to bottom, #a53a3a, #762929);
  color: #fff;
}
.btn--danger:hover:not(:disabled) {
  border-color: var(--danger-strong);
}
.icon-button {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    transform var(--transition),
    opacity var(--transition);
}
.icon-button:hover:not(:disabled) {
  color: var(--accent);
  background: var(--surface-hover);
  border-color: var(--accent-dark);
}
.icon-button:active:not(:disabled) {
  transform: translateY(1px);
}
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.3;
}
.icon-button--danger:hover:not(:disabled) {
  color: #ffbcbc;
  background: #2a1414;
  border-color: #6d2626;
}
.list-field {
  display: grid;
  grid-template-areas: "stack";
  width: var(--list-field-w);
  min-width: 0;
}
.list-field > * {
  grid-area: stack;
}
.select-field {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 100%;
  min-width: 0;
}
.select-field select {
  appearance: none;
  -webkit-appearance: none;
  min-height: 36px;
  width: 100%;
  padding: 6px 28px 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: linear-gradient(to bottom, var(--surface-3), #1b1b1b);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  text-overflow: ellipsis;
}
.select-field select:hover {
  border-color: var(--accent-dark);
}
.select-field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.select-field-icon {
  position: absolute;
  right: 9px;
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
  color: var(--text-dim);
  pointer-events: none;
}
.input,
.textarea {
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
}
.input::placeholder {
  color: var(--text-dim);
}
.input:hover,
.textarea:hover {
  border-color: var(--accent-dark);
}
.input:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.textarea {
  min-height: 0;
  resize: vertical;
  font-family: var(--mono);
  font-size: var(--font-sm);
}
.btn:focus-visible,
.icon-button:focus-visible,
.refine-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.row:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.row-label-input:focus-visible,
.list-rename:focus-visible {
  outline: none;
}

/* ============================== */
/* LIST TOOLS */
.list-rename {
  min-height: 36px;
  width: var(--list-field-w);
  padding: 6px 10px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* ============================== */
/* ROWS */
.rows {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.row {
  min-width: 0;
  min-height: var(--row-min);
  display: grid;
  grid-template-columns: var(--handle-track) var(--rank-track) minmax(0, 1fr) var(--grade-track);
  align-items: stretch;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: default;
}
.row:hover {
  border-color: var(--border-strong);
}
.row.is-selected {
  border-color: var(--accent);
}
.row.is-source-dragging {
  display: none;
}
.row-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  color: var(--text-dim);
  cursor: grab;
  touch-action: none;
}
.row:hover .row-handle,
.row.is-selected .row-handle {
  color: var(--text-muted);
}
.row-rank {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--font-sm);
  font-variant-numeric: tabular-nums;
  user-select: none;
}
.row.is-selected .row-rank {
  color: var(--accent);
}
.row-label {
  min-width: 0;
  display: flex;
  align-items: center;
  padding: 0 var(--space-5);
  overflow: hidden;
  color: var(--text);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
}
.row-label-input {
  align-self: center;
  min-width: 0;
  margin: 0 var(--space-4);
  padding: 4px 8px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--text);
  font-weight: 700;
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.row-grade {
  --t: 0.5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  color: color-mix(in oklab, color-mix(in oklab, var(--grade-low), var(--grade-mid) calc(clamp(0, calc(var(--t) * 2), 1) * 100%)), var(--grade-high) calc(clamp(0, calc((var(--t) - 0.5) * 2), 1) * 100%));
  font-family: var(--mono);
  font-size: var(--font-lg);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  letter-spacing: -0.01em;
  user-select: none;
}

/* ============================== */
/* INSPECTOR */
.inspector {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 15ch auto;
  align-items: center;
  gap: var(--space-5);
  min-height: 54px;
  margin-top: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.inspector-controls {
  display: flex;
  align-items: center;
  gap: var(--space-5);
}
.inspector-target {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: var(--font-md);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.inspector-hint {
  min-width: 0;
  overflow: hidden;
  color: var(--text-dim);
  font-size: var(--font-sm);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.inspector-range {
  color: var(--text-dim);
  font-size: var(--font-sm);
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.inspector[data-state="idle"] {
  grid-template-columns: minmax(0, 1fr) auto;
}
.inspector[data-state="idle"] .inspector-range {
  display: none;
}
.inspector-group {
  display: inline-flex;
  align-items: stretch;
  overflow: hidden;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.inspector-group > * + * {
  border-left: 1px solid var(--border);
}
.inspector-step {
  display: inline-flex;
  align-items: center;
  padding: 0 var(--space-5);
  color: var(--text);
  font-family: var(--mono);
  font-size: var(--font-sm);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
}
.refine-btn {
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: 0 14px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: var(--font-md);
  font-weight: 700;
  white-space: nowrap;
}
.refine-btn:hover:not(:disabled) {
  color: var(--accent);
  background: var(--surface-hover);
}
.refine-btn--danger:hover:not(:disabled) {
  color: #ffbcbc;
  background: #2a1414;
}
.refine-btn:disabled {
  cursor: not-allowed;
  opacity: 0.32;
}
.refine-btn .icon {
  width: 18px;
  height: 18px;
}

/* ============================== */
/* ADD ROW */
.empty-note {
  padding: var(--space-6) var(--space-5);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-align: center;
}
.add-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
}
.add-row .btn {
  flex: 0 0 auto;
}

/* ============================== */
/* DRAG */
.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 3000;
  margin: 0;
  pointer-events: none;
  border-color: var(--accent);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.55);
  transition: none;
}
.drag-placeholder {
  flex: none;
  min-height: var(--row-min);
  border: 1px dashed var(--accent);
  border-radius: var(--radius-sm);
  background: rgba(0, 227, 133, 0.06);
  pointer-events: none;
  transition: none;
}
body.is-dragging-row,
body.is-dragging-row * {
  cursor: grabbing !important;
}

/* ============================== */
/* MODALS */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  background: rgba(0, 0, 0, 0.74);
  opacity: 0;
  transition: opacity var(--transition);
}
.modal.is-open {
  opacity: 1;
}
.modal-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  width: 100%;
  max-width: 440px;
  max-height: min(86vh, 700px);
  overflow-y: auto;
  padding: var(--space-6);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  transform: translateY(12px) scale(0.985);
  transition: transform var(--transition);
}
.modal.is-open .modal-content {
  transform: translateY(0) scale(1);
}
.modal-content--small {
  max-width: 380px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
}
.modal-title {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  color: var(--accent);
  font-size: var(--font-md);
  font-weight: 800;
}
.modal-actions {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: var(--space-4);
}
.modal-actions--stack {
  grid-auto-flow: row;
}
.modal-actions .btn {
  width: 100%;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.form-group label {
  color: var(--text-muted);
  font-size: var(--font-sm);
  font-weight: 700;
}
.field-help {
  color: var(--text-dim);
  font-size: var(--font-sm);
}
.paste-summary {
  color: var(--text-muted);
  font-size: var(--font-sm);
}
.paste-preview {
  max-height: 168px;
  overflow: auto;
  padding: var(--space-5);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--font-xs);
  white-space: pre-wrap;
}
.confirm-message {
  color: var(--text-muted);
}

/* ============================== */
/* FEEDBACK */
.toast {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  z-index: 4000;
  max-width: min(440px, calc(100vw - 2 * var(--space-6)));
  padding: var(--space-6) var(--space-6);
  color: var(--text);
  background: #1c1c1c;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: none;
  font-size: var(--font-sm);
  line-height: 1.45;
  text-wrap: balance;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition:
    opacity var(--transition),
    transform var(--transition);
}
.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}
.toast.is-error {
  border-color: #8d3030;
  background: #2b1717;
}

/* ============================== */
/* APP FOOTER */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-6);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}
.app-footer p {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-4);
  padding-left: var(--space-3);
  font-size: var(--font-lg);
}
.app-footer a:not(.btn) {
  color: var(--text);
  font-weight: 700;
}
.heart {
  color: var(--accent);
}
.pizza-btn {
  flex: 0 0 auto;
}

/* ============================== */
/* RESPONSIVE */
@media (max-width: 720px) {
  :root {
    --row-min: 44px;
    --handle-track: 32px;
    --rank-track: 34px;
    --grade-track: 74px;
  }
  body {
    padding: var(--space-5);
  }
  .app-title {
    flex: 1 1 100%;
    text-align: center;
  }
  .controls-bar {
    width: 100%;
  }
  .list-tools {
    display: grid;
    grid-template-columns: minmax(0, 1fr) repeat(3, 36px);
    flex: 1 1 100%;
  }
  .list-field,
  .select-field,
  .select-field select,
  .list-rename {
    width: 100%;
  }
  .list-tools .icon-button {
    width: 100%;
  }
  .controls-sep {
    display: none;
  }
  .control-group {
    flex: 1 1 100%;
  }
  .control-group .btn {
    flex: 1 1 0;
  }
  .panel {
    display: flex;
    flex-direction: column;
  }
  .add-row {
    order: 1;
  }
  .inspector {
    order: 2;
  }
  .row-label {
    padding: 0 var(--space-4);
  }
  .row-grade {
    font-size: var(--font-md);
  }
  .inspector {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
    text-align: center;
  }
  .inspector-controls {
    flex-direction: column;
    gap: var(--space-3);
    width: 100%;
  }
  .inspector-group {
    width: 100%;
  }
  .inspector-group .refine-btn {
    flex: 1 1 0;
  }
  .inspector-range {
    min-height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
  }
  .inspector[data-state="idle"] .inspector-range {
    display: flex;
  }
  .inspector-target,
  .inspector-hint {
    display: none;
  }
  .scale-note {
    font-size: var(--font-sm);
    text-align: center;
  }
  .add-row {
    flex-direction: row;
    align-items: stretch;
  }
  .add-row .btn {
    flex: 0 0 auto;
  }
  .modal-actions {
    grid-auto-flow: row;
  }
  .toast {
    right: var(--space-3);
    bottom: var(--space-3);
    left: var(--space-3);
    max-width: none;
  }
  .app-footer {
    flex-direction: column;
    padding: var(--space-6);
    text-align: center;
  }
  .app-footer p {
    justify-content: center;
    padding-left: 0;
    font-size: var(--font-sm);
  }
  .pizza-btn {
    width: 100%;
  }
}

/* ============================== */
/* REDUCED MOTION */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
