:root {
  --ink: #17324d;
  --ink-2: #28475f;
  --muted: #71808d;
  --paper: #f3f0e8;
  --paper-2: #fbfaf5;
  --panel: #ffffff;
  --line: #d9dedc;
  --line-strong: #bdc7c6;
  --accent: #e8a52d;
  --accent-dark: #a96700;
  --series: #0072b2;
  --series-soft: #e5f3fb;
  --parallel: #c84f12;
  --parallel-soft: #fff0e8;
  --y-delta: #007b64;
  --y-delta-soft: #e5f6f1;
  --delta-y: #8a3f86;
  --delta-y-soft: #f7eaf6;
  --shadow: 0 16px 44px rgba(23, 50, 77, 0.11);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 1024px;
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 0%, rgba(232, 165, 45, 0.10), transparent 28rem),
    linear-gradient(180deg, #f8f5ee 0, var(--paper) 18rem);
  font-family: Inter, "Noto Sans JP", "Yu Gothic UI", "Yu Gothic", Meiryo, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid #111;
  outline-offset: 3px;
  box-shadow: 0 0 0 6px #fff;
}

.app-header {
  width: min(1560px, calc(100% - 44px));
  min-height: 86px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 26px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-block h1 {
  margin: 1px 0 0;
  font-size: 25px;
  letter-spacing: 0.08em;
  line-height: 1;
}

.brand-mark {
  position: relative;
  width: 38px;
  height: 50px;
}

.brand-mark::before {
  content: "";
  position: absolute;
  left: 18px;
  top: 7px;
  bottom: 7px;
  width: 3px;
  border-radius: 4px;
  background: var(--ink);
}

.brand-mark span,
.brand-mark i {
  position: absolute;
  left: 12px;
  width: 15px;
  height: 15px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--paper-2);
  z-index: 1;
}

.brand-mark span:first-child { top: 0; }
.brand-mark span:last-child { bottom: 0; }
.brand-mark i {
  top: 18px;
  left: 16px;
  width: 7px;
  height: 14px;
  border: 0;
  border-radius: 4px;
  background: var(--accent);
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.18em;
  line-height: 1.4;
}

.header-copy {
  margin: 0;
  color: #61707c;
  font-size: 13px;
}

.quiet-button,
.tool-buttons button {
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.76);
  font-weight: 700;
  cursor: pointer;
  transition: 150ms ease;
}

.quiet-button:hover,
.tool-buttons button:hover:not(:disabled) {
  border-color: var(--ink);
  background: #fff;
  transform: translateY(-1px);
}

.help-button {
  min-width: 98px;
  padding: 9px 13px;
}

.help-button span {
  display: inline-grid;
  width: 20px;
  height: 20px;
  margin-right: 5px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--ink);
  font-size: 12px;
}

main {
  width: min(1560px, calc(100% - 44px));
  margin: 0 auto 26px;
}

.generator-bar {
  min-height: 92px;
  padding: 13px 15px 13px 21px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 20px;
  border: 1px solid rgba(189, 199, 198, 0.72);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.80);
  box-shadow: 0 8px 30px rgba(23, 50, 77, 0.07);
  backdrop-filter: blur(12px);
}

.choice-group {
  min-width: 316px;
  margin: 0;
  padding: 0;
  border: 0;
}

.choice-group legend {
  float: left;
  width: 74px;
  margin: 0 12px 0 0;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 800;
  line-height: 49px;
}

.density-group {
  min-width: 272px;
}

.challenge-group {
  min-width: 356px;
  flex: 1;
}

.segmented-control {
  display: inline-flex;
  gap: 5px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #f2f4f2;
}

.segmented-control button {
  min-width: 70px;
  height: 42px;
  padding: 4px 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  transition: 150ms ease;
}

.density-group .segmented-control button {
  min-width: 58px;
}

.challenge-group .segmented-control button {
  min-width: 78px;
}

.segmented-control button b {
  font-size: 13px;
}

.segmented-control button small {
  color: var(--muted);
  font-size: 9px;
  white-space: nowrap;
}

.segmented-control button:hover {
  background: rgba(255, 255, 255, 0.72);
}

.segmented-control button[aria-pressed="true"] {
  border-color: rgba(23, 50, 77, 0.16);
  background: #fff;
  box-shadow: 0 3px 10px rgba(23, 50, 77, 0.12);
}

.segmented-control button[aria-pressed="true"] b::before {
  content: "✓";
  margin-right: 4px;
  color: var(--accent-dark);
}

.bar-divider {
  width: 1px;
  height: 52px;
  background: var(--line);
}

.generate-button {
  min-width: 172px;
  min-height: 54px;
  padding: 0 20px;
  border: 1px solid #c47c09;
  border-radius: 13px;
  color: #1e2e3b;
  background: linear-gradient(180deg, #f9c45e, #e9a52d);
  box-shadow: 0 8px 18px rgba(180, 111, 0, 0.22), inset 0 1px rgba(255, 255, 255, 0.7);
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: 150ms ease;
}

.generate-button:hover {
  filter: brightness(1.035);
  transform: translateY(-2px);
  box-shadow: 0 11px 22px rgba(180, 111, 0, 0.26), inset 0 1px rgba(255, 255, 255, 0.7);
}

.generate-button:active {
  transform: translateY(0);
}

.button-spark {
  margin-right: 7px;
  font-size: 17px;
}

.game-layout {
  margin-top: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 304px;
  gap: 14px;
  align-items: stretch;
}

.board-card,
.side-panel {
  border: 1px solid rgba(189, 199, 198, 0.84);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.board-card {
  min-width: 0;
}

.board-toolbar {
  min-height: 58px;
  padding: 9px 13px 9px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.circuit-caption {
  min-width: 0;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
}

.circuit-caption strong {
  white-space: nowrap;
}

.circuit-caption > span:last-child {
  min-width: 0;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  align-self: center;
  border-radius: 50%;
  background: #aeb8bc;
  box-shadow: 0 0 0 4px #eef0ef;
}

.status-dot.active {
  background: #2b9a73;
  box-shadow: 0 0 0 4px #e0f3ea;
}

.status-dot.complete {
  background: var(--accent-dark);
  box-shadow: 0 0 0 4px #fff1cc;
}

.tool-buttons {
  display: flex;
  gap: 5px;
}

.tool-buttons button {
  min-height: 34px;
  padding: 0 10px;
  color: var(--ink-2);
  font-size: 11px;
}

.tool-buttons button span {
  margin-right: 3px;
  font-size: 15px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.canvas-host {
  position: relative;
  height: clamp(520px, calc(100vh - 258px), 760px);
  min-height: 520px;
  overflow: hidden;
  background: var(--paper-2);
  touch-action: none;
  user-select: none;
}

.canvas-host:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -4px;
  box-shadow: inset 0 0 0 1px #fff;
}

.canvas-host canvas {
  position: absolute;
  inset: 0;
  display: block;
}

.canvas-corner-note {
  position: absolute;
  z-index: 4;
  right: 12px;
  bottom: 11px;
  padding: 6px 9px;
  border: 1px solid rgba(189, 199, 198, 0.8);
  border-radius: 8px;
  color: #71808d;
  background: rgba(255, 255, 255, 0.86);
  font-size: 9px;
  pointer-events: none;
  backdrop-filter: blur(4px);
}

.canvas-corner-note span {
  color: var(--ink-2);
  font-weight: 800;
}

.canvas-corner-note i {
  margin: 0 3px;
  font-style: normal;
}

.success-panel {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 50%;
  width: min(450px, calc(100% - 60px));
  padding: 28px 30px 26px;
  transform: translate(-50%, -50%);
  border: 1px solid #d7b25b;
  border-radius: 21px;
  background: rgba(255, 253, 246, 0.97);
  box-shadow: 0 24px 70px rgba(23, 50, 77, 0.24);
  text-align: center;
  backdrop-filter: blur(12px);
}

.success-panel[hidden] {
  display: none;
}

.success-symbol {
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: #24805f;
  box-shadow: 0 0 0 8px #e4f3eb;
  font-size: 29px;
  font-weight: 900;
}

.success-panel h2 {
  margin: 7px 0 8px;
  font-size: 25px;
}

.success-panel > p:not(.eyebrow) {
  margin: 0;
  color: #60707b;
  font-size: 13px;
}

.success-actions {
  margin-top: 20px;
  display: flex;
  justify-content: center;
  gap: 8px;
}

.generate-button.compact {
  min-width: 132px;
  min-height: 42px;
}

.success-actions .quiet-button {
  padding: 0 15px;
}

.board-footer {
  min-height: 42px;
  padding: 7px 14px 7px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-top: 1px solid var(--line);
  background: #fff;
  font-size: 10px;
}

.board-footer p {
  margin: 0;
  color: #596a77;
}

.keyboard-hints {
  color: var(--muted);
  white-space: nowrap;
}

kbd {
  min-width: 20px;
  padding: 1px 5px;
  display: inline-block;
  border: 1px solid #c5cdcc;
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--ink-2);
  background: #fff;
  box-shadow: inset 0 -1px #e8eae9;
  font: 700 9px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
  text-align: center;
}

.side-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  box-shadow: 0 14px 36px rgba(23, 50, 77, 0.09);
}

.panel-section {
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-section:last-child {
  border-bottom: 0;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.section-heading h2 {
  margin: 1px 0 0;
  font-size: 15px;
  letter-spacing: 0.02em;
}

.compact-heading {
  align-items: center;
}

.verified-badge {
  padding: 4px 6px;
  border: 1px solid #acd3c3;
  border-radius: 999px;
  color: #126248;
  background: #ebf7f2;
  font-size: 8px;
  font-weight: 800;
  white-space: nowrap;
}

.stats-grid {
  margin: 12px 0 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.stats-grid div {
  padding: 7px 4px 6px;
  border: 1px solid #e4e7e5;
  border-radius: 9px;
  background: #f8f9f7;
  text-align: center;
}

.stats-grid dt {
  color: var(--muted);
  font-size: 8px;
  font-weight: 700;
}

.stats-grid dd {
  margin: 1px 0 0;
  font: 800 18px/1.05 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.puzzle-meta {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 9px;
}

.puzzle-meta > span {
  padding: 3px 7px;
  border-radius: 999px;
  background: #eef1ef;
  font-weight: 700;
}

.puzzle-meta button {
  padding: 2px 5px;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.puzzle-meta button:hover {
  color: var(--ink);
  background: #f0f2f1;
}

.puzzle-meta code {
  font-size: 9px;
}

.heading-note {
  color: var(--muted);
  font-size: 8px;
}

.operation-list {
  margin-top: 10px;
  display: grid;
  gap: 6px;
}

.operation-card {
  position: relative;
  width: 100%;
  min-height: 48px;
  padding: 5px 8px 5px 5px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 27px;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 10px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  transition: 140ms ease;
}

.operation-card:not(:disabled):hover,
.operation-card.active {
  transform: translateX(2px);
  box-shadow: 0 4px 12px rgba(23, 50, 77, 0.09);
}

.operation-card.op-series { border-left-color: var(--series); }
.operation-card.op-parallel { border-left-color: var(--parallel); }
.operation-card.op-y-delta { border-left-color: var(--y-delta); }
.operation-card.op-delta-y { border-left-color: var(--delta-y); }
.operation-card.op-series.active { background: var(--series-soft); border-color: var(--series); }
.operation-card.op-parallel.active { background: var(--parallel-soft); border-color: var(--parallel); }
.operation-card.op-y-delta.active { background: var(--y-delta-soft); border-color: var(--y-delta); }
.operation-card.op-delta-y.active { background: var(--delta-y-soft); border-color: var(--delta-y); }

.op-number {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font: 800 11px/1 ui-monospace, monospace;
}

.op-series .op-number { background: var(--series); }
.op-parallel .op-number { background: var(--parallel); }
.op-y-delta .op-number { background: var(--y-delta); }
.op-delta-y .op-number { background: var(--delta-y); }

.op-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.op-copy b {
  font-size: 11px;
  line-height: 1.2;
}

.op-count {
  min-width: 23px;
  padding: 3px 4px;
  border-radius: 999px;
  color: #64727c;
  background: #edf0ef;
  font: 800 10px/1.3 ui-monospace, monospace;
  text-align: center;
}

.history-section {
  min-height: 126px;
  flex: 1;
  overflow: hidden;
}

.history-list {
  max-height: 126px;
  margin: 9px 0 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  scrollbar-width: thin;
}

.history-list li {
  min-height: 25px;
  padding: 5px 4px;
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 5px;
  border-bottom: 1px dashed #e2e5e3;
  color: #536571;
  font-size: 8px;
}

.history-list li:last-child {
  border-bottom: 0;
}

.history-list .history-index {
  color: #9aa4aa;
  font-family: ui-monospace, monospace;
}

.history-list .history-name {
  color: var(--ink-2);
  font-weight: 800;
}

.history-list .history-change {
  color: #7f8c94;
  font-family: ui-monospace, monospace;
}

.history-list .empty-history {
  display: block;
  padding: 15px 4px;
  border: 0;
  color: #9aa4aa;
  text-align: center;
}

.help-dialog {
  width: min(720px, calc(100vw - 80px));
  max-height: calc(100vh - 60px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  color: var(--ink);
  background: #fffefa;
  box-shadow: 0 30px 100px rgba(14, 32, 49, 0.30);
}

.help-dialog::backdrop {
  background: rgba(17, 35, 50, 0.54);
  backdrop-filter: blur(5px);
}

.help-dialog form {
  padding: 25px 28px 28px;
}

.help-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.help-topline h2 {
  margin: 2px 0 0;
  font-size: 24px;
}

.dialog-close {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  font-size: 21px;
  cursor: pointer;
}

.help-lead {
  margin: 16px 0 18px;
  color: #566975;
  font-size: 12px;
  line-height: 1.85;
}

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

.help-rules article {
  padding: 13px;
  display: grid;
  grid-template-columns: 31px 1fr;
  gap: 10px;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 12px;
}

.help-rules article > span {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font: 800 12px/1 ui-monospace, monospace;
}

.help-rules h3 {
  margin: 0;
  font-size: 13px;
}

.help-rules p {
  margin: 4px 0 0;
  color: #60727d;
  font-size: 10px;
  line-height: 1.65;
}

.help-rules code {
  padding: 1px 3px;
  border-radius: 4px;
  color: #314c5f;
  background: #eef1ef;
}

.rule-series { border-left-color: var(--series) !important; }
.rule-parallel { border-left-color: var(--parallel) !important; }
.rule-y-delta { border-left-color: var(--y-delta) !important; }
.rule-delta-y { border-left-color: var(--delta-y) !important; }
.rule-series > span { background: var(--series); }
.rule-parallel > span { background: var(--parallel); }
.rule-y-delta > span { background: var(--y-delta); }
.rule-delta-y > span { background: var(--delta-y); }

.help-notes {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #f1f3f0;
}

.help-notes p {
  margin: 0 0 7px;
  color: #536671;
  font-size: 10px;
  line-height: 1.65;
}

.help-notes p:last-child {
  margin-bottom: 0;
}

.help-close {
  min-height: 44px;
  margin: 17px auto 0;
  display: block;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 24px;
  min-width: 230px;
  max-width: 520px;
  padding: 10px 16px;
  transform: translate(-50%, 18px);
  border-radius: 10px;
  color: #fff;
  background: rgba(23, 50, 77, 0.94);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.20);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: 180ms ease;
}

.toast.visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

@media (max-width: 1250px) {
  .app-header,
  main {
    width: calc(100% - 26px);
  }

  .header-copy {
    display: none;
  }

  .generator-bar {
    gap: 12px;
  }

  .choice-group {
    min-width: 292px;
  }

  .density-group {
    min-width: 270px;
  }

  .challenge-group {
    min-width: 330px;
  }

  .choice-group legend {
    width: 64px;
    margin-right: 7px;
  }

  .density-group .segmented-control button {
    min-width: 56px;
    padding-inline: 9px;
  }

  .challenge-group .segmented-control button {
    min-width: 72px;
    padding-inline: 9px;
  }

  .generate-button {
    min-width: 156px;
    padding-inline: 14px;
  }

  .game-layout {
    grid-template-columns: minmax(0, 1fr) 282px;
  }

  .tool-buttons button {
    padding-inline: 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}
