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

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface2: #1d1d1d;
  --gold: #ff3d3d;
  --gold-light: #ff6b6b;
  --gold-glow: rgba(255,61,61,.14);
  --purple: #ff3d3d;
  --purple-soft: #ff6b6b;
  --text: #f4f4f4;
  --text-soft: #a3a3a3;
  --text-muted: #6e6e6e;
  --border: rgba(255,255,255,.16);
  --border-soft: rgba(255,255,255,.08);
}

html.light {
  --bg: #f4f4f4;
  --surface: #ececec;
  --surface2: #e2e2e2;
  --gold: #dc2626;
  --gold-light: #b91c1c;
  --gold-glow: rgba(220,38,38,.12);
  --purple: #dc2626;
  --purple-soft: #b91c1c;
  --text: #111;
  --text-soft: #444;
  --text-muted: #777;
  --border: rgba(0,0,0,.16);
  --border-soft: rgba(0,0,0,.08);
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  transition: background 0.4s, color 0.4s;
  font-family: "Space Grotesk", system-ui, sans-serif;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(var(--border) 1px, transparent 1.4px);
  background-size: 30px 30px;
  -webkit-mask-image: radial-gradient(ellipse 80% 70% at 50% 0%, #000 0%, transparent 75%);
  mask-image: radial-gradient(ellipse 80% 70% at 50% 0%, #000 0%, transparent 75%);
  pointer-events: none;
  z-index: 0;
}

/* ── Layout ── */
.app {
  position: relative;
  z-index: 1;
  max-width: 900px;
  margin: 0 auto;
  padding: 3rem 1.5rem 5rem;
}

/* ── Header ── */
.header {
  text-align: center;
  margin-bottom: 3rem;
  animation: fadeDown 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.logo {
  font-family: "DotGothic16", monospace;
  font-size: 28px;
  font-weight: 400;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold-light);
  margin-bottom: 0.4rem;
}

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

.subtitle {
  font-size: 14px;
  font-weight: 300;
  color: var(--text-soft);
  letter-spacing: 0.05em;
}

/* ── Portfolio-style divider ── */
.orn-divider {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin: 1.4rem auto 0;
  max-width: 240px;
  opacity: .3;
}
.orn-divider::before, .orn-divider::after {
  content: "";
  flex: 1; height: 1px;
  background: linear-gradient(to right, transparent, var(--gold) 40%, var(--gold) 60%, transparent);
}
.orn-divider span { color: var(--gold); font-size: .85rem; display: flex; align-items: center; gap: .6rem; }

/* ── Mode tabs ── */
.mode-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 2.5rem;
  border: 1px solid var(--border-soft);
  animation: fadeDown 0.9s 0.1s cubic-bezier(0.22, 1, 0.36, 1) both;
  overflow: hidden;
}

.mode-tab {
  flex: 1;
  padding: 12px 20px;
  background: transparent;
  border: none;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.3s, color 0.3s;
  border-right: 1px solid var(--border-soft);
}
.mode-tab:last-child { border-right: none; }
.mode-tab.active {
  background: var(--gold-glow);
  color: var(--gold);
}
.mode-tab:hover:not(.active) {
  background: rgba(201,169,110,.03);
  color: var(--text-soft);
}

/* ── Main grid ── */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  animation: fadeUp 0.9s 0.2s cubic-bezier(0.22, 1, 0.36, 1) both;
}

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

/* ── Panel ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  padding: 1.5rem;
  position: relative;
  transition: border-color .35s;
}
.panel:hover { border-color: rgba(201,169,110,.25); }

.panel-title {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--purple-soft);
  margin-bottom: 1.2rem;
}

/* ── Fields ── */
.field { margin-bottom: 1rem; }

.field label {
  display: block;
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--purple-soft);
  margin-bottom: 6px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border-soft);
  color: var(--text);
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 14px;
  padding: 9px 12px;
  outline: none;
  transition: border-color .25s;
  resize: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 20px rgba(201,169,110,.06);
}

.field select option { background: var(--surface); }

/* ── Tags input ── */
.tags-wrap {
  background: var(--surface2);
  border: 1px solid var(--border-soft);
  padding: 6px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 42px;
  align-items: center;
  transition: border-color .25s;
  cursor: text;
}
.tags-wrap:focus-within { border-color: var(--gold); }

.tag {
  background: var(--gold-glow);
  border: 1px solid var(--border);
  padding: 2px 8px;
  font-size: 12px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 5px;
}

.tag-remove {
  cursor: pointer;
  color: var(--text-muted);
  font-style: normal;
  font-size: 11px;
  line-height: 1;
  background: transparent;
  border: none;
  padding: 0;
  transition: color .2s;
}
.tag-remove:hover { color: var(--gold); }

.tags-input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 14px;
  flex: 1;
  min-width: 80px;
  padding: 2px 0;
}

.tags-input::placeholder { color: var(--text-muted); }

/* ── Templates ── */
.templates {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 1.2rem;
}

.tpl-btn {
  background: transparent;
  border: 1px solid var(--border-soft);
  padding: 5px 12px;
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .25s, border-color .25s, color .25s;
}
.tpl-btn:hover {
  background: var(--gold-glow);
  border-color: var(--gold);
  color: var(--gold);
}

/* ── Output panel ── */
.output-panel {
  grid-column: 1 / -1;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  padding: 1.5rem;
  transition: border-color .35s;
}
.output-panel:hover { border-color: rgba(201,169,110,.25); }

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.output-title {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--purple-soft);
}

.output-actions { display: flex; gap: 8px; }

.action-btn {
  background: transparent;
  border: 1px solid var(--border-soft);
  padding: 6px 14px;
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .25s, border-color .25s, color .25s;
}
.action-btn:hover {
  background: var(--gold-glow);
  border-color: var(--gold);
  color: var(--gold);
}

.action-btn.copied {
  color: var(--gold);
  border-color: var(--gold);
}

.output-text {
  background: var(--surface2);
  border: 1px solid var(--border-soft);
  padding: 1.2rem;
  font-size: 15px;
  color: var(--text);
  line-height: 1.8;
  min-height: 100px;
  white-space: pre-wrap;
  word-break: break-word;
}

.output-placeholder { color: var(--text-muted); }

/* ── History ── */
.history-section {
  margin-top: 2rem;
  animation: fadeUp 0.9s 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.section-title {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--purple-soft);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  padding: 12px 16px;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  transition: background .25s, border-color .25s;
}
.history-item:hover {
  background: var(--gold-glow);
  border-color: var(--gold);
}

.history-text {
  font-size: 13px;
  color: var(--text-soft);
  flex: 1;
  overflow: hidden;
  display: -webkit-box;
  line-clamp: 2;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.5;
}

.history-meta {
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.history-empty {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 1.5rem;
}

/* ── Char counter ── */
.char-count {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  margin-top: 4px;
}

/* ── Mode panels ── */
.mode-panel { display: none; }
.mode-panel.active { display: contents; }

.mode-tab:focus-visible,
.tpl-btn:focus-visible,
.action-btn:focus-visible,
.tags-input:focus-visible,
#theme-btn:focus-visible {
  outline: 1px solid var(--gold);
  outline-offset: 2px;
}

.theme-btn {
  position: fixed;
  top: 1.2rem;
  right: 1.2rem;
  z-index: 100;
  background: transparent;
  border: 1px solid var(--border-soft);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: background .25s, border-color .25s, color .25s;
}

.theme-btn:hover {
  background: var(--gold-glow);
  border-color: var(--gold);
  color: var(--gold);
}

.theme-icon { width: 16px; height: 16px; }
.theme-icon.sun { display: none; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── Animations ── */
@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Mobile ── */
@media (max-width: 640px) {
  .app { padding: 1.5rem 1rem 3rem; }
  .header { margin-bottom: 2rem; }
  .logo { font-size: 24px; }
  .subtitle { font-size: 12px; }
  .mode-tabs { margin-bottom: 1.5rem; }
  .mode-tab { padding: 10px 12px; font-size: 9px; }
  .panel { padding: 1rem; }
  .panel-title { font-size: 9px; margin-bottom: 0.8rem; }
  .field { margin-bottom: 0.75rem; }
  .field label { font-size: 9px; margin-bottom: 4px; }
  .field input, .field select, .field textarea { font-size: 13px; padding: 8px 10px; }
  .templates { gap: 4px; margin-bottom: 1rem; }
  .tpl-btn { padding: 4px 8px; font-size: 8px; }
  .output-panel { padding: 1rem; }
  .output-header { flex-direction: column; gap: 0.75rem; margin-bottom: 0.75rem; }
  .output-title { font-size: 9px; }
  .output-actions { flex-wrap: wrap; gap: 6px; width: 100%; }
  .action-btn { flex: 1; min-width: 70px; padding: 5px 8px; font-size: 8px; }
  .output-text { font-size: 13px; padding: 1rem; min-height: 80px; }
  .history-section { margin-top: 1.5rem; }
  .history-item { padding: 10px 12px; font-size: 12px; }
  .history-text { font-size: 12px; }
  .history-meta { font-size: 8px; }
  .char-count { font-size: 10px; }
  .theme-btn { width: 32px; height: 32px; }
  .theme-icon { width: 14px; height: 14px; }
}
