* {
  box-sizing: border-box;
}

:root {
  --bg: #eef3ff;
  --bg-accent: #e3fff8;
  --card: #ffffff;
  --ink: #101828;
  --muted: #5f6d7e;
  --line: #d4dcec;
  --primary: #4f883d;
  --primary-soft: rgba(79, 136, 61, 0.18);
  --danger: #c92f43;
  --success: #178f5f;
  --radius-xl: 5px;
  --radius-lg: 5px;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.09);
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: 'Nunito', sans-serif;
  background: #fff;
}

h1,
h2,
h3,
.brand-title {
  font-family: 'Space Grotesk', sans-serif;
}

.app-shell {
  width: 100%;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 370px 1fr;
  gap: 0;
}

.mobile-header {
  display: none;
}

.settings-panel,
.card {
  background: var(--card);
  border: 1px solid rgba(212, 220, 236, 0.8);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.settings-panel {
  position: sticky;
  top: 16px;
  align-self: start;
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 18px;
}

.settings-panel::-webkit-scrollbar {
  width: 8px;
}

.settings-panel::-webkit-scrollbar-thumb {
  background: #c5d0e4;
  border-radius: 999px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 14px;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 5px;
  display: grid;
  place-items: center;
  font-size: 23px;
  color: #fff;
  background: linear-gradient(135deg, #1f7aef, #14b8a6);
}

.brand-title {
  font-size: 1.12rem;
  font-weight: 700;
}

.brand-sub {
  color: var(--muted);
  font-size: 0.92rem;
}

.panel-section {
  padding: 14px;
  border-radius: var(--radius-lg);
  border: 1px solid #e7edf8;
  background: linear-gradient(180deg, #fcfdff 0%, #f9fbff 100%);
  margin-bottom: 12px;
}

.panel-section h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 700;
}

.field-label {
  display: block;
  margin: 10px 0 6px;
  color: #344054;
  font-size: 0.92rem;
  font-weight: 700;
}

.field-input {
  width: 100%;
  border: 1px solid #c9d5ea;
  background: #fff;
  border-radius: 5px;
  padding: 10px 12px;
  font: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.color-input {
  padding: 6px;
  min-height: 44px;
}

.inline-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: end;
}

.slider-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}

.slider-value {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 700;
  min-width: 58px;
  text-align: right;
}

.check-row {
  margin-top: 9px;
  display: flex;
  gap: 9px;
  align-items: center;
  font-size: 0.92rem;
}

.check-row input {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
}

.toggle-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}

.toggle-btn {
  border: 1px solid #c9d5ea;
  background: #fff;
  border-radius: 5px;
  padding: 8px 6px;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  color: #5f6d7e;
}

.toggle-btn:hover {
  background: #f2f8ef;
  border-color: #b7d4ad;
}

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

.action-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.action-grid-pairs {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.btn {
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 10px 12px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

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

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 8px 20px rgba(79, 136, 61, 0.28);
}

.btn-primary:hover {
  background: #406f31;
}

.btn-ghost {
  background: #fff;
  border-color: #b7d4ad;
  color: #3f6f30;
}

.btn-ghost:hover {
  background: #f2f8ef;
}

.btn-danger {
  background: #eef6ea;
  border-color: #a8c69d;
  color: #3f6f30;
}

.btn-danger:hover {
  background: #e2efdb;
}

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

.card {
  padding: 16px;
}

.board-card {
  padding-left: 0;
  padding-right: 0;
}

.board-card .card-top,
.board-card .status-bar {
  margin-left: 16px;
  margin-right: 16px;
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.card-top h2 {
  margin: 0;
  font-size: 1.45rem;
}

.card-top p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
}

.chip {
  border-radius: 5px;
  background: #f4f8ff;
  border: 1px solid #d2e0fa;
  color: #19458a;
  padding: 7px 11px;
  font-size: 0.83rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-bar {
  margin-top: 12px;
  border-radius: 5px;
  padding: 10px 12px;
  font-weight: 700;
  background: #f8faff;
  border: 1px solid #d9e4f7;
  color: #153e77;
}

.status-bar.warning {
  background: #fff8ea;
  border-color: #f6d086;
  color: #7a4a00;
}

.status-bar.error {
  background: #fff0f3;
  border-color: #f4b6c0;
  color: #8b1326;
}

.status-bar.success {
  background: #effcf5;
  border-color: #afe6c8;
  color: #0f6944;
}

.board-scroll {
  margin-top: 14px;
  overflow: auto;
  border: 1px solid #dae4f4;
  border-radius: 5px;
  background: #fbfdff;
  padding: 10px;
}

.board-layout {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  gap: 4px;
  width: fit-content;
}

.axis-corner {
  width: 42px;
  height: 28px;
  border-radius: 5px;
  background: #f1f5fe;
  border: 1px solid #dde6f7;
}

.axis {
  color: #3f4b60;
  font-size: 0.78rem;
  font-weight: 800;
}

.axis-top {
  display: grid;
  grid-auto-flow: column;
  gap: 0;
  align-items: stretch;
}

.axis-top span,
.axis-left span {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f5fe;
  border: 1px solid #dde6f7;
}

.axis-top span {
  min-height: 28px;
}

.axis-left {
  display: grid;
  grid-auto-flow: row;
  gap: 0;
}

.axis-left span {
  min-width: 42px;
}

.board-canvas {
  position: relative;
  border: 1px solid #cfdaee;
  background: #fff;
  border-radius: 5px;
  overflow: hidden;
}

.board-background {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  display: none;
}

.grid {
  position: absolute;
  inset: 0;
  display: grid;
}

.cell {
  border-right: 1px solid rgba(146, 170, 201, 0.55);
  border-bottom: 1px solid rgba(146, 170, 201, 0.55);
  background: rgba(255, 255, 255, 0.8);
  cursor: crosshair;
  transition: background 0.12s ease;
}

.cell:hover {
  background: rgba(31, 122, 239, 0.11);
}

.cell.is-preview-valid {
  background: rgba(26, 169, 108, 0.24);
}

.cell.is-preview-invalid {
  background: rgba(217, 45, 32, 0.2);
}

.cell.is-error {
  animation: cellError 0.38s ease;
}

@keyframes cellError {
  0% { background: rgba(217, 45, 32, 0.45); }
  100% { background: rgba(255, 255, 255, 0.8); }
}

.node-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.node-point {
  position: absolute;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  margin-top: -7px;
  border-radius: 50%;
  pointer-events: auto;
  cursor: crosshair;
  z-index: 2;
  background: transparent;
  transition: background 0.12s ease, box-shadow 0.12s ease;
}

.node-point:hover {
  background: rgba(31, 122, 239, 0.25);
  box-shadow: 0 0 0 3px rgba(31, 122, 239, 0.12);
}

.node-point.is-preview-valid {
  background: rgba(26, 169, 108, 0.4);
  box-shadow: 0 0 0 3px rgba(26, 169, 108, 0.18);
}

.node-point.is-preview-invalid {
  background: rgba(217, 45, 32, 0.35);
  box-shadow: 0 0 0 3px rgba(217, 45, 32, 0.15);
}

.node-point.is-error {
  animation: nodeError 0.38s ease;
}

@keyframes nodeError {
  0% { background: rgba(217, 45, 32, 0.55); box-shadow: 0 0 0 4px rgba(217, 45, 32, 0.3); }
  100% { background: transparent; box-shadow: none; }
}

.overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.overlay .start-point-hit {
  pointer-events: auto;
  cursor: pointer;
}

.legend-card h3 {
  margin: 0;
  font-size: 1.1rem;
}

.legend-title-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.legend-tip {
  font-size: 0.83rem;
  color: var(--muted);
}

.legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 10px;
}

.legend-empty {
  padding: 14px;
  border: 1px dashed #c9d8ee;
  border-radius: 5px;
  color: var(--muted);
}

.legend-item {
  border: 1px solid #d8e3f6;
  border-radius: 5px;
  padding: 12px;
  background: #fff;
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.05);
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.legend-item:hover {
  border-color: #9abaf1;
}

.legend-item.active {
  border-color: #2b73dc;
  box-shadow: 0 0 0 2px rgba(43, 115, 220, 0.2);
}

.legend-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #a6b6d0;
}

.legend-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 800;
  font-size: 0.95rem;
}

.legend-start {
  color: #4b5563;
  font-size: 0.82rem;
  font-weight: 700;
}

.legend-moves {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.move-chip {
  border-radius: 5px;
  padding: 3px 8px;
  border: 1px solid #d4deef;
  background: #f8fbff;
  font-size: 0.83rem;
  font-weight: 700;
}

.move-empty {
  color: var(--muted);
  font-size: 0.84rem;
}

.export-stage {
  position: fixed;
  left: -20000px;
  top: 0;
  width: 900px;
  pointer-events: none;
}

.print-sheet {
  width: 794px;
  height: 1123px;
  min-height: 1123px;
  background: #fff;
  color: #111;
  padding: 42px 44px 44px;
  font-family: 'Nunito', sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.print-main {
  flex: 1 1 auto;
}

.print-continuation {
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 700;
  color: #475569;
}

.print-header h1 {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 31px;
  line-height: 1.15;
}

.print-header p {
  margin: 8px 0 0;
  font-size: 16px;
  color: #374151;
}

.print-meta {
  margin: 14px 0 18px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  color: #334155;
  border-top: 1px solid #d1d5db;
  padding-top: 10px;
}

.print-board {
  margin-bottom: 18px;
}

.print-board svg {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
}

.print-legend-title {
  margin: 0 0 8px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 20px;
}

.print-legend {
  display: grid;
  gap: 8px;
}

.print-legend-item {
  border: 1px solid #d1d5db;
  border-radius: 5px;
  padding: 9px 11px;
  break-inside: avoid;
  page-break-inside: avoid;
}

.print-legend-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 800;
  font-size: 14px;
  margin-bottom: 6px;
}

.print-legend-moves {
  font-size: 15px;
  line-height: 1.6;
  word-break: break-word;
}

.print-empty {
  border: 1px dashed #94a3b8;
  border-radius: 5px;
  padding: 12px;
  color: #475569;
  font-size: 14px;
  break-inside: avoid;
  page-break-inside: avoid;
}

.print-sheet-tight .print-legend-moves {
  font-size: 14px;
  line-height: 1.45;
}

.print-footer {
  margin-top: auto;
  padding-top: 14px;
  text-align: center;
  color: #64748b;
  font-size: 12px;
  border-top: 1px solid #d1d5db;
}

@media (max-width: 1150px) {
  .app-shell {
    grid-template-columns: 320px 1fr;
  }
}

@media (max-width: 799px) {
  .app-shell {
    display: block;
    padding: 0;
  }

  .mobile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    border: 1px solid rgba(212, 220, 236, 0.8);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
    padding: 12px 14px;
    margin-bottom: 10px;
  }

  .mobile-header h1 {
    margin: 0;
    font-size: 1.16rem;
  }

  .mobile-header p {
    margin: 2px 0 0;
    font-size: 0.84rem;
    color: var(--muted);
  }

  .settings-panel {
    display: none;
    position: static;
    max-height: none;
    margin-bottom: 10px;
  }

  .app-shell.panel-open .settings-panel {
    display: block;
  }

  .workspace {
    gap: 10px;
  }

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

  .card-top {
    flex-direction: column;
    align-items: flex-start;
  }
}
