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

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-hover: #334155;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #7dd3fc;

  --zone-1: #22c55e;
  --zone-2: #eab308;
  --zone-3: #f97316;
  --zone-4: #ef4444;

  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', monospace;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 2.5rem;
}

header h1 {
  font-size: 2.5rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1.05rem;
  margin-top: 0.25rem;
}

/* Controls */
.controls {
  margin-bottom: 2rem;
}

.input-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

#airport {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 1.1rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 0.5rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

#airport::placeholder {
  text-transform: none;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.95rem;
}

#airport:focus {
  border-color: var(--accent);
}

#decode-btn {
  padding: 0.75rem 2rem;
  font-size: 1rem;
  font-weight: 700;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}

#decode-btn:hover {
  background: var(--accent-hover);
}

#decode-btn:active {
  transform: scale(0.97);
}

#decode-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.toggles {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.toggle-group {
  display: flex;
  background: var(--surface);
  border-radius: 0.5rem;
  overflow: hidden;
  border: 1px solid var(--border);
}

.toggle {
  padding: 0.5rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  background: transparent;
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.toggle.active {
  background: var(--accent);
  color: var(--bg);
}

/* Result area */
.result {
  margin-bottom: 1.5rem;
}

.result.hidden, .error.hidden, .settings.hidden {
  display: none;
}

/* Raw text display */
.raw-text-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.raw-text-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.raw-text-label {
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}

.char-count {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-muted);
}

#char-count {
  font-weight: 700;
  color: var(--text);
  transition: color 0.3s;
}

.raw-text {
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text);
  max-height: 200px;
  overflow-y: auto;
  margin: 0;
}

/* Ruler */
.ruler-container {
  position: relative;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
}

.ruler-zones {
  display: flex;
  height: 40px;
  border-radius: 0.5rem;
  overflow: hidden;
  position: relative;
}

.ruler-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: rgba(0, 0, 0, 0.7);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  transition: opacity 0.3s;
  position: relative;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding: 0 0.5rem;
}

.ruler-zone.inactive {
  opacity: 0.3;
}

.ruler-zone.active {
  opacity: 1;
}

/* Ruler ticks */
.ruler-ticks {
  position: relative;
  height: 20px;
  margin-top: 2px;
}

.ruler-tick {
  position: absolute;
  bottom: 0;
  width: 1px;
  background: var(--text-muted);
  opacity: 0.4;
}

.ruler-tick.major {
  height: 12px;
  opacity: 0.7;
}

.ruler-tick.minor {
  height: 6px;
}

.ruler-tick-label {
  position: absolute;
  bottom: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  white-space: nowrap;
}

/* Needle */
.ruler-needle {
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  height: 40px;
  transition: left 1.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 10;
  pointer-events: none;
}

.needle-line {
  width: 3px;
  height: 100%;
  background: var(--text);
  border-radius: 1px;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

.needle-label {
  position: absolute;
  top: -28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: var(--font-mono);
  white-space: nowrap;
}

.needle-label::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid var(--text);
}

/* Verdict */
.verdict {
  text-align: center;
  padding: 1.5rem;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.5s, transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.verdict.visible {
  opacity: 1;
  transform: scale(1);
}

.verdict-text {
  font-size: 2.5rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.verdict-subtext {
  font-size: 1rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* Error */
.error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  padding: 1rem;
  border-radius: 0.5rem;
  text-align: center;
  margin-bottom: 1.5rem;
}

/* Settings */
.settings-btn {
  display: block;
  margin: 0 auto 1rem;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s;
}

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

.settings {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.settings h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.settings-mode {
  margin-bottom: 1.25rem;
}

.settings-zones {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.settings-zone-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.settings-zone-row label {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 110px;
}

.settings-zone-row input[type="number"] {
  width: 80px;
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
  font-family: var(--font-mono);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  color: var(--text);
  outline: none;
}

.settings-zone-row input[type="number"]:focus {
  border-color: var(--accent);
}

.settings-zone-row input[type="text"] {
  flex: 1;
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  color: var(--text);
  outline: none;
}

.settings-zone-row input[type="text"]:focus {
  border-color: var(--accent);
}

.settings-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.settings-actions button {
  padding: 0.5rem 1.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.2s;
}

.settings-actions button:first-child {
  background: var(--accent);
  color: var(--bg);
}

.settings-actions button:first-child:hover {
  background: var(--accent-hover);
}

.settings-actions button.secondary {
  background: var(--surface-hover);
  color: var(--text-muted);
}

.settings-actions button.secondary:hover {
  color: var(--text);
}

/* Footer */
footer {
  text-align: center;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

footer p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.credit {
  margin-top: 0.25rem;
  opacity: 0.6;
}

/* Loading spinner on button */
#decode-btn.loading {
  position: relative;
  color: transparent;
}

#decode-btn.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--bg);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Typing cursor */
.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  animation: blink 0.6s step-end infinite;
  vertical-align: text-bottom;
  margin-left: 1px;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* Responsive */
@media (max-width: 600px) {
  .container {
    padding: 1.5rem 1rem;
  }

  header h1 {
    font-size: 2rem;
  }

  .toggles {
    flex-direction: column;
  }

  .toggle-group {
    width: 100%;
  }

  .toggle {
    flex: 1;
    text-align: center;
  }

  .verdict-text {
    font-size: 2rem;
  }

  .ruler-zone {
    font-size: 0.6rem;
    padding: 0 0.25rem;
  }
}
