* {
  box-sizing: border-box;
}

:root {
  --bg: #0f0f12;
  --surface: #1a1a20;
  --surface-elevated: #24242c;
  --border: #2e2e38;
  --text: #e8e8ed;
  --text-muted: #9090a0;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --success: #22c55e;
  --warning: #f59e0b;
  --orange: #f97316;
  --radius: 12px;
}

body {
  margin: 0;
  font-family: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: auto 1fr auto auto;
  min-height: 100vh;
  gap: 0;
}

.header {
  grid-column: 1 / -1;
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--border);
}

.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.header h1 {
  margin: 0 0 0.25rem 0;
  font-size: 1.5rem;
  font-weight: 600;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.lang-btn {
  flex-shrink: 0;
  padding: 0.35rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--surface-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

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

/* 控制面板 */
.controls {
  padding: 1.25rem;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--surface);
  overflow-y: auto;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.control-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.control-divider {
  height: 1px;
  background: var(--border);
  margin: 0.25rem 0;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.slider-row input[type="range"] {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 3px;
  cursor: pointer;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.slider-row input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.slider-row span {
  min-width: 3rem;
  font-size: 0.85rem;
  font-family: "SF Mono", Consolas, monospace;
  color: var(--text);
}

#radius-input,
#box-width-input,
#box-height-input {
  width: 100%;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  font-family: monospace;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}

#radius-input:focus,
#box-width-input:focus,
#box-height-input:focus {
  outline: none;
  border-color: var(--accent);
}

select {
  padding: 0.5rem 0.6rem;
  font-size: 0.85rem;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
}

select:focus {
  outline: none;
  border-color: var(--accent);
}

/* 补偿信息显示 */
.comp-ratio-display {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface-elevated);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}

.comp-ratio-display.algo {
  border-left-color: var(--orange);
}

.comp-ratio-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex: 1;
}

.comp-ratio-num {
  font-size: 0.9rem;
  font-weight: 700;
  font-family: "SF Mono", Consolas, monospace;
  color: var(--accent);
}

.comp-ratio-display.algo .comp-ratio-num {
  color: var(--orange);
}

.comp-ratio-result {
  font-size: 0.8rem;
  font-family: "SF Mono", Consolas, monospace;
  color: var(--text-muted);
}

.comp-btn {
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s;
}

.comp-btn:hover {
  background: var(--accent-hover);
}

/* 2x2 对比网格 */
.comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 1rem;
  padding: 1.5rem;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.panel h2 {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
}

.panel h3.panel-subtitle {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: "SF Mono", Consolas, monospace;
  text-align: center;
}

.panel-a .panel-subtitle { color: var(--accent); }
.panel-b .panel-subtitle { color: var(--orange); }
.panel-c .panel-subtitle { color: var(--success); }
.panel-d .panel-subtitle { color: var(--warning); }

.preview-container {
  flex: 1;
  min-height: 240px;
  background: #6b7280;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  border-radius: 8px;
}

.preview-box {
  width: 200px;
  height: 200px;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: border-radius 0.15s ease, corner-shape 0.15s ease, width 0.2s ease, height 0.2s ease;
}

/* 面板描述文字 */
.panel-desc {
  margin: 0;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.3;
  opacity: 0.8;
}

/* 补偿原理说明 */
.explanation {
  grid-column: 1 / -1;
  padding: 1.5rem 2rem;
  border-top: 1px solid var(--border);
}

.explanation > h3 {
  margin: 0 0 1rem 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.explain-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.explain-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  border-top: 3px solid var(--border);
}

.explain-card.card-depth {
  border-top-color: var(--accent);
}

.explain-card.card-area {
  border-top-color: var(--orange);
}

.explain-card h4 {
  margin: 0 0 0.6rem 0;
  font-size: 0.85rem;
  font-weight: 600;
}

.card-depth h4 { color: var(--accent); }
.card-area h4 { color: var(--orange); }

.explain-card p {
  margin: 0 0 0.5rem 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.explain-card p:last-child {
  margin-bottom: 0;
}

.explain-formula {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 0.75rem !important;
  background: var(--surface-elevated);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  color: var(--text) !important;
}

.explain-trait {
  font-weight: 500;
  color: var(--text) !important;
}

.explain-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1.25rem;
}

.explain-summary p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.explain-summary strong {
  color: var(--text);
}

/* CSS 代码输出 */
.css-output-wrap {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 1rem 2rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.css-output {
}

.css-output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.css-output-header h3 {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.css-output pre {
  margin: 0;
  padding: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
}

.css-output code {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 0.8rem;
  color: var(--text);
  line-height: 1.6;
  white-space: pre;
}

/* footer */
.footer {
  grid-column: 1 / -1;
  padding: 1rem 2rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.footer p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* 响应式 */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto auto auto;
  }

  .controls {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .comparison {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
  }

  .explain-grid {
    grid-template-columns: 1fr;
  }

  .css-output-wrap {
    grid-template-columns: 1fr;
  }
}
