/* ---------- Design tokens ---------- */
:root {
  --font-ui: 'Space Grotesk', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  --accent: #7C5CD6;      /* keyword purple */
  --accent-2: #E0954A;    /* string amber */

  --red: #DC2626;
  --blue: #2563EB;
  --green: #16A34A;
  --focus-blue: #8EC1FF;  /* light shade for box focus border */

  --topbar-h: 56px;
  --toolbar-h: 52px;
  --line-h: 21px;
  --radius: 6px;
  --bottom-gap: 22px;
}

html[data-theme="light"] {
  --bg: #F5F6F4;
  --surface: #FFFFFF;
  --surface-2: #EFF1EE;
  --text: #1B1E1F;
  --text-dim: #6B7278;
  --border: #DCE0DD;
  --focus-ring: #7C5CD655;
  --box-bg: #FFFFFF;
  --box-text: #1B1E1F;
  --gutter-bg: #EEEFF1;
  --gutter-fg: #9AA0A8;
}

html[data-theme="dark"] {
  --bg: #14171C;
  --surface: #1B1F26;
  --surface-2: #21262F;
  --text: #E6E8EA;
  --text-dim: #8B93A0;
  --border: #2A2F38;
  --focus-ring: #9C82F455;
  --box-bg: #1B1F26;
  --box-text: #E6E8EA;
  --gutter-bg: #12151A;
  --gutter-fg: #5B6472;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  padding-bottom: var(--bottom-gap);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Top bar ---------- */
.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-name {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 23px;
  letter-spacing: 0.01em;
}

/* Theme toggle */
.theme-switch { background: none; border: none; padding: 0; cursor: pointer; }
.theme-switch-track {
  width: 54px;
  height: 30px;
  border-radius: 999px;
  background: #CFE8FF;
  border: 1px solid #AFD8FA;
  position: relative;
  display: inline-block;
  transition: background 0.15s ease, border-color 0.15s ease;
}
html[data-theme="dark"] .theme-switch-track {
  background: #232B3A;
  border-color: #333D4F;
}
.theme-switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}
html[data-theme="dark"] .theme-switch-thumb { transform: translateX(24px); }

.theme-switch-thumb .icon {
  position: absolute;
  opacity: 0;
  color: #6B7278;
  transition: opacity 0.15s ease;
}
html[data-theme="light"] .icon-sun { opacity: 1; color: #E0954A; }
html[data-theme="dark"] .icon-moon { opacity: 1; color: #3B4252; }

/* Reusable checkbox-switch track/thumb (Ignore empty lines) */
.switch-track {
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  position: relative;
  display: inline-block;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.15s ease, background 0.15s ease;
}

/* ---------- Toolbar ---------- */
.toolbar {
  flex: 0 0 auto;
  min-height: var(--toolbar-h);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 20px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field label, .field > span:first-child {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
}

.field input[type="text"],
.field input[type="number"] {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 8px;
}

#delimiterInput { width: 64px; text-align: center; color: var(--accent-2); font-weight: 500; }
#groupSizeInput { width: 64px; }

.count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-dim);
}

/* Checkbox-based switch */
.switch { position: relative; display: inline-flex; align-items: center; }
.switch input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 42px;
  height: 24px;
  margin: 0;
  cursor: pointer;
}
.switch input:checked ~ .switch-track { background: var(--green); border-color: var(--green); }
.switch input:checked ~ .switch-track .switch-thumb { transform: translateX(18px); background: #fff; }
.switch input:focus-visible ~ .switch-track { outline: 2px solid var(--green); outline-offset: 2px; }
.toggle-field { cursor: pointer; }

/* ---------- Panels ---------- */
.panels {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  overflow: hidden;
}

.panel {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-height: 0;
}

.panel-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--surface);
}

.panel-title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-dim);
}

.ghost-btn {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius);
  padding: 4px 14px;
  cursor: pointer;
  border: 1.5px solid transparent;
}

#clearBtn {
  color: var(--red);
  background: transparent;
  border-color: var(--red);
}
#clearBtn:hover { background: var(--red); color: #fff; }

#copyBtn {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}
#copyBtn:hover { filter: brightness(1.08); }
#copyBtn.copied {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

/* Editor: gutter + textarea, styled as one bordered box */
.editor {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  margin: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.12s ease, border-width 0.12s ease;
}
.editor:focus-within {
  border: 3px solid var(--focus-blue);
}

.gutter {
  flex: 0 0 auto;
  padding: 10px 8px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: var(--line-h);
  color: var(--gutter-fg);
  background: var(--gutter-bg);
  overflow: hidden;
  user-select: none;
  min-width: 34px;
}

textarea {
  flex: 1 1 auto;
  border: none;
  resize: none;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: var(--line-h);
  color: var(--box-text);
  background: var(--box-bg);
  white-space: pre;
  overflow: auto;
}

textarea:focus { outline: none; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .panels {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
  .toolbar { gap: 14px 20px; }
  .count { margin-left: 0; width: 100%; }
}
