:root {
  color-scheme: light;
  --bg: #f7f8f9;
  --surface: #ffffff;
  --surface-soft: #f1f3f5;
  --ink: #15171a;
  --muted: #6f7782;
  --line: #dfe3e8;
  --line-strong: #cbd1d8;
  --accent: #275fe8;
  --accent-soft: #e9eefc;
  --success: #1e8e69;
  --warning: #d39527;
  --danger: #d85d4f;
  --shadow: 0 18px 50px rgba(20, 28, 38, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.84), rgba(247,248,249,0.92)),
    radial-gradient(circle at 18% 8%, rgba(39, 95, 232, 0.07), transparent 28%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button {
  border: 0;
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  min-height: calc(100vh - 48px);
  margin: 24px auto;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 2px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-size: 18px;
  font-weight: 720;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background:
    radial-gradient(circle at 30% 30%, var(--accent) 0 12%, transparent 13%),
    radial-gradient(circle at 70% 32%, #25b489 0 10%, transparent 11%),
    radial-gradient(circle at 34% 70%, #f0b441 0 10%, transparent 11%),
    radial-gradient(circle at 70% 72%, #d85d4f 0 12%, transparent 13%),
    #fff;
}

.top-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.top-status span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 11px;
  background: rgba(255, 255, 255, 0.72);
}

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

.board-section,
.side-panel {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.board-section {
  padding: 24px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 14px;
}

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

.micro-label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 52px);
  line-height: 0.98;
  font-weight: 760;
  letter-spacing: 0;
}

.secret-code {
  display: grid;
  grid-template-columns: repeat(var(--code-length, 4), 42px);
  gap: 8px;
  flex: 0 0 auto;
}

.secret-cover,
.secret-token {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 15px;
  font-weight: 760;
}

.secret-cover {
  background:
    linear-gradient(135deg, transparent 47%, rgba(21,23,26,0.13) 48% 52%, transparent 53%),
    var(--surface-soft);
}

.board-labels,
.guess-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 104px;
  align-items: center;
}

.board-labels {
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
}

.board-labels span:last-child {
  grid-column: 3;
}

.guess-board {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.guess-row {
  min-height: 48px;
  border-top: 1px solid var(--line);
}

.guess-row.is-current {
  background: linear-gradient(90deg, rgba(39,95,232,0.055), transparent 74%);
}

.attempt-number {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.guess-cells,
.feedback-cells,
.current-slots {
  display: grid;
  grid-template-columns: repeat(var(--code-length, 4), 42px);
  gap: 8px;
  align-items: center;
}

.feedback-cells {
  grid-template-columns: repeat(var(--code-length, 4), 13px);
  grid-auto-rows: 13px;
  gap: 6px;
  justify-content: end;
}

.cell,
.token-button,
.current-slot {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 760;
  line-height: 1;
}

.cell.is-empty,
.current-slot.is-empty {
  background: rgba(241, 243, 245, 0.74);
  color: transparent;
}

.piece-color {
  border-radius: 50%;
  color: transparent;
  border-color: rgba(21, 23, 26, 0.1);
}

.piece-word {
  width: 42px;
  min-width: 42px;
  padding: 0;
  font-size: 14px;
}

.piece-word.is-exact {
  background: #dcefe7;
  border-color: rgba(30, 142, 105, 0.38);
  color: #17694f;
}

.piece-word.is-near {
  background: #fff2d4;
  border-color: rgba(211, 149, 39, 0.4);
  color: #8a5e0e;
}

.piece-word.is-miss {
  background: #e8ebef;
  color: #6f7782;
}

.piece-number {
  font-variant-numeric: tabular-nums;
  font-size: 16px;
}

.token-button.piece-number {
  width: 100%;
}

body[data-mode="number"] .token-palette {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.piece-dots {
  color: transparent;
  position: relative;
}

.piece-dots::before {
  content: "";
  width: 24px;
  height: 24px;
  display: block;
  background: var(--dot-pattern);
}

.feedback-dot,
.feedback-sample {
  width: 13px;
  height: 13px;
  display: inline-block;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: transparent;
}

.feedback-dot.exact,
.feedback-sample.exact {
  background: var(--ink);
  border-color: var(--ink);
}

.feedback-dot.near,
.feedback-sample.near {
  background: var(--surface);
  border-color: var(--ink);
}

.input-dock {
  display: block;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.primary-action,
.ghost-action {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 760;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.primary-action {
  background: var(--ink);
  color: #fff;
}

.ghost-action {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
}

.primary-action:hover,
.ghost-action:hover,
.mode-tab:hover,
.token-button:hover {
  transform: translateY(-1px);
}

.primary-action:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

.side-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel-block {
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

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

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mode-tab {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 760;
}

.mode-tab.is-active {
  background: var(--accent-soft);
  border-color: rgba(39, 95, 232, 0.34);
  color: var(--accent);
}

.status-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.status-dot {
  width: 10px;
  height: 10px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--accent);
}

.status-card.is-win .status-dot {
  background: var(--success);
}

.status-card.is-lose .status-dot {
  background: var(--danger);
}

.status-card.is-hint .status-dot {
  background: var(--warning);
}

.status-text {
  min-height: 40px;
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  font-weight: 560;
}

.token-palette {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.check-in-panel {
  width: 100%;
  margin-top: 18px;
}

.token-button {
  width: 100%;
  cursor: pointer;
}

.token-button.piece-color {
  width: 42px;
  justify-self: center;
}

.token-button.piece-word {
  width: 100%;
  min-width: 0;
}

body[data-mode="word"] .token-palette {
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

body[data-mode="word"] .token-button {
  height: 34px;
  font-size: 12px;
}

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

.compact-rules {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.compact-rules div {
  display: flex;
  align-items: center;
  gap: 8px;
}

@media (max-width: 900px) {
  .app-shell {
    width: min(100vw - 24px, 680px);
    margin: 12px auto;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    order: -1;
  }

  .board-section {
    padding: 18px;
  }
}

@media (max-width: 560px) {
  .topbar,
  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .secret-code,
  .guess-cells,
  .current-slots {
    grid-template-columns: repeat(var(--code-length, 4), minmax(0, 1fr));
    width: 100%;
  }

  .secret-cover,
  .secret-token,
  .cell,
  .token-button,
  .current-slot {
    width: 100%;
    height: 38px;
  }

  .piece-word {
    min-width: 0;
    font-size: 12px;
  }

  .board-labels,
  .guess-row {
    grid-template-columns: 38px minmax(0, 1fr) 54px;
  }

  .feedback-cells {
    grid-template-columns: repeat(2, 11px);
    gap: 5px;
  }
}
