/* 四码方图 · 四万 — V1.0 样式 */

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

:root {
  --bg: #fafafa;
  --panel-bg: #ffffff;
  --panel-border: #e0e0e0;
  --text: #212121;
  --text-muted: #757575;
  --accent: #1976d2;
  --accent-hover: #1565c0;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.12);
  --radius: 6px;
  --grid-size: min(85vh, 900px);
  --cell-size: calc(var(--grid-size) / 100);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== Header ===== */
.app-header {
  padding: 12px 24px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 600;
}

.app-header .codename {
  color: var(--accent);
  font-weight: 700;
}

.app-header .meta {
  color: var(--text-muted);
  font-size: 13px;
}

.app-header .meta .dot {
  margin: 0 8px;
  color: #ccc;
}

/* ===== Main layout ===== */
.app-main {
  flex: 1;
  display: flex;
  gap: 16px;
  padding: 16px;
  min-height: 0;
}

/* ===== Control panel ===== */
.control-panel {
  width: 280px;
  flex-shrink: 0;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  overflow-y: auto;
  max-height: calc(100vh - 100px);
}

.ctrl-group {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid #f0f0f0;
}

.ctrl-group:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.ctrl-group h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.ctrl-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 8px;
  color: var(--text);
}

.ctrl-group label > span {
  flex-shrink: 0;
  min-width: 70px;
}

.ctrl-group input[type="date"] {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  background: white;
}

.ctrl-group input[type="date"]:focus {
  outline: none;
  border-color: var(--accent);
}

/* ===== Slider ===== */
.slider-row {
  margin-bottom: 8px;
}

#date-slider {
  width: 100%;
  height: 24px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}

#date-slider::-webkit-slider-runnable-track {
  height: 4px;
  background: #e0e0e0;
  border-radius: 2px;
}

#date-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  height: 18px;
  width: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: grab;
  margin-top: -7px;
  box-shadow: var(--shadow);
}

#date-slider::-webkit-slider-thumb:active {
  cursor: grabbing;
  background: var(--accent-hover);
}

#date-slider::-moz-range-thumb {
  height: 18px;
  width: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: grab;
  border: none;
  box-shadow: var(--shadow);
}

.slider-readout {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 4px;
}

.slider-readout strong {
  color: var(--accent);
  font-weight: 600;
}

.slider-readout .period-count {
  color: var(--text-muted);
  margin-left: 4px;
  font-size: 12px;
}

.slider-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Switch ===== */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.toggle {
  width: 36px;
  height: 20px;
  -webkit-appearance: none;
  appearance: none;
  background: #ccc;
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle:checked {
  background: var(--accent);
}

.toggle::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: var(--shadow);
}

.toggle:checked::before {
  transform: translateX(16px);
}

.toggle-label {
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== Color pickers ===== */
.custom-colors {
  margin-top: 10px;
  opacity: 0.4;
  pointer-events: none;
  transition: opacity 0.2s;
}

.custom-colors.enabled {
  opacity: 1;
  pointer-events: auto;
}

.color-pick {
  margin-bottom: 8px;
}

.color-pick label {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot-color {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  display: inline-block;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.color-pick input[type="color"] {
  width: 36px;
  height: 24px;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  background: none;
}

.color-pick input[type="color"]:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.color-pick.combo label {
  font-weight: 500;
  color: var(--text);
}

.default-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
  padding: 8px;
  background: #fafafa;
  border-radius: 4px;
  border-left: 3px solid var(--accent);
}

.custom-colors.enabled ~ .default-hint {
  display: none;
}

/* ===== Stats ===== */
.stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.stat-label {
  color: var(--text-muted);
}

.stat-val {
  font-weight: 600;
  color: var(--text);
}

/* ===== Legend ===== */
.legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.legend > div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  width: 16px;
  height: 16px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.06);
}

/* 同步新梯度公式 (L = max(15, 95 - count*10), S=80%) */
.swatch.intensity[data-i="1"]  { background: hsl(0, 80%, 85%); }
.swatch.intensity[data-i="3"]  { background: hsl(0, 80%, 65%); }
.swatch.intensity[data-i="6"]  { background: hsl(0, 80%, 35%); }
.swatch.intensity[data-i="10"] { background: hsl(0, 80%, 15%); }

/* ===== Grid container ===== */
.grid-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  position: relative;
  min-width: 0;
}

.grid-wrap {
  display: flex;
  align-items: flex-start;
}

/* ===== The 100x100 grid ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(100, var(--cell-size));
  grid-template-rows: repeat(100, var(--cell-size));
  width: var(--grid-size);
  height: var(--grid-size);
  background: #eceff1;
  border: 1px solid #b0bec5;
  position: relative;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: 0.5px solid rgba(0, 0, 0, 0.04);
  cursor: default;
  transition: background-color 0.1s;
}

/* ===== 10×10 块底色 (未命中格用棋盘式 2 种灰) ===== */
.cell[data-block="a"] { background: #f5f5f5; }
.cell[data-block="b"] { background: #d8d8d8; }

/* ===== 10×10 块粗分隔线 (每 10 行/列一道) ===== */
.cell[data-r$="0"] { border-top: 1.5px solid #9e9e9e; }
.cell[data-c$="0"] { border-left: 1.5px solid #9e9e9e; }

.cell.hit {
  /* 默认模式 count=1 的底色 (与新梯度公式一致) */
  background: hsl(0, 80%, 85%);
}

.cell:hover {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
  z-index: 2;
}

/* ===== Tooltip ===== */
.tooltip {
  position: fixed;
  background: rgba(33, 33, 33, 0.95);
  color: white;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-family: "SF Mono", Consolas, "Courier New", monospace;
  pointer-events: none;
  z-index: 1000;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}

.tooltip strong {
  color: #ffd54f;
}

.tooltip .morph-tags {
  margin-top: 4px;
  font-size: 11px;
  color: #b0bec5;
}

/* ===== Footer ===== */
.app-footer {
  padding: 8px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 11px;
  border-top: 1px solid var(--panel-border);
  background: var(--panel-bg);
}

/* ===== Responsive (basic) ===== */
@media (max-width: 1100px) {
  .app-main {
    flex-direction: column;
  }
  .control-panel {
    width: 100%;
    max-height: none;
  }
  :root {
    --grid-size: min(95vw, 700px);
  }
}
