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

:root {
  --bg:              #121212;
  --bg-input:        #242424;
  --bg-hover:        #2e2e2e;
  --fg:              #e6e6e6;
  --fg-dim:          #b0b0b0;
  --fg-muted:        #8F8F8F;
  --red:             #b91c1c;
  --red-hover:       #dc2626;
  --red-dim:         #7f1d1d;
  --red-glow:        rgba(185, 28, 28, 0.15);
  --border:          #303030;
  --border-focus:    #b91c1c;
  --radius:          0;
  --radius-sm:       0;
  --font-ui:         "Literata", Georgia, "Times New Roman", serif;
  --font-mono:       "Fira Code", "Courier New", monospace;
}

html {
  scroll-behavior: smooth;
}

html, body {
  min-height: 100%;
  background-color: #121212;
  background-image: url("topography.svg");
  background-repeat: repeat;
  background-size: 600px 600px;
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* ── App shell ─────────────────────────────────────────────────── */
.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 24px 40px;
}

/* ── Header ────────────────────────────────────────────────────── */
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 12px;
  gap: 16px;
  flex-wrap: wrap;
}

.header-left {
  min-width: 0;
}

.header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--fg);
  letter-spacing: 1px;
  line-height: 1.2;
  text-wrap: balance;
}

.header h1 .accent {
  color: var(--red);
}

.subtitle {
  font-size: 12px;
  color: var(--fg-dim);
  margin-top: 2px;
  word-break: break-word;
}

/* ── Mode toggle ───────────────────────────────────────────────── */
.mode-toggle {
  display: flex;
  gap: 4px;
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 3px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  min-height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-dim);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
}

.mode-btn:hover {
  color: var(--fg);
  background-color: var(--bg-hover);
}

.mode-btn.active {
  background-color: var(--red);
  color: #fff;
  box-shadow: 0 0 12px var(--red-glow);
}

/* ── Separator ─────────────────────────────────────────────────── */
.separator {
  height: 2px;
  background: linear-gradient(90deg, var(--red), transparent);
  margin-bottom: 18px;
  border-radius: 0;
}

/* ── Sections ──────────────────────────────────────────────────── */
.section {
  margin-bottom: 12px;
}

.section-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-dim);
  letter-spacing: 0.8px;
  margin-bottom: 6px;
  font-variant: small-caps;
  text-transform: lowercase;
}

.textarea-wrap {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s;
  position: relative;
}

.textarea-wrap::before {
  content: none;
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg width='400' height='400' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0.03 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  mix-blend-mode: overlay;
  opacity: 1;
  background-color: rgba(180,140,80,.22);
}

body.grain-on .textarea-wrap::before {
  content: '';
}

.textarea-wrap:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--red-glow);
}

textarea {
  width: 100%;
  min-height: 180px;
  padding: 12px 14px;
  border: none;
  outline: none;
  background: transparent;
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  resize: vertical;
}

textarea::placeholder {
  color: var(--fg-muted);
}

.output-display {
  width: 100%;
  min-height: 180px;
  max-height: 400px;
  overflow-y: auto;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-all;
  cursor: default;
}

.output-display:empty::before {
  content: attr(data-placeholder);
  color: var(--fg-muted);
}

.output-display .url {
  color: var(--red);
  font-weight: 600;
}

/* ── Actions ───────────────────────────────────────────────────── */
.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 20px;
  min-height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: 0.3px;
  -webkit-user-select: none;
  user-select: none;
  background-image: url("data:image/svg+xml,%3Csvg width='6' height='6' viewBox='0 0 6 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23e0e0e0' fill-opacity='0.18' fill-rule='evenodd'%3E%3Cpath d='M5 0h1L0 6V5zM6 5v1H5z'/%3E%3C/g%3E%3C/svg%3E");
  position: relative;
  overflow: hidden;
}

.btn.shine::before {
  content: '';
  position: absolute;
  top: 0;
  left: -120%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    120deg,
    transparent,
    rgba(255, 255, 255, 0.35),
    transparent
  );
  transform: skewX(-25deg);
  animation: slide-shine 3s infinite;
  pointer-events: none;
}

@keyframes slide-shine {
  0% { left: -120%; }
  50%, 100% { left: 120%; }
}

.btn-resolve {
  background-color: var(--red);
  color: #fff;
}

.btn-resolve:hover {
  background-color: var(--red-hover);
  box-shadow: 0 2px 16px var(--red-glow);
}

.btn-resolve:active {
  transform: scale(0.97);
}

.btn-resolve.loading {
  pointer-events: none;
}

.btn-resolve.loading.shine::before {
  animation: none;
  display: none;
}

/* ── In-button spinner ─────────────────────────────────────────── */
.btn-spinner {
  display: none;
  align-items: center;
  gap: 3px;
  height: 20px;
  position: relative;
  z-index: 1;
}

.btn-resolve.loading .btn-text,
.btn-resolve.loading .btn-arrow { display: none; }

.btn-resolve.loading .btn-spinner {
  display: inline-flex;
}

.btn-spinner span {
  display: block;
  width: 4px;
  height: 20px;
  background-color: currentColor;
  animation: btnbar 1.2s infinite ease-in-out;
}

.btn-spinner span:nth-child(2) { animation-delay: -1.1s; }
.btn-spinner span:nth-child(3) { animation-delay: -1.0s; }
.btn-spinner span:nth-child(4) { animation-delay: -0.9s; }
.btn-spinner span:nth-child(5) { animation-delay: -0.8s; }

@keyframes btnbar {
  0%, 40%, 100% { transform: scaleY(0.4); }
  20%           { transform: scaleY(1); }
}

@media (prefers-reduced-motion: reduce) {
  .btn-spinner span {
    animation: none;
    opacity: 0.4;
  }
}

.btn-clear {
  background-color: var(--bg-input);
  color: var(--fg-dim);
  border: 1px solid var(--border);
}

.btn-clear:hover {
  color: var(--fg);
  background-color: var(--bg-hover);
  border-color: var(--fg-muted);
}

.btn-copy {
  background-color: var(--bg-input);
  color: var(--fg);
  border: 1px solid var(--border);
}

.btn-copy:hover {
  background-color: var(--bg-hover);
  border-color: var(--fg-muted);
}

.btn-clear:active,
.btn-copy:active,
.btn-editor:active {
  transform: scale(0.97);
}

.btn-editor {
  background-color: var(--bg-input);
  color: var(--red);
  border: 1px solid var(--red-dim);
  text-decoration: none;
}

.btn-editor:hover {
  background-color: var(--red-dim);
  color: #fff;
  border-color: var(--red);
}

.status {
  margin-left: auto;
  font-size: 12px;
  color: var(--fg-dim);
  min-width: 0;
  word-break: break-word;
}

.status.resolved {
  color: var(--red);
  font-weight: 600;
}

.status.error,
.error {
  color: var(--red);
}

/* ── Copy row ──────────────────────────────────────────────────── */
.copy-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.copy-status {
  font-size: 12px;
  color: var(--red);
  font-weight: 600;
  transition: opacity 0.3s;
}

/* ── Tablet (≤768px) ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .app {
    padding: 16px 16px 28px;
  }

  .header h1 {
    font-size: 20px;
  }
}

/* ── Mobile (≤640px) ──────────────────────────────────────────── */
@media (max-width: 640px) {
  .app {
    padding: 12px 12px 24px;
  }

  .header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .header h1 {
    font-size: 18px;
  }

  .mode-toggle {
    align-self: flex-start;
  }

  .textarea-wrap {
    border-radius: var(--radius);
  }

  textarea {
    min-height: 140px;
    font-size: 13px;
    padding: 10px 12px;
  }

  .actions {
    gap: 6px;
  }

  .btn {
    min-height: 44px;
    padding: 10px 16px;
    font-size: 14px;
  }

  .btn-resolve {
    flex: 1;
    min-width: 0;
  }

  .btn-clear {
    flex-shrink: 0;
  }

  .status {
    width: 100%;
    margin-left: 0;
    margin-top: 4px;
    font-size: 11px;
  }

  .copy-row {
    gap: 8px;
  }

  .btn-copy {
    min-height: 44px;
    padding: 10px 16px;
    font-size: 14px;
  }
}

/* ── Small phone (≤380px) ─────────────────────────────────────── */
@media (max-width: 380px) {
  .app {
    padding: 10px 10px 20px;
  }

  .header h1 {
    font-size: 16px;
    letter-spacing: 0.5px;
  }

  .subtitle {
    font-size: 11px;
  }

  .mode-btn {
    padding: 6px 10px;
    font-size: 11px;
  }

  textarea {
    min-height: 120px;
    font-size: 12px;
  }

  .btn {
    min-height: 44px;
    font-size: 13px;
  }
}

/* ── Landscape phone ──────────────────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  textarea {
    min-height: 100px;
  }
}

/* ── Safe area (notched phones) ────────────────────────────────── */
@supports (padding: env(safe-area-inset-bottom)) {
  .app {
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
}

/* ── Bottom bar ───────────────────────────────────────────────── */
.bottom-bar {
  text-align: center;
  padding: 6px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--fg-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.3px;
}

.bottom-bar a {
  color: var(--red);
  text-decoration: none;
}

/* ── Touch focus visible ───────────────────────────────────────── */
@media (hover: none) and (pointer: coarse) {
  .btn:focus-visible,
  .mode-btn:focus-visible {
    outline: 2px solid var(--red);
    outline-offset: 2px;
  }
}

/* ── Info button ───────────────────────────────────────────────── */
.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-input);
  color: var(--fg-dim);
  font-size: 15px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.info-btn:hover {
  color: var(--red);
  border-color: var(--red);
  box-shadow: 0 0 10px var(--red-glow);
}

.info-btn:active {
  transform: scale(0.94);
}

.info-btn:focus-visible,
.modal-close:focus-visible,
.modal-try:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

/* ── Info modal ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.72);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 580px;
  max-height: 86vh;
  overflow-y: auto;
  background: #1a1a1a;
  border: 1px solid var(--border);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--red-dim);
  animation: modal-pop 0.18s ease-out;
}

@keyframes modal-pop {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 12px;
}

.modal-header h2 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--fg);
}

.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--bg-input);
  color: var(--fg-dim);
  font-size: 15px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.modal-close:hover {
  color: #fff;
  background: var(--red);
}

.modal-close:active {
  transform: scale(0.92);
}

.modal-sep {
  height: 2px;
  background: linear-gradient(90deg, var(--red), transparent);
  margin: 0 20px 6px;
}

.modal-body {
  padding: 10px 20px 22px;
  color: var(--fg-dim);
  font-size: 13px;
  line-height: 1.65;
}

.modal-body p {
  margin-bottom: 10px;
}

.modal-body h3 {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--red);
  margin: 16px 0 6px;
}

.modal-body ol,
.modal-body ul {
  margin: 0 0 6px;
  padding-left: 20px;
}

.modal-body li {
  margin-bottom: 4px;
}

.modal-body strong {
  color: var(--fg);
  font-weight: 600;
}

.modal-body kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
}

.modal-sample {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-left: 3px solid var(--red);
  padding: 10px 12px;
  color: var(--fg);
  margin-bottom: 12px;
  word-break: break-word;
}

.modal-try {
  background-color: var(--bg-input);
  color: var(--fg);
  border: 1px solid var(--border);
}

.modal-try:hover {
  background-color: var(--red);
  border-color: var(--red);
  color: #fff;
}

@media (max-width: 640px) {
  .modal-header,
  .modal-body {
    padding-left: 16px;
    padding-right: 16px;
  }

  .modal-sep {
    margin-left: 16px;
    margin-right: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .modal {
    animation: none;
  }
}

/* ── Blacklist ─────────────────────────────────────────────────── */
.blacklist {
  margin-top: 10px;
}

.blacklist .section-label {
  margin-bottom: 5px;
}

.blacklist-control {
  display: flex;
  gap: 8px;
}

.blacklist-control input {
  flex: 1;
  min-width: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.blacklist-control input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--red-glow);
}

.blacklist-control input::placeholder {
  color: var(--fg-muted);
}

.blacklist-add {
  min-height: 36px;
  padding: 6px 16px;
  background-color: var(--bg-input);
  color: var(--fg-dim);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.blacklist-add:hover {
  color: var(--fg);
  background-color: var(--bg-hover);
  border-color: var(--fg-muted);
}

.blacklist-add:active {
  transform: scale(0.97);
}

.blacklist-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.blacklist-chips:empty {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 4px 3px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg);
}

.chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  color: var(--fg-dim);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip-remove:hover {
  background: var(--red);
  color: #fff;
}

/* ── Preferences ───────────────────────────────────────────────── */
.modal-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 11px 14px;
}

.switch-label strong {
  display: block;
  color: var(--fg);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.switch-label small {
  display: block;
  color: var(--fg-muted);
  font-size: 11px;
  margin-top: 1px;
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  width: 40px;
  height: 22px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  position: relative;
  transition: background 0.2s, border-color 0.2s;
}

.switch-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--fg-muted);
  border-radius: var(--radius-sm);
  transition: transform 0.2s, background 0.2s;
}

.switch input:checked + .switch-track {
  background: var(--red-dim);
  border-color: var(--red);
}

.switch input:checked + .switch-track::after {
  transform: translateX(20px);
  background: #fff;
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}
