:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #ffffff;
  --text: #20211e;
  --muted: #777970;
  --line: #e9e9e3;
  --accent: #1e6e52;
  --tile-bg: #f1f2ec;
  --shadow: 0 12px 35px rgb(34 42 37 / 7%);
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: "Noto Sans KR", sans-serif;
  transition: background-color .25s ease, color .25s ease;
}

body.dark-mode {
  color-scheme: dark;
  --page: #171a18;
  --surface: #202420;
  --text: #f2f3ed;
  --muted: #acb0a9;
  --line: #363a35;
  --accent: #80c6a4;
  --tile-bg: #2a2f2a;
  --shadow: 0 12px 35px rgb(0 0 0 / 18%);
}

button { font: inherit; }

.app-shell { width: min(100% - 40px, 640px); margin: 0 auto; padding: 28px 0 56px; }

.app-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 38px; }

.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--text); font-size: .78rem; font-weight: 700; letter-spacing: .09em; text-decoration: none; }
.brand-mark { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 9px; background: var(--accent); font-size: 1rem; }

.icon-button, .text-button { border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; font-size: 1.15rem; transition: border-color .2s, color .2s, transform .2s; }
.icon-button:hover { color: var(--accent); border-color: var(--accent); transform: rotate(12deg); }

.game-card { padding: 30px 24px 28px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); text-align: center; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: .68rem; font-weight: 700; letter-spacing: .13em; }
h2 { margin: 0; letter-spacing: -.04em; }

.stats-bar { display: flex; align-items: center; justify-content: center; gap: 28px; margin-bottom: 20px; }
.stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stat-label { color: var(--muted); font-size: .7rem; font-weight: 700; letter-spacing: .08em; }
.stat-value { font-size: 1.4rem; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.stats-bar .text-button { font-size: .8rem; text-decoration: underline; text-underline-offset: 3px; }
.stats-bar .text-button:hover { color: var(--accent); }

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  padding: 10px;
  border-radius: 18px;
  background: var(--tile-bg);
  aspect-ratio: 1 / 1;
  user-select: none;
}

.tile {
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  border: 0;
  border-radius: 50%;
  font-size: clamp(1.7rem, 6.5vw, 2.5rem);
  line-height: 1;
  cursor: pointer;
  box-shadow: inset 0 -4px 0 rgb(0 0 0 / 8%), inset 0 3px 0 rgb(255 255 255 / 55%), 0 2px 4px rgb(0 0 0 / 8%);
  transition: transform .15s ease, box-shadow .15s ease, opacity .2s ease;
}

.tile-0 { background: #ffe1b8; }
.tile-1 { background: #ffd0e0; }
.tile-2 { background: #ffcaa8; }
.tile-3 { background: #c7e8ff; }
.tile-4 { background: #f0dcc0; }
.tile-5 { background: #e3e6ea; }

body.dark-mode .tile-0 { background: #6b552f; }
body.dark-mode .tile-1 { background: #6b3a4a; }
body.dark-mode .tile-2 { background: #6b4630; }
body.dark-mode .tile-3 { background: #2f5266; }
body.dark-mode .tile-4 { background: #5a4a34; }
body.dark-mode .tile-5 { background: #4a4d52; }

.tile:hover { transform: translateY(-2px) scale(1.06); }
.tile.selected { box-shadow: 0 0 0 3px var(--accent), inset 0 -4px 0 rgb(0 0 0 / 8%), inset 0 3px 0 rgb(255 255 255 / 55%); transform: scale(1.08); }
.tile.clearing { transform: scale(.3); opacity: 0; }

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(10 12 10 / 55%);
  padding: 20px;
  z-index: 10;
}

.overlay[hidden] { display: none; }

.overlay-card {
  width: min(100%, 340px);
  padding: 34px 28px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.final-score { margin: 10px 0 22px; color: var(--muted); font-size: .95rem; }
.final-score strong { color: var(--accent); font-size: 1.3rem; }

.generate-button { width: 100%; padding: 14px 20px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; cursor: pointer; font-weight: 700; transition: filter .2s, transform .2s; }
.generate-button:hover { filter: brightness(.93); transform: translateY(-1px); }

@media (max-width: 480px) {
  .app-shell { width: min(100% - 28px, 560px); padding-top: 18px; }
  .app-header { margin-bottom: 26px; }
  .game-card { padding: 28px 16px 22px; }
  .stats-bar { gap: 18px; }
}
