:root {
  --bg: #f4f0ff;
  --bg-grad-a: #eef2ff;
  --bg-grad-b: #fdf2f8;
  --card: #ffffff;
  --text: #24213b;
  --muted: #6b6784;
  --primary: #6c5ce7;
  --primary-dark: #5a45d1;
  --accent: #ff6f91;
  --accent-2: #00c9a7;
  --border: #e6e2f6;
  --shadow: 0 8px 24px rgba(108, 92, 231, 0.12);
  --radius: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(135deg, var(--bg-grad-a), var(--bg-grad-b));
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding: 18px 28px;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand a {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.brand-icon { font-size: 28px; }

.brand-name {
  font-size: 20px;
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tabs {
  display: flex;
  gap: 6px;
  background: var(--card);
  padding: 6px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.18s ease;
  white-space: nowrap;
  display: inline-block;
}

.tab-btn:hover { color: var(--primary); }

.tab-btn.active {
  background: linear-gradient(135deg, var(--primary), #8b7cf6);
  color: #fff;
  box-shadow: 0 4px 12px rgba(108, 92, 231, 0.35);
}

/* Main content */
.content {
  flex: 1;
  padding: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.hero {
  max-width: 980px;
  width: 100%;
  text-align: center;
}

.hero h1 {
  font-size: clamp(22px, 3.6vw, 30px);
  margin: 4px 0 8px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.hero-tagline {
  color: var(--muted);
  font-size: 14px;
  max-width: 640px;
  margin: 0 auto;
  line-height: 1.6;
}

.hero-tagline a {
  color: var(--primary-dark);
  font-weight: 700;
  text-decoration: none;
}

.hero-tagline a:hover { text-decoration: underline; }

.breadcrumb {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 10px;
}

.breadcrumb a {
  color: var(--primary-dark);
  text-decoration: none;
  font-weight: 600;
}

.breadcrumb a:hover { text-decoration: underline; }

.breadcrumb .sep { margin: 0 4px; }

.game-panel {
  display: none;
  gap: 24px;
  max-width: 980px;
  width: 100%;
  animation: fadeIn 0.25s ease;
  scroll-margin-top: 100px;
}

.game-panel.active { display: flex; flex-wrap: wrap; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.board-area {
  flex: 1 1 480px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 320px;
}

.board-header {
  width: 100%;
  margin-bottom: 16px;
}

.board-header h2 {
  margin: 0 0 4px 0;
  font-size: 22px;
  font-weight: 800;
}

.game-intro {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

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

/* Side panel (randomizer lives here) */
.side-panel {
  flex: 0 0 200px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-self: flex-start;
  height: fit-content;
}

.randomize-btn {
  border: none;
  padding: 13px 14px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #ff9a76);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(255, 111, 145, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.randomize-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 18px rgba(255, 111, 145, 0.4); }
.randomize-btn:active { transform: translateY(0); }

.secondary-btn {
  border: 1px solid var(--border);
  background: #faf9ff;
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease;
}

.secondary-btn:hover { background: #f0edff; }

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-group label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.control-group select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

.stat-row span:last-child { color: var(--text); font-weight: 800; }

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
}

/* Sudoku */
.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  width: min(430px, 100%);
  aspect-ratio: 1;
  border: 2px solid var(--text);
  border-radius: 8px;
  overflow: hidden;
}

.sudoku-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(13px, 3.4vw, 18px);
  font-weight: 700;
  border: 1px solid #d9d5ef;
  background: #fff;
  color: var(--primary-dark);
  cursor: text;
}

.sudoku-cell.given { color: var(--text); background: #f6f4ff; cursor: default; }
.sudoku-cell.error { background: #ffe3e8; color: var(--accent); }
.sudoku-cell:nth-child(3n) { border-right: 2px solid var(--text); }
.sudoku-cell:nth-child(9n+1) { border-left: 2px solid var(--text); }
.sudoku-row-thick { border-bottom: 2px solid var(--text); }

/* 2048 */
.twenty48-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
  width: min(380px, 100%);
  aspect-ratio: 1;
  background: #e4defa;
  border-radius: 12px;
  padding: 10px;
}

.t48-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-weight: 800;
  font-size: clamp(14px, 4vw, 24px);
  background: #ded6f7;
  color: #b3a8e0;
  transition: all 0.1s ease;
}

.t48-tile[data-val="2"] { background: #f4f1ff; color: #6c5ce7; }
.t48-tile[data-val="4"] { background: #ece5ff; color: #6c5ce7; }
.t48-tile[data-val="8"] { background: #c9b8ff; color: #fff; }
.t48-tile[data-val="16"] { background: #a68bff; color: #fff; }
.t48-tile[data-val="32"] { background: #8b6cf6; color: #fff; }
.t48-tile[data-val="64"] { background: #6c5ce7; color: #fff; }
.t48-tile[data-val="128"] { background: #ff9a76; color: #fff; font-size: 90%; }
.t48-tile[data-val="256"] { background: #ff7f5c; color: #fff; font-size: 90%; }
.t48-tile[data-val="512"] { background: #ff6f91; color: #fff; font-size: 90%; }
.t48-tile[data-val="1024"] { background: #ff4f78; color: #fff; font-size: 80%; }
.t48-tile[data-val="2048"] { background: #00c9a7; color: #fff; font-size: 80%; }

/* Kakuro */
.kakuro-board {
  display: grid;
  gap: 2px;
  background: var(--text);
  border-radius: 8px;
  overflow: hidden;
  width: min(430px, 100%);
}

.kakuro-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  font-size: clamp(12px, 3vw, 16px);
  font-weight: 700;
  color: var(--primary-dark);
  position: relative;
}

.kakuro-cell.blocked {
  background: #2f2b45;
}

.kakuro-cell.clue {
  background: #34304d;
  color: #fff;
  font-size: clamp(9px, 2.2vw, 11px);
  font-weight: 700;
}

.kakuro-cell.clue .clue-right {
  position: absolute;
  top: 3px;
  right: 5px;
}

.kakuro-cell.clue .clue-down {
  position: absolute;
  bottom: 3px;
  left: 5px;
}

.kakuro-cell.clue .clue-slash {
  position: absolute;
  width: 140%;
  height: 1px;
  background: #605c7a;
  transform: rotate(-40deg);
}

.kakuro-cell.error { background: #ffe3e8; }

.kakuro-cell input {
  width: 100%;
  height: 100%;
  border: none;
  text-align: center;
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
  background: transparent;
  outline: none;
}

/* Minesweeper */
.minesweeper-board {
  display: grid;
  gap: 2px;
  background: #c9c4e6;
  border-radius: 8px;
  padding: 4px;
  overflow: auto;
  max-width: 100%;
}

.ms-cell {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ede9fb;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
}

.ms-cell.revealed {
  background: #fff;
  cursor: default;
}

.ms-cell.mine { background: var(--accent); }
.ms-cell.flag { background: #ffd97d; }

.ms-cell[data-n="1"] { color: #6c5ce7; }
.ms-cell[data-n="2"] { color: #00c9a7; }
.ms-cell[data-n="3"] { color: #ff6f91; }
.ms-cell[data-n="4"] { color: #5a45d1; }
.ms-cell[data-n="5"] { color: #ff9a76; }
.ms-cell[data-n="6"] { color: #34304d; }

/* 15 puzzle */
.fifteen-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 8px;
  width: min(360px, 100%);
  aspect-ratio: 1;
  background: #e4defa;
  border-radius: 12px;
  padding: 8px;
}

.f15-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #8b7cf6);
  color: #fff;
  font-weight: 800;
  font-size: clamp(16px, 5vw, 26px);
  cursor: pointer;
  transition: transform 0.1s ease;
}

.f15-tile:hover { transform: scale(1.03); }
.f15-tile.empty { background: transparent; cursor: default; box-shadow: none; }

/* Footer */
.site-footer {
  text-align: center;
  padding: 16px;
  font-size: 12px;
  color: var(--muted);
}

.site-footer p { margin: 0; }

/* Responsive */
@media (max-width: 720px) {
  .site-header { flex-direction: column; align-items: flex-start; }
  .game-panel { flex-direction: column; }
  .side-panel { flex-direction: row; flex-wrap: wrap; width: 100%; }
  .side-panel .randomize-btn { flex: 1 1 100%; }
}
