:root {
  --bg: #0d1117;
  --panel: #161b22;
  --border: #e8e8e8;
  --ink: #f0f0f0;
  --muted: #9aa4b2;
  --red: #ff3b3b;
  --green: #3dff6a;
  --cell: #0a0a0a;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --font: "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Mono", "Consolas", "Courier New", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse 80% 50% at 20% 0%, #1a2332 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 90% 100%, #1a1520 0%, transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2.5rem;
}

.header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

.how-to {
  margin: 0.85rem 0 0;
  padding: 0.75rem 0.75rem 0.75rem 1.5rem;
  background: var(--panel);
  border: 1px solid #30363d;
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.45;
}

.how-to li + li {
  margin-top: 0.35rem;
}

.how-to strong {
  color: var(--ink);
  font-weight: 600;
}

.how-to .path-hint {
  color: #ffe600;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
  margin: 1.25rem 0;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid #30363d;
  border-radius: 10px;
}

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

.control-group label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.control-group input {
  width: 5rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid #30363d;
  border-radius: 6px;
  background: #0d1117;
  color: var(--ink);
  font-size: 1rem;
}

.mode-group,
.action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.btn {
  padding: 0.5rem 0.85rem;
  border: 1px solid #30363d;
  border-radius: 6px;
  background: #21262d;
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.btn:hover {
  background: #30363d;
}

.btn:active {
  transform: scale(0.98);
}

.btn.mode.active {
  border-color: var(--accent);
  background: #1f3a5f;
  color: #93c5fd;
}

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

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

.btn-ghost {
  background: transparent;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(200px, 260px) 1fr;
  gap: 1.25rem;
  align-items: start;
}

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

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

.tchart {
  background: #0a0a0a;
  border: 2px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  min-height: 220px;
}

.tchart-head {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 2px solid var(--border);
  font-family: var(--mono);
  font-weight: 700;
  color: var(--red);
  text-align: center;
  padding: 0.55rem 0.4rem;
  font-size: 1rem;
}

.tchart-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 180px;
}

.tchart-col {
  padding: 0.6rem 0.5rem;
  font-family: var(--mono);
  font-size: 1.05rem;
  color: var(--red);
  line-height: 1.55;
  text-align: center;
}

.tchart-col:first-child {
  border-right: 2px solid var(--border);
}

.tchart-col .crossed {
  text-decoration: line-through;
  opacity: 0.55;
}

.status {
  margin: 0;
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.4;
}

.status.ok {
  color: var(--green);
}

.status.err {
  color: var(--danger);
}

.legend {
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.swatch {
  display: inline-block;
  min-width: 1.4rem;
  font-family: var(--mono);
  font-weight: 700;
  text-align: center;
}

.swatch.f { color: var(--green); }
.swatch.id,
.swatch.g,
.swatch.h,
.swatch.arrow { color: var(--red); }

.grid-wrap {
  overflow: auto;
  padding: 0.25rem;
}

.grid {
  display: grid;
  gap: 0;
  width: max-content;
  border: 3px solid var(--border);
  background: var(--border);
}

.cell {
  position: relative;
  width: var(--cell-size, 88px);
  height: var(--cell-size, 88px);
  background: var(--cell);
  border: 2px solid var(--border);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

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

.cell.blocked {
  background:
    repeating-linear-gradient(
      -45deg,
      transparent,
      transparent 6px,
      var(--red) 6px,
      var(--red) 8px
    ),
    var(--cell);
}

.cell .mark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell-size, 88px) * 0.36);
  font-weight: 800;
  color: var(--red);
  font-family: var(--mono);
  pointer-events: none;
  z-index: 0;
  opacity: 0.92;
}

.cell.has-data .mark {
  font-size: calc(var(--cell-size, 88px) * 0.28);
  opacity: 0.75;
}

.cell .f,
.cell .id,
.cell .g,
.cell .h {
  position: absolute;
  font-family: var(--mono);
  font-weight: 700;
  font-size: calc(var(--cell-size, 88px) * 0.18);
  line-height: 1;
  pointer-events: none;
  z-index: 2;
}

.cell .f {
  top: 4px;
  left: 5px;
  color: var(--green);
}

.cell .id {
  top: 4px;
  right: 5px;
  color: var(--red);
}

.cell .g {
  bottom: 4px;
  left: 5px;
  color: var(--red);
}

.cell .h {
  bottom: 4px;
  right: 5px;
  color: var(--red);
}

.cell .arrow {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell-size, 88px) * 0.28);
  color: var(--red);
  pointer-events: none;
  z-index: 1;
  line-height: 1;
}

.cell.path {
  box-shadow: inset 0 0 0 3px #ffe600;
}

.cell.in-closed {
  background-color: #1a0f0f;
}

.cell.in-open:not(.blocked) {
  background-color: #0f1a14;
}
