/* Theme variables (light/dark palettes) moved to theme.css — every page must load theme.css before this file. */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Jost", "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", Arial, sans-serif;
  font-weight: 300;
  min-height: 100vh;
  transition: background-color 0.2s ease, color 0.2s ease;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

.scroll-progress {
  height: 3px;
  left: 0;
  pointer-events: none;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 30;
}

.scroll-progress-bar {
  background: var(--accent);
  height: 100%;
  transition: width 0.12s linear;
  width: 0%;
}

.site-header {
  align-items: center;
  backdrop-filter: blur(16px);
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  padding: 16px clamp(18px, 5vw, 72px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  align-items: baseline;
  display: inline-flex;
  gap: 8px;
}

.brand span {
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 400;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.brand strong {
  color: var(--muted);
  font-weight: 300;
}

nav {
  align-items: center;
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  gap: clamp(10px, 2vw, 24px);
  justify-content: center;
}

nav a {
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.94rem;
  padding: 6px 4px;
  position: relative;
}

nav a:hover {
  color: var(--ink);
}

nav a.is-active {
  color: var(--gold);
  font-weight: 800;
}

nav a.is-active::after {
  background: var(--gold);
  border-radius: 999px;
  bottom: -2px;
  content: "";
  height: 2px;
  left: 4px;
  position: absolute;
  right: 4px;
}

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

.theme-toggle {
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 700;
  min-height: 40px;
  padding: 0 14px;
  white-space: nowrap;
}

.nav-toggle {
  align-items: center;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  display: none;
  font-size: 1.2rem;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0;
}

.hero {
  align-items: center;
  display: grid;
  gap: clamp(32px, 6vw, 72px);
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  min-height: calc(100svh - 66px);
  padding: clamp(54px, 9vw, 110px) clamp(18px, 5vw, 72px);
}

.hero-copy {
  max-width: 780px;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
  letter-spacing: 0.18em;
  margin: 0 0 14px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3 {
  font-weight: 300;
}

h1 {
  font-size: clamp(3.3rem, 9vw, 7.7rem);
  letter-spacing: 0;
  line-height: 0.95;
  margin-bottom: 24px;
}

h2 {
  font-size: clamp(2rem, 5vw, 4.8rem);
  letter-spacing: 0;
  line-height: 1.05;
  margin-bottom: 14px;
}

p {
  color: var(--muted);
  line-height: 1.8;
}

.hero-copy p:not(.eyebrow) {
  font-size: clamp(1.05rem, 1.8vw, 1.35rem);
}

.hero-actions,
.button-row,
.inline-control,
.hanoi-toolbar,
.mine-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.hero-actions {
  margin-top: 30px;
}

.button,
button {
  align-items: center;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  font-weight: 500;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.button-primary,
button {
  background: var(--accent);
  color: #ffffff;
}

.button-primary:hover,
button:hover {
  background: var(--accent-hover);
}

.button-secondary,
.ghost-button {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
}

.button-secondary:hover,
.ghost-button:hover {
  border-color: var(--accent-hover);
  color: var(--accent-hover);
}

.hero-board {
  aspect-ratio: 1;
  background: var(--card-base);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 360px;
  overflow: hidden;
  position: relative;
}

.mini-sudoku {
  display: grid;
  gap: 5px;
  grid-template-columns: repeat(9, 1fr);
  left: 8%;
  position: absolute;
  right: 18%;
  top: 10%;
}

.mini-sudoku span {
  aspect-ratio: 1;
  background: var(--deco);
  border: 1px solid var(--deco-strong);
  display: grid;
  place-items: center;
}

.mini-hanoi {
  border-bottom: 4px solid var(--deco-strong);
  bottom: 14%;
  height: 34%;
  left: 10%;
  position: absolute;
  right: 10%;
}

.mini-hanoi i {
  background: var(--deco);
  bottom: 0;
  display: block;
  height: 100%;
  position: absolute;
  width: 5px;
}

.mini-hanoi i:nth-child(1) {
  left: 16%;
}

.mini-hanoi i:nth-child(2) {
  left: 50%;
}

.mini-hanoi i:nth-child(3) {
  left: 84%;
}

.mini-hanoi b {
  background: var(--cyan);
  border-radius: 999px;
  bottom: 0;
  display: block;
  height: 16px;
  left: 16%;
  position: absolute;
  transform: translateX(-50%);
}

.mini-hanoi .disk-1 {
  bottom: 36px;
  width: 78px;
}

.mini-hanoi .disk-2 {
  bottom: 18px;
  width: 112px;
}

.mini-hanoi .disk-3 {
  background: var(--gold);
  width: 148px;
}

.mini-ab {
  background: rgba(0, 0, 0, 0.44);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--accent);
  font-size: clamp(2rem, 6vw, 4.4rem);
  font-weight: 900;
  padding: 12px 18px;
  position: absolute;
  right: 8%;
  top: 44%;
}

.game-section {
  display: grid;
  gap: 22px;
  padding: 0 clamp(18px, 5vw, 72px) clamp(70px, 9vw, 110px);
}

.game-panel {
  background: var(--card-base);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
  padding: clamp(18px, 4vw, 34px);
}

.panel-heading {
  max-width: 820px;
}

.sudoku-layout {
  align-items: start;
  display: grid;
  gap: 24px;
  grid-template-columns: minmax(280px, 0.82fr) minmax(320px, 1fr);
}

.ab-layout {
  align-items: start;
  display: grid;
  gap: 24px;
  grid-template-columns: minmax(280px, 0.82fr) minmax(320px, 1fr);
  grid-template-areas: "play history";
}

.ab-layout .ab-play {
  grid-area: play;
}

.ab-layout .history-card {
  grid-area: history;
}

.control-stack,
.ab-play {
  display: grid;
  gap: 12px;
}

label {
  color: var(--muted);
  font-weight: 700;
}

input,
select {
  background: var(--field-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  min-height: 44px;
  outline: none;
  padding: 0 12px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(62, 143, 216, 0.14);
}

.inline-control input {
  flex: 1 1 180px;
}

output,
.history-card {
  background: var(--well);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--green);
  display: block;
  line-height: 1.7;
  min-height: 52px;
  padding: 14px;
}

.history-card {
  color: var(--ink);
}

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

.history-title span {
  color: var(--gold);
}

ol {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 0;
  max-height: 260px;
  overflow: auto;
  padding: 0;
}

ol li {
  align-items: center;
  background: var(--surface-strong);
  border-radius: var(--radius);
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
}

ol li span {
  color: var(--green);
  font-weight: 900;
}

.sudoku-board {
  aspect-ratio: 1;
  background: var(--ink);
  border: 3px solid var(--ink);
  display: grid;
  gap: 1px;
  grid-template-columns: repeat(9, 1fr);
  max-width: min(100%, 560px);
}

.sudoku-board .cell {
  align-items: center;
  border: 0;
  border-radius: 0;
  color: #10201c;
  cursor: pointer;
  display: flex;
  font-size: clamp(0.85rem, 3.6vw, 1.8rem);
  font-weight: 900;
  justify-content: center;
  min-height: 0;
  min-width: 0;
  outline: none;
  padding: 0;
  text-align: center;
  user-select: none;
  width: 100%;
}

.sudoku-board .cell:nth-child(3n) {
  border-right: 2px solid #10201c;
}

.sudoku-board .cell:nth-child(9n) {
  border-right: 0;
}

.sudoku-board .cell:nth-child(n + 19):nth-child(-n + 27),
.sudoku-board .cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom: 2px solid #10201c;
}

.sudoku-board .cell:not(.fixed) {
  background: #ffffff;
}

.sudoku-board .fixed {
  background: #dce8e1;
  color: #0f251f;
}

/* 選取格的列/行/宮格，以及相同數字所在的行列：反差底色 */
.sudoku-board .cell.related,
.sudoku-board .fixed.related {
  background: #fdf3c8;
}

/* 與目前數字相同的格子：更強的反差 */
.sudoku-board .cell.same,
.sudoku-board .fixed.same {
  background: #b9d7f3;
  color: #123a63;
}

/* 目前選取的格子 */
.sudoku-board .cell.selected,
.sudoku-board .fixed.selected {
  background: #3e8fd8;
  color: #ffffff;
}

.sudoku-board .wrong {
  background: #ffd7df;
  color: #8d1732;
}

.sudoku-board .hinted {
  background: #dcfff0;
  color: #11613c;
}

/* 筆記小數字：3x3 排列 */
.sudoku-board .cell-notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: 100%;
  width: 100%;
}

.sudoku-board .cell-notes span {
  align-items: center;
  color: #55697a;
  display: flex;
  font-size: clamp(0.42rem, 1.15vw, 0.68rem);
  font-weight: 600;
  justify-content: center;
  line-height: 1;
}

.sudoku-board .cell.selected .cell-notes span {
  color: #eaf3fc;
}

/* 數字鍵盤 */
.sudoku-pad {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, 1fr);
  max-width: 320px;
}

.sudoku-pad button {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 1.35rem;
  font-weight: 700;
  min-height: 54px;
}

.sudoku-pad button:hover {
  background: var(--surface);
  border-color: var(--accent);
  color: var(--accent);
}

#sudokuNoteButton.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.sudoku-keys {
  color: var(--muted);
  font-size: 0.88rem;
}

.sudoku-keys p {
  line-height: 2;
  margin: 8px 0 0;
}

.hanoi-toolbar {
  align-items: center;
  margin-bottom: 18px;
}

.hanoi-toolbar select {
  width: 86px;
}

.hanoi-toolbar span {
  color: var(--gold);
  font-weight: 900;
  margin-left: auto;
}

.hanoi-board {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, 1fr);
  min-height: 330px;
}

.tower {
  align-items: center;
  background: var(--well);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  justify-content: flex-start;
  min-height: 320px;
  overflow: hidden;
  padding: 28px 12px 18px;
  position: relative;
}

.tower::before {
  background: var(--deco);
  bottom: 0;
  content: "";
  height: 30%;
  left: 0;
  position: absolute;
  right: 0;
  z-index: 0;
}

.tower.selected {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 2px rgba(62, 143, 216, 0.24);
}

.pole {
  background: var(--deco-strong);
  bottom: 18px;
  left: 50%;
  position: absolute;
  top: 34px;
  transform: translateX(-50%);
  width: 8px;
  z-index: 0;
}

.hanoi-disk {
  background: var(--accent);
  border-radius: 999px;
  box-shadow: none;
  color: #ffffff;
  display: grid;
  font-style: normal;
  font-weight: 900;
  height: 24px;
  max-width: 92%;
  place-items: center;
  position: relative;
  width: calc(30% + var(--size) * 9%);
  z-index: 1;
}

.mine-toolbar {
  align-items: center;
  margin-bottom: 18px;
}

.mine-toolbar select {
  min-width: 150px;
}

.mine-toolbar span {
  color: var(--gold);
  font-weight: 900;
  margin-left: auto;
}

.mine-board-wrap {
  min-width: 0;
  overflow: auto;
  padding-bottom: 4px;
}

.mine-board {
  display: grid;
  gap: 3px;
  grid-template-columns: repeat(var(--cols), minmax(30px, 1fr));
  max-width: 720px;
  min-width: min(100%, 360px);
}

.mine-cell {
  aspect-ratio: 1;
  background: var(--cell-base);
  border: 1px solid var(--cell-border);
  color: var(--ink);
  font-size: clamp(0.9rem, 2vw, 1.15rem);
  min-height: 30px;
  padding: 0;
  user-select: none;
}

.mine-cell.revealed {
  background: rgba(247, 251, 246, 0.92);
  border-color: rgba(0, 0, 0, 0.16);
  color: #10201c;
}

.mine-cell.flagged {
  background: rgba(62, 143, 216, 0.14);
  color: var(--gold);
}

.mine-cell.mine {
  background: #ffd7df;
  color: #8d1732;
}

.mine-cell[data-count="1"] {
  color: #1767c7;
}

.mine-cell[data-count="2"] {
  color: #147a38;
}

.mine-cell[data-count="3"] {
  color: #b32032;
}

.mine-cell[data-count="4"],
.mine-cell[data-count="5"],
.mine-cell[data-count="6"],
.mine-cell[data-count="7"],
.mine-cell[data-count="8"] {
  color: #6430a4;
}

.back-to-top {
  align-items: center;
  background: var(--accent);
  border: 0;
  border-radius: 999px;
  bottom: 24px;
  box-shadow: var(--shadow);
  color: #ffffff;
  cursor: pointer;
  display: flex;
  font-size: 1.3rem;
  font-weight: 500;
  height: 48px;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  right: 24px;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease, background-color 0.2s ease;
  width: 48px;
  z-index: 25;
}

.back-to-top:hover {
  background: var(--accent-hover);
}

.back-to-top.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.footer {
  align-items: center;
  border-top: 1px solid var(--line);
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  padding: 24px clamp(18px, 5vw, 72px);
}

.footer p {
  margin: 0;
}

.footer a {
  color: var(--gold);
}

@media (max-width: 900px) {
  .hero,
  .ab-layout,
  .sudoku-layout {
    grid-template-columns: 1fr;
  }

  /* 1A2B:手機改成「紀錄在上、輸入區在下」,鍵盤與輸入框相鄰,少上下滑 */
  .ab-layout {
    gap: 14px;
    grid-template-areas:
      "history"
      "play";
  }

  .ab-layout .history-card ol {
    max-height: 148px;
  }

  .hero {
    min-height: auto;
  }

  .hero-board {
    min-height: min(82vw, 520px);
  }

  .nav-toggle {
    display: inline-flex;
    order: 2;
  }

  .header-actions {
    margin-left: auto;
    order: 2;
  }

  nav {
    background: var(--header-bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    display: none;
    flex-basis: 100%;
    flex-direction: column;
    gap: 4px;
    justify-content: flex-start;
    max-height: 70vh;
    max-width: 100%;
    min-width: 0;
    order: 3;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 10px;
    width: 100%;
  }

  nav.is-open {
    display: flex;
  }

  nav a {
    max-width: 100%;
    overflow-wrap: anywhere;
    padding: 10px 12px;
  }

  nav a.is-active {
    background: var(--surface-strong);
    border-radius: var(--radius);
  }

  nav a.is-active::after {
    display: none;
  }
}

@media (max-width: 620px) {
  .site-header,
  .footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .header-actions {
    margin-left: 0;
  }

  h1 {
    font-size: clamp(3rem, 17vw, 4.7rem);
  }

  .button,
  .hero-actions a,
  .button-row button,
  .inline-control button,
  .inline-control input {
    width: 100%;
  }

  .hanoi-board {
    gap: 8px;
    min-height: 270px;
  }

  .mine-toolbar span {
    margin-left: 0;
  }

  .mine-board {
    grid-template-columns: repeat(var(--cols), 30px);
    max-width: none;
    width: max-content;
  }

  .tower {
    min-height: 260px;
    padding-inline: 6px;
  }

  .hanoi-disk {
    font-size: 0.82rem;
    height: 22px;
  }

  .back-to-top {
    bottom: 16px;
    right: 16px;
  }
}

/* ===== 1A2B 數字小鍵盤(手機好按,桌機也可點) ===== */
.ab-keypad {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 12px;
  max-width: 300px;
}

.ab-keypad button {
  background: var(--field-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  min-height: 52px;
  touch-action: manipulation;
  transition: border-color 0.15s ease, background-color 0.15s ease;
  user-select: none;
}

.ab-keypad button:hover {
  border-color: var(--accent);
}

.ab-keypad button:active {
  background: var(--surface-strong);
  transform: translateY(1px);
}

.ab-keypad .ab-key-fn {
  color: var(--muted);
}

.ab-keypad .ab-key-enter {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-size: 1.05rem;
}

.ab-keypad .ab-key-enter:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

@media (max-width: 640px) {
  .ab-keypad {
    gap: 7px;
    max-width: none;
  }

  .ab-keypad button {
    min-height: 50px;
    font-size: 1.15rem;
  }
}
