:root {
  color-scheme: light;
  --bg: #dfe7f2;
  --bg-gradient-a: rgba(255, 255, 255, 0.7);
  --bg-gradient-b: #eef3f8;
  --bg-gradient-c: #d8e1eb;
  --bg-gradient-d: #c8d3df;
  --panel: rgba(248, 251, 254, 0.88);
  --panel-border: rgba(43, 63, 84, 0.14);
  --text: #17212b;
  --muted: #5f7084;
  --accent: #2e5b88;
  --accent-dark: #214569;
  --accent-soft: rgba(46, 91, 136, 0.14);
  --shadow: 0 20px 40px rgba(33, 52, 74, 0.14);
  --surface-input: rgba(255, 255, 255, 0.74);
  --surface-log: rgba(16, 24, 33, 0.96);
  --surface-log-text: #e6edf5;
  --surface-log-placeholder: rgba(230, 237, 245, 0.45);
  --highlight-bg: rgba(83, 161, 255, 0.44);
  --highlight-text: #ffffff;
  --highlight-border: rgba(149, 205, 255, 0.5);
  --highlight-shadow: rgba(83, 161, 255, 0.3);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --mono: "SFMono-Regular", "Consolas", "Liberation Mono", monospace;
  --sans: "Segoe UI", "Noto Sans TC", sans-serif;
}

body[data-theme="terminal-dark"] {
  color-scheme: dark;
  --bg: #0b1117;
  --bg-gradient-a: rgba(41, 64, 45, 0.28);
  --bg-gradient-b: #0d1319;
  --bg-gradient-c: #0a1015;
  --bg-gradient-d: #071017;
  --panel: rgba(13, 20, 26, 0.9);
  --panel-border: rgba(93, 129, 109, 0.2);
  --text: #d9e7df;
  --muted: #8ca298;
  --accent: #2fa36b;
  --accent-dark: #23784f;
  --accent-soft: rgba(47, 163, 107, 0.18);
  --shadow: 0 22px 44px rgba(0, 0, 0, 0.34);
  --surface-input: rgba(17, 27, 34, 0.92);
  --surface-log: rgba(3, 8, 11, 0.98);
  --surface-log-text: #d6f5e2;
  --surface-log-placeholder: rgba(214, 245, 226, 0.38);
  --highlight-bg: rgba(47, 196, 123, 0.4);
  --highlight-text: #ffffff;
  --highlight-border: rgba(126, 240, 176, 0.48);
  --highlight-shadow: rgba(47, 196, 123, 0.28);
}

body[data-theme="light-ops"] {
  color-scheme: light;
  --bg: #eef4f8;
  --bg-gradient-a: rgba(255, 255, 255, 0.8);
  --bg-gradient-b: #f7fafc;
  --bg-gradient-c: #edf3f7;
  --bg-gradient-d: #dbe8f1;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-border: rgba(73, 96, 122, 0.14);
  --text: #1f2c38;
  --muted: #627487;
  --accent: #2672b8;
  --accent-dark: #1d5a90;
  --accent-soft: rgba(38, 114, 184, 0.12);
  --shadow: 0 18px 38px rgba(64, 92, 122, 0.12);
  --surface-input: rgba(248, 251, 254, 0.96);
  --surface-log: rgba(245, 248, 251, 0.98);
  --surface-log-text: #233240;
  --surface-log-placeholder: rgba(35, 50, 64, 0.38);
  --highlight-bg: rgba(255, 210, 61, 0.5);
  --highlight-text: #3a2b00;
  --highlight-border: rgba(212, 166, 17, 0.42);
  --highlight-shadow: rgba(255, 210, 61, 0.2);
}

body[data-theme="amber-terminal"] {
  color-scheme: dark;
  --bg: #160f08;
  --bg-gradient-a: rgba(255, 183, 77, 0.18);
  --bg-gradient-b: #1c130a;
  --bg-gradient-c: #120b06;
  --bg-gradient-d: #0b0704;
  --panel: rgba(27, 18, 10, 0.9);
  --panel-border: rgba(198, 142, 62, 0.18);
  --text: #f5ddba;
  --muted: #c6a97f;
  --accent: #d78b2d;
  --accent-dark: #aa6c1f;
  --accent-soft: rgba(215, 139, 45, 0.16);
  --shadow: 0 24px 48px rgba(0, 0, 0, 0.34);
  --surface-input: rgba(38, 25, 14, 0.92);
  --surface-log: rgba(10, 6, 3, 0.98);
  --surface-log-text: #ffdca6;
  --surface-log-placeholder: rgba(255, 220, 166, 0.34);
  --highlight-bg: rgba(255, 176, 56, 0.46);
  --highlight-text: #fffaf0;
  --highlight-border: rgba(255, 216, 145, 0.46);
  --highlight-shadow: rgba(255, 176, 56, 0.28);
}

body[data-theme="minimal-mono"] {
  color-scheme: light;
  --bg: #e5e5e5;
  --bg-gradient-a: rgba(255, 255, 255, 0.66);
  --bg-gradient-b: #f3f3f3;
  --bg-gradient-c: #e4e4e4;
  --bg-gradient-d: #d4d4d4;
  --panel: rgba(250, 250, 250, 0.9);
  --panel-border: rgba(52, 52, 52, 0.12);
  --text: #151515;
  --muted: #666666;
  --accent: #2d2d2d;
  --accent-dark: #111111;
  --accent-soft: rgba(45, 45, 45, 0.08);
  --shadow: 0 16px 30px rgba(0, 0, 0, 0.08);
  --surface-input: rgba(255, 255, 255, 0.88);
  --surface-log: rgba(20, 20, 20, 0.98);
  --surface-log-text: #f3f3f3;
  --surface-log-placeholder: rgba(243, 243, 243, 0.36);
  --highlight-bg: rgba(214, 214, 214, 0.5);
  --highlight-text: #ffffff;
  --highlight-border: rgba(255, 255, 255, 0.34);
  --highlight-shadow: rgba(255, 255, 255, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(circle at top left, var(--bg-gradient-a), transparent 30%),
    linear-gradient(135deg, var(--bg-gradient-b) 0%, var(--bg-gradient-c) 42%, var(--bg-gradient-d) 100%);
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  width: calc(100vw - 32px);
  max-width: 100%;
  margin: 24px auto 40px;
}

.hero,
.panel {
  backdrop-filter: blur(18px);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
}

.hero {
  display: grid;
  grid-template-columns: 1.7fr 1fr;
  gap: 20px;
  padding: 28px;
  border-radius: 32px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.8rem;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.eyebrow-primary {
  font-weight: 800;
  font-size: 0.96rem;
  letter-spacing: 0.04em;
  text-transform: none;
}

.eyebrow-secondary {
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1.02;
  letter-spacing: -0.04em;
}

.hero-copy,
.panel-header p,
#summaryText {
  color: var(--muted);
}

.hero-copy {
  max-width: 66ch;
  margin-top: 14px;
  line-height: 1.65;
}

.hero-actions {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
}

.theme-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--muted);
  font-size: 0.95rem;
}

.theme-picker select {
  min-height: 48px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--surface-input);
  color: var(--text);
  padding: 0 14px;
}

.file-picker,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 999px;
  border: 0;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.file-picker {
  position: relative;
  padding: 0 20px;
  background: var(--accent);
  color: #fff8f3;
  font-weight: 700;
  box-shadow: 0 12px 30px rgba(173, 63, 38, 0.28);
}

.file-picker input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

button {
  padding: 0 20px;
  background: var(--accent);
  color: #fff8f3;
  font-weight: 700;
}

button:hover,
.file-picker:hover {
  transform: translateY(-1px);
}

.secondary-button {
  background: var(--surface-input);
  color: var(--text);
  border: 1px solid var(--panel-border);
  box-shadow: none;
}

.ghost-button {
  background: transparent;
  color: var(--muted);
  border: 1px dashed color-mix(in srgb, var(--panel-border) 75%, transparent);
}

.panel {
  margin-top: 18px;
  padding: 22px;
  border-radius: var(--radius-lg);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.panel-header h2 {
  font-size: 1.25rem;
}

.rules-table {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rule-row {
  display: grid;
  grid-template-columns: 140px 170px 170px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.rule-row-header {
  color: var(--muted);
  font-size: 0.92rem;
  padding: 0 6px;
}

.rule-pattern-input {
  width: 100%;
  min-height: 48px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--surface-input);
  padding: 0 14px;
  color: var(--text);
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--surface-input);
  color: var(--text);
}

.inline-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.action-row {
  display: flex;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.log-textarea {
  width: 100%;
  min-height: 260px;
  border-radius: 18px;
  border: 1px solid var(--panel-border);
  background: var(--surface-log);
  color: var(--surface-log-text);
  padding: 18px;
  font-family: var(--mono);
  font-size: 0.92rem;
  line-height: 1.6;
}

.result-header {
  align-items: center;
}

.result-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.compact-check {
  min-height: 44px;
  white-space: nowrap;
  justify-content: flex-start;
}

.result-output {
  min-height: calc(50 * 1.6em + 36px);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow: auto;
}

.result-output.is-empty::before {
  content: "套用過濾後的結果會顯示在這裡。";
  color: var(--surface-log-placeholder);
}

.result-line {
  display: block;
}

.result-highlight {
  background: var(--highlight-bg);
  color: var(--highlight-text);
  border-radius: 4px;
  font-weight: 700;
  padding: 0 1px;
  box-shadow:
    inset 0 0 0 1px var(--highlight-border),
    0 0 0 1px rgba(255, 255, 255, 0.03),
    0 0 10px var(--highlight-shadow);
}

.result-output.no-wrap {
  white-space: pre;
  overflow-x: auto;
  overflow-wrap: normal;
}

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

  .rule-row,
  .rule-row-header {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hero-actions {
    align-items: stretch;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100vw - 18px, 100%);
    margin-top: 10px;
  }

  .hero,
  .panel {
    padding: 18px;
    border-radius: 22px;
  }

  .rule-row,
  .rule-row-header {
    grid-template-columns: 1fr;
  }

  .action-row,
  .panel-header {
    flex-direction: column;
    align-items: stretch;
  }

  .result-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
}
