:root {
      --bg: #f7f8fc;
      --panel: #ffffff;
      --line: #cfd5e3;
      --line-strong: #49566f;
      --text: #223049;
      --muted: #6b7891;
      --accent: #2d6cdf;
      --fixed: #1f2a44;
      --answer: #245bc8;
      --conflict: #ffe2e2;
      --same: #fff0c9;
      --related: #eef6ff;
      --button: #f1f4fa;
      --button-hover: #e5ebf7;
      --danger: #c13d3d;
    }

    * { box-sizing: border-box; }

    body {
      margin: 0;
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
      background: var(--bg);
      color: var(--text);
    }

    .wrap {
      max-width: 1260px;
      margin: 0 auto;
      padding: 12px;
    }

    h1 {
      margin: 0 0 4px;
      font-size: clamp(1.35rem, 1.9vw, 1.9rem);
    }

    p {
      margin: 0;
      line-height: 1.6;
    }

    .lead {
      color: var(--muted);
      margin-bottom: 10px;
      font-size: 0.9rem;
    }

    .layout {
      display: grid;
      grid-template-columns: minmax(0, 1fr) 320px;
      gap: 12px;
      align-items: start;
    }

    .ad-box {
      margin: 14px 0;
    }

    .panel {
      background: var(--panel);
      border: 1px solid #e3e8f2;
      border-radius: 16px;
      box-shadow: 0 8px 22px rgba(38, 53, 87, 0.05);
      padding: 12px;
    }

    .topbar {
      display: flex;
      justify-content: space-between;
      gap: 8px;
      align-items: flex-start;
      flex-wrap: wrap;
      margin-bottom: 8px;
    }

    .status-row {
      display: flex;
      gap: 6px;
      flex-wrap: wrap;
    }

    .badge {
      background: #eef2f8;
      color: var(--text);
      border-radius: 999px;
      padding: 5px 9px;
      font-size: 0.8rem;
    }

    .badge.error {
      background: #ffe6e6;
      color: #a42f2f;
    }

    .digit-summary-wrap {
      width: min(100%, 560px);
      margin: 10px auto 10px;
    }

    .digit-summary-title {
      font-size: 0.78rem;
      color: var(--muted);
      margin-bottom: 5px;
      line-height: 1.2;
    }

    .digit-summary {
      display: grid;
      grid-template-columns: repeat(9, 1fr);
      gap: 0;
      width: 100%;
    }

    .digit-chip {
      border: 1px solid #d7deeb;
      border-right: none;
      background: #fff;
      color: #50607c;
      border-radius: 0;
      min-height: 0;
      height: 56px;
      padding: 0 1px;
      text-align: center;
      cursor: pointer;
      font: inherit;
      transition: 0.15s ease;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }

    .digit-chip:hover { background: #f7faff; }

    .digit-chip:first-child {
      border-top-left-radius: 8px;
      border-bottom-left-radius: 8px;
    }

    .digit-chip:last-child {
      border-right: 1px solid #d7deeb;
      border-top-right-radius: 8px;
      border-bottom-right-radius: 8px;
    }

    .digit-chip.active {
      border: 2px solid #e0a400;
      background: #fff4cc;
      color: #8a6300;
      font-weight: 700;
      position: relative;
      z-index: 1;
    }

    .digit-chip.done {
      border: 2px solid #2d6cdf;
      background: #2d6cdf;
      color: #fff;
      font-weight: 700;
      position: relative;
      z-index: 1;
    }

    .digit-chip .n {
      font-size: 1rem;
      line-height: 1;
      margin-bottom: 3px;
    }

    .digit-chip .c {
      font-size: 0.58rem;
      line-height: 1;
    }

    .mode-switch {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 6px;
      margin-bottom: 8px;
    }

    .mode-btn,
    .action-btn,
    .num-btn {
      border: none;
      border-radius: 10px;
      background: var(--button);
      color: var(--text);
      padding: 9px 10px;
      font-size: 0.9rem;
      cursor: pointer;
      transition: 0.18s ease;
      font-family: inherit;
    }

    .mode-btn:hover,
    .action-btn:hover,
    .num-btn:hover {
      background: var(--button-hover);
    }

    .mode-btn.active {
      background: var(--accent);
      color: #fff;
      font-weight: 700;
    }

    .board-wrap {
      width: min(100%, 560px);
      margin: 0 auto;
    }

    .board {
      display: grid;
      grid-template-columns: repeat(9, 1fr);
      grid-template-rows: repeat(9, 1fr);
      aspect-ratio: 1 / 1;
      border: 3px solid var(--line-strong);
      background: #fff;
      user-select: none;
    }

    .cell {
      position: relative;
      border: 1px solid var(--line);
      display: flex;
      align-items: center;
      justify-content: center;
      min-width: 0;
      cursor: pointer;
      background: #fff;
    }

    .cell.right-strong { border-right: 3px solid var(--line-strong); }
    .cell.bottom-strong { border-bottom: 3px solid var(--line-strong); }
    .cell.related { background: var(--related); }
    .cell.same { background: var(--same); }
    .cell.conflict { background: var(--conflict); }
    .cell.selected {
      outline: 3px solid var(--accent);
      outline-offset: -3px;
      z-index: 2;
    }

    .value {
      font-size: clamp(1.1rem, 2.1vw, 1.7rem);
      font-weight: 700;
      line-height: 1;
    }

    .value.fixed { color: var(--fixed); }
    .value.answer { color: var(--answer); }

    .notes {
      width: 100%;
      height: 100%;
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      grid-template-rows: repeat(3, 1fr);
      padding: 2px;
      font-size: clamp(0.46rem, 0.95vw, 0.68rem);
      color: #55637e;
    }

    .notes span {
      display: flex;
      align-items: center;
      justify-content: center;
      opacity: 0;
    }

    .notes span.on { opacity: 1; font-weight: 600; }
    .notes span.hint { opacity: 0.4; color: #5f8fe8; }

    .number-pad {
      display: grid;
      grid-template-columns: repeat(5, 1fr);
      gap: 6px;
      margin-top: 10px;
    }

    .num-btn { font-size: 1rem; min-height: 42px; }

    .history-actions {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 6px;
      margin-top: 8px;
    }

    .actions {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 6px;
      margin-top: 8px;
    }

    .action-btn:disabled {
      cursor: not-allowed;
      opacity: 0.45;
    }

    .action-btn.danger {
      background: #ffe8e8;
      color: var(--danger);
    }

    .message {
      margin-top: 8px;
      background: #eef6ff;
      color: #21457d;
      border-radius: 10px;
      padding: 10px 12px;
      font-size: 0.88rem;
    }

    .footer-note {
      margin-top: 10px;
      color: var(--muted);
      font-size: 0.8rem;
    }

    .side-section + .side-section { margin-top: 10px; }

    .side-section h2 {
      font-size: 0.98rem;
      margin: 0 0 6px;
    }

    .helper-box {
      background: #f5f7fb;
      border-radius: 10px;
      padding: 9px 10px;
      color: var(--muted);
      font-size: 0.84rem;
      line-height: 1.55;
    }

    textarea {
      width: 100%;
      min-height: 72px;
      resize: vertical;
      border: 1px solid #d5dbea;
      border-radius: 10px;
      padding: 10px;
      font: inherit;
      font-size: 0.9rem;
      margin-top: 8px;
    }

    .side-actions {
      display: grid;
      gap: 6px;
      margin-top: 8px;
    }

    .small {
      color: var(--muted);
      font-size: 0.78rem;
      margin-top: 4px;
    }

    @media (max-width: 980px) {
      .layout {
        grid-template-columns: 1fr;
      }
      .board-wrap {
        width: min(100%, 620px);
      }
    }

    @media (max-width: 640px) {
      .wrap { padding: 10px; }
      .layout { gap: 10px; }
      .panel { padding: 10px; }
      .mode-switch { grid-template-columns: 1fr; }
      .digit-summary { gap: 0; }
      .digit-chip { height: 46px; }
    }
