:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #526073;
  --faint: #8b95a7;
  --line: #e3e7ee;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --accent-hover: #245ed0;
  --empty: #eef1f4;
  --grid: #d5dbe3;
  --hover-line: #c5d0de;
  --soft: #eef3ff;
  --soft-line: #c5d4f7;
  --soft-strong: #e8eefc;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --row-line: #f0f2f5;
  --danger: #c73e3a;
  --warn: #fff6f4;
  --minus: #c5ccd6;
  --scrollbar: #8b98ab;
  --scrollbar-track: #e3e8ef;
  --shadow: rgba(28, 36, 48, 0.16);
  --dialog-shadow: rgba(28, 36, 48, 0.22);
  --backdrop: rgba(28, 36, 48, 0.38);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #10151c;
  --card: #1b2430;
  --ink: #e7edf5;
  --muted: #a9b4c5;
  --faint: #7e8c9f;
  --line: #313c4c;
  --accent: #7aa6ff;
  --accent-ink: #0d1420;
  --accent-hover: #98baff;
  --empty: #141b25;
  --grid: #3d4a5c;
  --hover-line: #516178;
  --soft: #1c2b46;
  --soft-line: #3d5c96;
  --soft-strong: #243656;
  --surface: #1b2430;
  --surface-2: #151c26;
  --row-line: #2a3442;
  --danger: #ff9b96;
  --warn: #3a2624;
  --minus: #6e7d90;
  --scrollbar: #7d8da3;
  --scrollbar-track: #2a3442;
  --shadow: rgba(0, 0, 0, 0.4);
  --dialog-shadow: rgba(0, 0, 0, 0.5);
  --backdrop: rgba(0, 0, 0, 0.66);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--hover-line);
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 20px 36px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1 1 240px;
  min-width: min(100%, 220px);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  margin-left: auto;
}

.theme-btn,
.account-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
  border-radius: 999px;
  padding: 8px 14px 8px 10px;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line);
}

.theme-btn svg,
.account-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-btn .sun {
  display: none;
}

html[data-theme="dark"] .theme-btn .moon {
  display: none;
}

html[data-theme="dark"] .theme-btn .sun {
  display: block;
}

.theme-btn[aria-pressed="true"] {
  color: var(--accent);
  background: var(--soft);
  box-shadow: 0 0 0 1px var(--soft-line);
}

.account-btn span,
.theme-btn span {
  max-width: 8em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-btn.signed {
  color: var(--accent);
  background: var(--soft);
  box-shadow: 0 0 0 1px var(--soft-line);
}

.logo {
  width: 56px;
  height: 56px;
  flex: none;
  border-radius: 16px;
  box-shadow: 0 8px 18px var(--shadow);
}

.header h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0.02em;
}

.theme-mark {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.lede,
.hint,
.summary {
  margin: 6px 0 0;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 440px);
  gap: 22px;
  align-items: stretch;
  height: calc(100vh - 188px);
  min-height: 560px;
  margin-top: 18px;
}

.palette-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.palette-scroll {
  height: 100%;
  max-height: 100%;
  overflow-y: scroll;
  scrollbar-width: none;
  padding: 2px 18px 12px 2px;
}

.palette-scroll::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.palette-bar {
  position: absolute;
  top: 2px;
  right: 2px;
  bottom: 12px;
  width: 10px;
  border-radius: 999px;
  background: var(--scrollbar-track);
}

.palette-bar[hidden] {
  display: none;
}

.palette-thumb {
  width: 100%;
  border-radius: 999px;
  background: var(--scrollbar);
  cursor: grab;
  touch-action: none;
}

.palette-scroll.busy {
  pointer-events: none;
  opacity: 0.72;
}

.group {
  margin: 0 0 18px;
}

.group h2 {
  margin: 0 0 10px;
  font-size: 15px;
}

.group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}

.card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 0 0 1px var(--line);
  display: flex;
  flex-direction: column;
  min-height: 168px;
}

.card.selected {
  box-shadow: 0 0 0 3px var(--piece);
}

.add {
  flex: 1;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px 12px 0;
  cursor: pointer;
  border-radius: 12px 12px 0 0;
}

.preview {
  height: 84px;
  display: grid;
  place-items: center;
}

.mini {
  display: grid;
  gap: 2px;
}

.mini i {
  width: 22px;
  height: 22px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-style: normal;
  font-size: 11px;
  font-weight: 700;
}

.card-title {
  margin-top: 6px;
  font-size: 14px;
}

.count {
  margin-top: 2px;
  color: var(--faint);
  font-size: 13px;
}

.count.on {
  color: var(--accent);
  font-weight: 600;
}

.card-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-height: 48px;
  padding: 6px 12px 12px;
}

.req {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.req[hidden] {
  display: none;
}

.req.on {
  color: var(--accent);
  font-weight: 600;
}

.req input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.minus {
  width: 36px;
  height: 28px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  color: var(--minus);
  background: var(--empty);
}

.minus:not(:disabled) {
  color: var(--accent);
  background: var(--soft-strong);
  border-color: var(--soft-line);
}

.result-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.result-pane h2 {
  margin: 0;
  font-size: 18px;
  flex: none;
}

.summary {
  margin: 4px 0 10px;
  flex: none;
}

.board-fit {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 180px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  container-type: size;
}

.board {
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(6, minmax(0, 1fr));
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: clamp(14px, 2.4vw, 20px);
  user-select: none;
  border: 0 solid transparent;
}

.cell.empty {
  background: var(--empty);
  box-shadow: inset 0 0 0 1px var(--grid);
}

.status {
  white-space: pre-line;
  min-height: 2.8em;
  margin: 12px 0 0;
  flex: none;
}

.actions,
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.actions {
  margin-top: 4px;
  flex: none;
}

.archive-entry .actions {
  display: grid;
  grid-template-columns: 1fr;
}

[hidden] {
  display: none !important;
}

dialog:not([open]) {
  display: none;
}

dialog {
  border: 0;
  border-radius: 14px;
  padding: 18px 18px 16px;
  width: min(440px, calc(100vw - 32px));
  color: var(--ink);
  background: var(--card);
  box-shadow: 0 18px 60px var(--dialog-shadow);
}

dialog::backdrop {
  background: var(--backdrop);
}

dialog h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

#terms-dialog {
  width: min(640px, calc(100vw - 32px));
}

.terms-body {
  max-height: min(58vh, 460px);
  margin-top: 8px;
  padding-right: 6px;
  overflow: auto;
}

.terms-body h4 {
  margin: 14px 0 4px;
  font-size: 15px;
}

.terms-body p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.site-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-top: 22px;
  color: var(--faint);
  font-size: 13px;
}

.text-link {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

#save-name,
.feedback-input {
  width: 100%;
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.feedback-input {
  min-height: 140px;
  resize: vertical;
}

#feedback-list-dialog {
  width: min(640px, calc(100vw - 32px));
}

.feedback-list {
  max-height: min(420px, 56vh);
  margin-top: 12px;
  overflow: auto;
}

.feedback-item {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.feedback-item p {
  margin: 6px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
}

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

.error {
  min-height: 1.2em;
  margin: 8px 0 0;
  color: var(--danger);
}

.archive-entry {
  flex: none;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.archive-entry h3 {
  margin: 0;
  font-size: 15px;
}

#archive-dialog,
#export-dialog {
  width: min(560px, calc(100vw - 32px));
}

.archive-list {
  max-height: min(360px, 48vh);
  margin-top: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.archive-head,
.archive-row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) 0.9fr 0.7fr;
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 8px 12px;
  text-align: left;
}

.archive-list.picks .archive-head,
.archive-list.picks .archive-row {
  grid-template-columns: 28px minmax(0, 1.6fr) 0.9fr 0.7fr;
}

.archive-pick {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.archive-head {
  position: sticky;
  top: 0;
  color: var(--faint);
  font-size: 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

.archive-row {
  border: 0;
  border-bottom: 1px solid var(--row-line);
  border-radius: 0;
  background: var(--surface);
  cursor: pointer;
}

.archive-row.selected {
  background: var(--soft-strong);
}

.archive-row.current .name {
  color: var(--accent);
  font-weight: 650;
}

.archive-row .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.confirm {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--warn);
}

.confirm[hidden] {
  display: none;
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 14px;
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-head h3 {
  margin: 0;
}

.icon-close {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-top: 14px;
  padding: 4px;
  border-radius: 10px;
  background: var(--empty);
}

.seg-btn {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.seg-btn.on {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px var(--shadow);
}

.field {
  display: block;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.field input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
}

.field-note {
  margin: 10px 0 0;
  color: var(--faint);
  font-size: 12px;
}

.account-card {
  margin: 16px 0 0;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--soft);
}

#account-user[hidden],
#account-guest[hidden] {
  display: none;
}

@media (max-width: 760px) {
  .layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .palette-wrap,
  .palette-scroll {
    height: auto;
    max-height: 52vh;
  }

  .result-pane {
    height: auto;
  }

  .board-fit {
    min-height: 0;
    container-type: normal;
    display: block;
  }

  .board {
    width: min(100%, 420px);
    height: auto;
  }

  .palette-bar {
    display: none;
  }

  .header h1 {
    font-size: 24px;
  }
}
