:root {
  color-scheme: dark;
  --bg: #0b1020;
  --panel: #111a31;
  --panel-2: #16223d;
  --text: #f3f7ff;
  --muted: #aab8d0;
  --line: rgba(255, 255, 255, 0.13);
  --accent: #79d4ff;
  --accent-2: #9cffd0;
  --danger: #ff7f93;
  --danger-bg: #b92842;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden],
.modal[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(121, 212, 255, 0.14), transparent 30rem),
    radial-gradient(circle at top right, rgba(156, 255, 208, 0.12), transparent 26rem),
    var(--bg);
  color: var(--text);
}

button,
textarea,
input {
  font: inherit;
}

button,
.primary-import,
.secondary-import {
  border: 1px solid rgba(121, 212, 255, 0.42);
  background: linear-gradient(180deg, rgba(121, 212, 255, 0.18), rgba(121, 212, 255, 0.07));
  color: var(--text);
  border-radius: 0.95rem;
  padding: 0.82rem 1rem;
  cursor: pointer;
  font-weight: 800;
  text-align: center;
}

button:active,
.primary-import:active,
.secondary-import:active {
  transform: translateY(1px);
}

button.danger {
  border-color: rgba(255, 127, 147, 0.5);
  background: linear-gradient(180deg, rgba(255, 127, 147, 0.18), rgba(255, 127, 147, 0.07));
}

.primary-import,
.secondary-import {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.primary-import input,
.secondary-import input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.app-shell {
  width: min(980px, calc(100% - 2rem));
  margin: 0 auto;
  padding: max(1.25rem, env(safe-area-inset-top)) 0 max(2rem, env(safe-area-inset-bottom));
}

.start-screen {
  min-height: 78vh;
  display: grid;
  align-content: center;
  gap: 1rem;
}

.start-screen,
.editor-header,
.panel,
.json-panel,
.modal-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.03));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 1.35rem;
}

.start-screen {
  padding: clamp(1.25rem, 6vw, 3rem);
}

.eyebrow {
  color: var(--accent-2);
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 0 0 0.5rem;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(2.35rem, 9vw, 5rem);
  line-height: 0.95;
  margin-bottom: 0.9rem;
}

h2 {
  font-size: 1.15rem;
  margin-bottom: 0.45rem;
}

.subtitle,
.status-line,
.privacy-note,
.panel-header p,
.modal-header p,
.field span,
.empty {
  color: var(--muted);
}

.subtitle {
  font-size: 1.1rem;
  max-width: 680px;
}

.primary-import {
  width: 100%;
  min-height: 4.8rem;
  font-size: clamp(1.45rem, 6vw, 2.4rem);
  border-radius: 1.25rem;
  color: var(--accent-2);
}

.status-line,
.privacy-note {
  margin-bottom: 0;
}

.editor-screen {
  display: grid;
  gap: 1rem;
}

.editor-header,
.panel,
.json-panel {
  padding: 1.15rem;
}

.editor-header {
  display: grid;
  gap: 1rem;
}

.toolbar,
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
}

.toolbar button,
.toolbar .secondary-import {
  flex: 1 1 auto;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.panel-header,
.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}

.panel-header p {
  margin-bottom: 0.8rem;
}

.count {
  min-width: 2.4rem;
  text-align: center;
  padding: 0.32rem 0.55rem;
  border-radius: 999px;
  background: rgba(156, 255, 208, 0.12);
  color: var(--accent-2);
  border: 1px solid rgba(156, 255, 208, 0.2);
  font-weight: 900;
}

.compact-actions {
  margin-bottom: 0.95rem;
}

.compact-actions button {
  padding: 0.72rem 0.8rem;
  flex: 1 1 auto;
}

.icon-button {
  flex: 0 0 3.25rem !important;
  min-width: 3.25rem;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--accent-2);
}

textarea,
input[type="text"] {
  width: 100%;
  color: var(--text);
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid var(--line);
  border-radius: 0.95rem;
  padding: 0.9rem;
  outline: none;
}

textarea {
  min-height: 8.5rem;
  resize: vertical;
  margin-bottom: 0.75rem;
}

textarea:focus,
input[type="text"]:focus,
pre:focus {
  border-color: rgba(121, 212, 255, 0.72);
  box-shadow: 0 0 0 3px rgba(121, 212, 255, 0.12);
}

.list-rows {
  display: grid;
  gap: 0.55rem;
}

.rule-row {
  position: relative;
  overflow: hidden;
  border-radius: 0.95rem;
  background: var(--danger-bg);
  touch-action: pan-y;
}

.row-delete {
  position: absolute;
  inset: 0 0 0 auto;
  width: 96px;
  border-radius: 0;
  border: 0;
  background: var(--danger-bg);
  color: white;
}

.row-foreground {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 3.25rem;
  padding: 0.8rem;
  border: 1px solid rgba(121, 212, 255, 0.16);
  border-radius: 0.95rem;
  background: rgba(5, 10, 22, 0.96);
  transition: transform 180ms ease;
}

.rule-row.revealed .row-foreground {
  transform: translateX(-96px);
}

.row-foreground code {
  color: var(--text);
  overflow-wrap: anywhere;
  font-size: 0.94rem;
}

.swipe-hint {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.78rem;
}

.empty {
  padding: 0.7rem 0;
}

.json-panel summary {
  cursor: pointer;
  font-weight: 900;
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0.9rem 0 0;
  padding: 1rem;
  min-height: 11rem;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  border-radius: 0.95rem;
  color: var(--accent-2);
}

.json-input {
  margin-top: 0.9rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.78);
}

.modal-card {
  width: min(560px, 100%);
  max-height: calc(100vh - 2rem);
  overflow: auto;
  padding: 1.25rem;
  background: #111a31;
}

.field {
  display: grid;
  gap: 0.35rem;
  margin: 1rem 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.7rem;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(1rem);
  opacity: 0;
  pointer-events: none;
  max-width: calc(100% - 2rem);
  padding: 0.8rem 1rem;
  border-radius: 999px;
  background: rgba(10, 16, 32, 0.96);
  border: 1px solid rgba(156, 255, 208, 0.28);
  color: var(--text);
  box-shadow: var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
}

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

@media (min-width: 960px) {
  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .editor-header {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 1rem, 980px);
  }

  .start-screen {
    min-height: calc(100vh - 2rem);
  }

  .panel,
  .json-panel,
  .editor-header {
    padding: 1rem;
  }

  .toolbar button {
    flex-basis: 100%;
  }

  .modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
