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

:root {
  --bg:         #0d0f14;
  --surface:    #13161d;
  --card:       #181c25;
  --panel:      #1c2030;
  --border:     #252a36;
  --border-hi:  #2f3647;
  --accent:     #00e5a0;
  --accent2:    #0099ff;
  --accent-dim: #00b07a;
  --danger:     #ff4d6d;
  --warn:       #ffb627;
  --text:       #e2e8f0;
  --muted:      #64748b;
  --mono:       'JetBrains Mono', monospace;
  --sans:       'Syne', sans-serif;
}

html, body { height: 100%; }

body {
  font-family: var(--mono);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed; inset: 0;
  background-image:
    linear-gradient(rgba(0,229,160,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,229,160,.025) 1px, transparent 1px);
  background-size: 44px 44px;
  pointer-events: none; z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  width: 700px; height: 700px; border-radius: 50%;
  background: radial-gradient(circle, rgba(0,229,160,.05) 0%, transparent 70%);
  top: -200px; right: -150px;
  pointer-events: none; z-index: 0;
}

.page {
  position: relative; z-index: 1;
  display: flex; flex-direction: column;
  min-height: 100vh;
  padding: 1.75rem 1.5rem 2rem;
  max-width: 1400px; margin: 0 auto; width: 100%;
  gap: .75rem;
}

/* Header */
.header { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.header-left .tag {
  font-size: .68rem; letter-spacing: .18em; text-transform: uppercase;
  color: var(--accent); margin-bottom: .35rem;
  display: flex; align-items: center; gap: .4rem;
}
.header-left .tag::before { content: '>'; }
h1 { font-family: var(--sans); font-size: 1.9rem; font-weight: 700; letter-spacing: -.015em; line-height: 1; }
h1 span { color: var(--accent); }
.header-meta { font-size: .68rem; color: var(--muted); line-height: 1.7; text-align: right; }

/* Pattern bar */
.pattern-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .9rem 1.1rem;
}
.pattern-row { display: flex; align-items: center; gap: .5rem; }
.pattern-delim { font-size: 1.3rem; color: var(--accent); line-height: 1; flex-shrink: 0; user-select: none; }
.pattern-input {
  flex: 1; min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .55rem .75rem;
  font-family: var(--mono); font-size: .88rem;
  color: var(--text); outline: none;
  transition: border-color .15s;
  caret-color: var(--accent);
}
.pattern-input:focus { border-color: var(--accent); }
.pattern-input.is-error { border-color: var(--danger); }

.flags-group { display: flex; gap: .25rem; flex-shrink: 0; }
.flag-btn {
  width: 26px; height: 26px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  color: var(--muted);
  font-family: var(--mono); font-size: .72rem; font-weight: 500;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .12s;
}
.flag-btn:hover { border-color: var(--border-hi); color: var(--text); }
.flag-btn.active { background: var(--accent); border-color: var(--accent); color: #0d0f14; font-weight: 700; }

.pattern-meta { display: flex; align-items: center; justify-content: space-between; margin-top: .5rem; min-height: 1rem; }
.pattern-error { font-size: .71rem; color: var(--danger); }
.match-count { font-size: .71rem; color: var(--muted); margin-left: auto; }
.match-count strong { color: var(--accent); }

/* Panels */
.panels { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; min-height: 0; }

.panel {
  display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden; min-height: 360px;
}
.panel-header {
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface); flex-shrink: 0;
}
.panel-title { font-size: .65rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); flex: 1; }
.panel-badge { font-size: .6rem; padding: .15rem .45rem; border-radius: 4px; letter-spacing: .06em; text-transform: uppercase; font-weight: 600; }
.badge-idle    { background: rgba(100,116,139,.1);  color: var(--muted);  border: 1px solid var(--border); }
.badge-match   { background: rgba(0,229,160,.12);   color: var(--accent); border: 1px solid rgba(0,229,160,.25); }
.badge-nomatch { background: rgba(255,77,109,.12);  color: var(--danger); border: 1px solid rgba(255,77,109,.2); }
.panel-action {
  font-size: .65rem; color: var(--muted); cursor: pointer;
  padding: .2rem .45rem; border-radius: 4px;
  border: 1px solid transparent; background: none;
  font-family: var(--mono); transition: all .12s;
  display: flex; align-items: center; gap: .3rem;
}
.panel-action:hover { color: var(--text); border-color: var(--border-hi); background: var(--card); }

textarea {
  flex: 1; width: 100%;
  background: transparent; border: none; outline: none;
  padding: 1rem;
  font-family: var(--mono); font-size: .81rem;
  color: var(--text); resize: none; line-height: 1.75;
  caret-color: var(--accent);
}
textarea::placeholder { color: var(--muted); opacity: .55; }
textarea:focus { background: rgba(0,229,160,.012); }

/* Highlight output */
.highlight-output {
  flex: 1; padding: 1rem;
  font-family: var(--mono); font-size: .81rem;
  line-height: 1.75; white-space: pre-wrap; word-break: break-all;
  color: var(--muted); overflow-y: auto;
}
.highlight-output.has-text { color: var(--text); }
.empty-hint { color: var(--muted); opacity: .5; font-style: italic; }
mark.m0 { background: rgba(0,229,160,.28); color: var(--accent); border-radius: 2px; padding: 0 1px; font-weight: 500; }
mark.m1 { background: rgba(0,153,255,.22); color: #7dd3fc; border-radius: 2px; padding: 0 1px; font-weight: 500; }
mark.m2 { background: rgba(251,191,36,.18); color: #fbbf24; border-radius: 2px; padding: 0 1px; font-weight: 500; }
mark.m3 { background: rgba(192,132,252,.18); color: #c084fc; border-radius: 2px; padding: 0 1px; font-weight: 500; }

/* Matches panel */
.matches-section {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
}
.matches-header {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.matches-title { font-size: .65rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.matches-sub { font-size: .65rem; color: var(--muted); margin-left: auto; }
.match-list { padding: .6rem; display: flex; flex-direction: column; gap: .35rem; max-height: 280px; overflow-y: auto; }
.match-item {
  border: 1px solid var(--border); border-radius: 8px;
  padding: .55rem .75rem; font-size: .75rem;
}
.match-item-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; margin-bottom: .3rem;
}
.match-num { font-size: .63rem; color: var(--muted); font-weight: 600; }
.match-pos { font-size: .63rem; color: var(--muted); }
.match-val {
  font-family: var(--mono); color: var(--accent);
  background: rgba(0,229,160,.07); border: 1px solid rgba(0,229,160,.15);
  border-radius: 4px; padding: .2rem .5rem;
  font-size: .79rem; word-break: break-all;
  display: block; margin-bottom: .3rem;
}
.match-groups { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .3rem; }
.group-chip {
  font-size: .63rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 3px;
  padding: .12rem .38rem; color: var(--muted);
}
.group-chip em { font-style: normal; color: #7dd3fc; }

/* Cheat sheet */
.cheat-section { background: var(--card); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.cheat-toggle {
  width: 100%; padding: .7rem 1.1rem;
  background: none; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  color: var(--muted); font-family: var(--mono); font-size: .7rem;
  letter-spacing: .1em; text-transform: uppercase; transition: color .12s;
}
.cheat-toggle:hover { color: var(--text); }
.cheat-toggle svg { transition: transform .2s; flex-shrink: 0; }
.cheat-toggle.open svg { transform: rotate(180deg); }
.cheat-body {
  display: none; padding: .9rem 1.1rem 1rem;
  border-top: 1px solid var(--border);
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: .3rem .75rem;
}
.cheat-body.open { display: grid; }
.cheat-row { display: flex; align-items: center; gap: .5rem; font-size: .71rem; }
.cheat-sym {
  font-family: var(--mono); color: var(--accent);
  background: rgba(0,229,160,.08); border-radius: 3px;
  padding: .1rem .35rem; min-width: 2.8rem; text-align: center; flex-shrink: 0;
}
.cheat-desc { color: var(--muted); }

/* Footer */
.footer-note { font-size: .63rem; color: var(--muted); text-align: center; margin-top: .25rem; letter-spacing: .04em; }
.footer-note a { color: var(--accent-dim); text-decoration: none; }
.footer-note a:hover { color: var(--accent); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* Animation */
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.page { animation: fadeUp .35s ease both; }

@media (max-width: 780px) {
  .panels { grid-template-columns: 1fr; }
  .header-meta { display: none; }
}
@media (max-width: 500px) {
  .flags-group { flex-wrap: wrap; }
}

/* ── Site Nav ── */
.site-nav {
  position: sticky; top: 0; z-index: 1000;
  background: rgba(13,15,20,.92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.site-nav-inner {
  display: flex; align-items: center; height: 56px; gap: 2rem;
  max-width: 1400px; margin: 0 auto; padding: 0 2rem; width: 100%;
}
.nav-logo {
  font-family: var(--mono); font-size: .85rem; font-weight: 700;
  color: var(--accent); text-decoration: none; letter-spacing: -.01em;
  white-space: nowrap; display: flex; align-items: center; gap: .15rem;
}
.nav-logo .brace { color: var(--muted); font-weight: 400; }
.nav-links { display: flex; align-items: center; gap: 1.5rem; flex: 1; }
.nav-links a { font-family: var(--mono); font-size: .78rem; color: var(--muted); text-decoration: none; letter-spacing: .03em; transition: color .14s; }
.nav-links a:hover { color: var(--text); }
.nav-dropdown { position: relative; }
.nav-dropdown-toggle {
  display: inline-flex; align-items: center; gap: .35rem;
  background: none; border: none; cursor: pointer;
  font-family: var(--mono); font-size: .78rem;
  color: var(--accent); padding: 0; letter-spacing: .03em; transition: color .14s;
}
.nav-dropdown-toggle:hover { color: #00ffb3; }
.nav-dropdown-toggle svg { transition: transform .2s ease; }
.nav-dropdown.open .nav-dropdown-toggle svg { transform: rotate(180deg); }
.nav-dropdown-menu {
  position: absolute; top: calc(100% + 1rem); left: 50%; transform: translateX(-50%);
  min-width: 210px; background: #181c25;
  border: 1px solid var(--border-hi); border-radius: 10px;
  padding: .4rem; display: none; flex-direction: column; gap: .15rem;
  box-shadow: 0 12px 32px rgba(0,0,0,.6); z-index: 999;
}
.nav-dropdown.open .nav-dropdown-menu { display: flex; animation: dropIn .15s ease both; }
.nav-dropdown-menu a {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .75rem; border-radius: 7px;
  font-size: .75rem; color: #94a3b8; text-decoration: none;
  transition: background .12s, color .12s; white-space: nowrap; letter-spacing: .02em;
}
.nav-dropdown-menu a:hover { background: rgba(0,229,160,.07); color: var(--accent); }
.nav-dropdown-menu a.active { background: rgba(0,229,160,.1); color: var(--accent); }
.nav-dropdown-menu a svg { opacity: .55; flex-shrink: 0; }
.nav-dropdown-menu a:hover svg, .nav-dropdown-menu a.active svg { opacity: 1; }
@keyframes dropIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-6px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.nav-cv {
  font-family: var(--mono); font-size: .72rem; font-weight: 700;
  padding: .35rem .85rem; border-radius: 6px;
  background: var(--accent); color: #0d0f14; text-decoration: none;
  letter-spacing: .05em; transition: background .14s; white-space: nowrap; margin-left: auto;
}
.nav-cv:hover { background: #00ffb3; }
@media (max-width: 640px) {
  .nav-links a:not(.nav-dropdown-toggle) { display: none; }
}
