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

:root {
  --primary: #3498db;
  --primary-dark: #2980b9;
  --light-bg: #f8f9fa;
  --border: #e0e0e0;
  --text: #333;
  --text-light: #666;
  --success: #2ecc71;
  --error: #e74c3c;
  --gray: #95a5a6;
  --highlight-bg: #ffeb3b;
  --highlight-text: #212121;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", sans-serif;
  background: linear-gradient(135deg, #f0f7ff, #e3f2fd);
  color: var(--text);
  line-height: 1.6;
  /* ✅ 关键：全局左右留白 100px */
  padding: 0 100px;
}

/* ✅ 移除原 .container max-width 和 padding，仅用于垂直居中 */
.container {
  max-width: none; /* 不限制宽度 */
  margin: 0 auto;
  padding: 20px 0; /* 仅上下 padding */
}

header {
  text-align: center;
  margin-bottom: 30px;
}

header h1 {
  font-size: 2.2rem;
  color: var(--primary);
  margin-bottom: 8px;
}

header p {
  color: var(--gray);
  font-size: 1rem;
}

/* ========== 双列布局核心修复 ========== */
.columns {
  display: flex;
  gap: 24px;
  width: 100%; /* 填满 padding 内区域 */
  margin-bottom: 24px;
}

.input-section,
.output-section {
  flex: 1; /* 等宽 */
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  min-height: 0;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

textarea,
input[type="text"] {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
  margin-bottom: 10px;
  transition: border-color 0.3s, box-shadow 0.3s;
}

textarea:focus,
input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

.regex-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.regex-wrapper input {
  width: 100%;
  min-width: 0;
}

.flags {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin: 0;
}

.flags label {
  font-size: 1rem;
  padding: 2px 6px;
  min-width: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  border: 1px solid #e0e0e0;
  cursor: pointer;
  background: #f8f9fa;
  user-select: none;
}

.flags label:hover {
  background: #e3f2fd;
  border-color: var(--primary);
}

.flags input[type="checkbox"] {
  margin-right: 4px;
  transform: scale(0.9);
}

.error-message {
  color: var(--error);
  font-size: 0.9rem;
  margin-top: 8px;
  min-height: 1.4em;
  padding-left: 2px;
}

.output-section h2 {
  margin-bottom: 16px;
  color: var(--primary);
}

.match-output {
  background: var(--light-bg);
  padding: 16px;
  border-radius: 6px;
  min-height: 200px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  border: 1px dashed var(--border);
  flex: 1;
  overflow: visible;
  flex-direction: column;
}

.match-output > * {
  flex: 0 0 auto;
}

.match-output .placeholder {
  color: var(--text-light);
  font-style: italic;
}

.match-output .highlight {
  background-color: var(--highlight-bg);
  color: var(--highlight-text);
  padding: 2px 4px;
  border-radius: 8px;
  font-weight: bold;
}

.match-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  font-size: 0.95rem;
  color: var(--text-light);
}

#copy-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s;
}

#copy-btn:hover {
  background: var(--primary-dark);
}

footer {
  text-align: center;
  margin-top: 20px;
  color: var(--text-light);
  font-size: 0.9rem;
}

footer a,
footer a:visited,
footer a:hover,
footer a:active {
  color: var(--text-light);
  text-decoration: none;
}

/* ========== 常用正则模板样式 ========== */
.templates-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

h3 {
  margin-bottom: 4px;
  color: var(--primary);
  font-size: 1.2rem;
}

.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.template-btn {
  padding: 8px 10px;
  background: #f1f9ff;
  border: 1px solid #d6eaf8;
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--primary-dark);
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.2s;
}

.template-btn:hover {
  background: #e3f2fd;
  border-color: var(--primary);
  transform: translateY(-1px);
}

.template-btn:active {
  transform: translateY(0);
}

/* ========== 响应式：移动端单列 ========== */
@media (max-width: 900px) {
  body {
    padding: 0 12px; /* 移动端留白小些 */
  }

  .columns {
    flex-direction: column;
    gap: 16px;
  }

  .input-section,
  .output-section {
    min-height: auto;
  }
}