/* ===== CSS Reset ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ===== Theme Variables ===== */
:root {
  --bg-primary: #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #eef2ff;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);
  --radius: 8px;
  --radius-lg: 12px;
  --font-mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', 'Courier New', monospace;
  --transition: 200ms ease;
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-light: #1e1b4b;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4), 0 2px 4px -2px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.5), 0 4px 6px -4px rgba(0,0,0,0.4);
}

/* ===== Base ===== */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ===== Buttons ===== */
.btn-back {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
  transition: all var(--transition);
}
.btn-back:hover {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.btn-icon:hover {
  background: var(--accent-light);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:hover {
  background: var(--accent-light);
  border-color: var(--accent);
}
.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-sm {
  padding: 4px 12px;
  font-size: 0.8125rem;
}

.btn-group {
  display: flex;
  gap: 1px;
  flex-wrap: wrap;
}
.btn-group .btn {
  border-radius: 0;
}
.btn-group .btn:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
}
.btn-group .btn:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* ===== Main Content ===== */
.app-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px;
  min-height: calc(100vh - 140px);
}

/* ===== Card Grid (Homepage) ===== */
.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 24px 0 12px;
  padding: 0 4px;
}
.section-title:first-child {
  margin-top: 0;
}

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

.card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  font-family: inherit;
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
}
.card:active {
  transform: translateY(0);
}

.card-icon {
  font-size: 2rem;
  flex-shrink: 0;
  width: 48px;
  text-align: center;
}

.card-info {
  min-width: 0;
}
.card-name {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 2px;
}
.card-desc {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Tool/Game Detail View ===== */
.detail-view {
  animation: fadeIn 0.2s ease;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.detail-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
}

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

/* ===== Form Elements ===== */
.input, .textarea, .select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-family: inherit;
  background: var(--bg-secondary);
  color: var(--text-primary);
  transition: border-color var(--transition);
}
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.input-mono, .textarea-mono {
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

.textarea {
  resize: vertical;
  min-height: 180px;
  line-height: 1.5;
}

.select {
  cursor: pointer;
  width: auto;
  min-width: 120px;
}

label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 4px;
}

.form-group {
  margin-bottom: 14px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  margin-right: 6px;
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.checkbox-group label {
  display: inline-flex;
  align-items: center;
  margin-bottom: 0;
  cursor: pointer;
}

/* ===== Output / Preview Panels ===== */
.output-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 60px;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  overflow: auto;
  max-height: 500px;
  white-space: pre-wrap;
  word-break: break-all;
}

.output-panel.error {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(239,68,68,0.05);
}

/* ===== Split Pane ===== */
.split-pane {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
.split-pane .textarea {
  min-height: 400px;
}
.split-pane .output-panel {
  min-height: 400px;
  max-height: 600px;
}

/* ===== Status Bar ===== */
.status-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 8px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ===== Color Swatches ===== */
.swatch-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: transform var(--transition);
}
.swatch:hover {
  transform: scale(1.2);
  border-color: var(--accent);
}

.color-preview {
  width: 100%;
  height: 80px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 16px;
  transition: background-color 0.2s ease;
}

/* ===== Password Strength ===== */
.strength-bar {
  height: 6px;
  border-radius: 3px;
  margin-top: 8px;
  transition: width 0.3s ease, background-color 0.3s ease;
  background: var(--border);
}
.strength-bar.weak { background: var(--danger); width: 33%; }
.strength-bar.medium { background: var(--warning); width: 66%; }
.strength-bar.strong { background: var(--success); width: 100%; }

.password-display {
  display: flex;
  gap: 8px;
}
.password-display .input {
  font-family: var(--font-mono);
  font-size: 1.125rem;
  letter-spacing: 1px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--bg-primary);
  padding: 10px 24px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  z-index: 1000;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 1.7s forwards;
  pointer-events: none;
}

/* ===== Error / Info messages ===== */
.error-msg {
  color: var(--danger);
  font-size: 0.875rem;
  margin-top: 8px;
}
.info-note {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ===== Loading state ===== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
}
.loading::after {
  content: '';
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 10px;
}

/* ===== Noscript ===== */
.noscript-msg {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  font-size: 1.125rem;
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(-50%) translateY(0); }
  to   { opacity: 0; transform: translateX(-50%) translateY(10px); }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .app-header {
    padding: 10px 14px;
  }
  .app-title {
    font-size: 1.1rem;
  }
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
  }
  .split-pane {
    grid-template-columns: 1fr;
  }
  .split-pane .textarea,
  .split-pane .output-panel {
    min-height: 250px;
    max-height: 400px;
  }
  .detail-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 480px) {
  .app-main {
    padding: 16px 10px;
  }
  .card-grid {
    grid-template-columns: 1fr;
  }
  .card {
    padding: 14px 16px;
    gap: 10px;
  }
  .card-icon {
    font-size: 1.5rem;
    width: 36px;
  }
  .btn-group {
    width: 100%;
  }
  .btn-group .btn {
    flex: 1;
  }
}
