/* ===== GameHanpan shared styles (dark modern theme) ===== */
:root {
  --bg: #0f1220;
  --bg-soft: #151a2e;
  --card: #1a2038;
  --card-hover: #222a4a;
  --border: #2b3355;
  --text: #e8eaf4;
  --muted: #9aa3bd;
  --accent: #6c8cff;
  --accent-soft: rgba(108, 140, 255, 0.15);
  --green: #41d99d;
  --red: #ff5d6c;
  --yellow: #ffcf5c;
  --radius: 14px;
  --maxw: 860px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic",
    "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  line-height: 1.65;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }

/* ----- header ----- */
.site-header {
  background: rgba(15, 18, 32, 0.92);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}
.brand {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
}
.brand:hover { text-decoration: none; color: var(--accent); }
.nav-right { display: flex; align-items: center; gap: 16px; }
.nav-links { display: flex; gap: 18px; }
.nav-links a { color: var(--muted); font-size: 0.92rem; font-weight: 600; }
.nav-links a:hover { color: var(--text); text-decoration: none; }

/* ----- language toggle ----- */
.lang-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--card);
}
.lang-toggle button {
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 5px 12px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, color 0.15s ease;
}
.lang-toggle button.active { background: var(--accent); color: #fff; }
.lang-toggle button:not(.active):hover { color: var(--text); }

/* ----- main ----- */
main { flex: 1; padding: 24px 0 48px; }

.hero { text-align: center; padding: 28px 0 8px; }
.hero h1 { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; }
.hero p { color: var(--muted); margin-top: 8px; }

h1 { font-size: 1.5rem; margin-bottom: 12px; letter-spacing: -0.02em; }
h2 { font-size: 1.15rem; margin: 28px 0 10px; letter-spacing: -0.01em; }
p + p { margin-top: 10px; }

/* ----- game card grid ----- */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 24px;
}
.game-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 18px;
  color: var(--text);
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.game-card:hover {
  background: var(--card-hover);
  border-color: var(--accent);
  transform: translateY(-3px);
  text-decoration: none;
}
.game-card .emoji { font-size: 2rem; display: block; margin-bottom: 8px; }
.game-card h3 { font-size: 1.05rem; margin-bottom: 4px; }
.game-card p { color: var(--muted); font-size: 0.86rem; line-height: 1.5; }

/* ----- game page common ----- */
.game-wrap {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  margin: 16px 0;
  text-align: center;
}
.score-bar {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.score-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 16px;
  min-width: 90px;
}
.score-box .label { font-size: 0.72rem; color: var(--muted); display: block; }
.score-box .value { font-size: 1.2rem; font-weight: 800; }

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 11px 26px;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: scale(0.97); }
.btn.secondary { background: var(--card); border: 1px solid var(--border); color: var(--text); }

.status-msg { margin: 12px 0; min-height: 1.6em; color: var(--muted); font-weight: 600; }

/* ----- ad slot: collapses automatically when empty ----- */
.ad-slot { margin: 0 auto; text-align: center; overflow: hidden; }
.ad-slot:empty { display: none; }
.ad-slot:not(:empty) { margin: 18px auto; }

/* ----- game guide section ----- */
.guide {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 24px;
}
.guide h2 { margin-top: 0; }
.guide ul { padding-left: 20px; margin: 8px 0; }
.guide li { margin: 4px 0; color: var(--muted); }
.guide p { color: var(--muted); font-size: 0.94rem; }

/* ----- more games ----- */
.more-games { margin-top: 28px; }
.more-games h2 { margin-bottom: 12px; }
.more-list { display: flex; flex-wrap: wrap; gap: 10px; }
.more-list a {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}
.more-list a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

/* ----- footer ----- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}
.site-footer a { color: var(--muted); text-decoration: underline; }

/* ===== Reaction Time Test ===== */
.reaction-pad {
  border-radius: var(--radius);
  height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.3rem;
  font-weight: 800;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  transition: background 0.1s ease;
  padding: 16px;
}
.reaction-pad.idle { background: var(--card); border: 2px dashed var(--border); }
.reaction-pad.waiting { background: #8b2635; }
.reaction-pad.ready { background: #1d8a5f; }
.reaction-pad.result { background: var(--card); border: 2px solid var(--accent); }
.reaction-pad small { font-size: 0.85rem; font-weight: 400; color: rgba(255,255,255,0.75); margin-top: 8px; }
.reaction-pad .big { font-size: 2.2rem; }

/* ===== Number Guess ===== */
.guess-input-row { display: flex; gap: 8px; justify-content: center; margin: 14px 0; }
.guess-input-row input {
  width: 130px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
  padding: 10px;
  font-family: inherit;
}
.guess-input-row input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.guess-history {
  list-style: none;
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}
.guess-history li {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
}
.hint-up { color: var(--green); font-weight: 700; }
.hint-down { color: var(--red); font-weight: 700; }
.hint-correct { color: var(--yellow); font-weight: 700; }

/* ===== 2048 ===== */
.board2048 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  width: min(92vw, 380px);
  margin: 0 auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.tile2048 {
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: clamp(1rem, 6vw, 1.6rem);
  background: var(--bg-soft);
  color: var(--text);
  transition: background 0.08s ease;
}
.t2 { background: #3a4166; } .t4 { background: #45508a; }
.t8 { background: #5468c4; } .t16 { background: #6c8cff; }
.t32 { background: #8a6cff; } .t64 { background: #b45cff; }
.t128 { background: #e05cd8; font-size: clamp(0.9rem, 5vw, 1.4rem); }
.t256 { background: #ff5d9e; font-size: clamp(0.9rem, 5vw, 1.4rem); }
.t512 { background: #ff6c5c; font-size: clamp(0.9rem, 5vw, 1.4rem); }
.t1024 { background: #ff9d3c; font-size: clamp(0.8rem, 4.5vw, 1.15rem); }
.t2048 { background: #ffcf5c; color: #201500; font-size: clamp(0.8rem, 4.5vw, 1.15rem); }
.tile-new { animation: pop 0.15s ease; }
@keyframes pop { from { transform: scale(0.5); } to { transform: scale(1); } }

/* ===== Emoji Memory Match ===== */
.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: min(92vw, 380px);
  margin: 0 auto;
}
.mcard {
  aspect-ratio: 1;
  perspective: 500px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.mcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.3s ease;
}
.mcard.flipped .mcard-inner { transform: rotateY(180deg); }
.mcard-face {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.4rem, 7vw, 2rem);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.mcard-back { background: var(--accent-soft); border: 1px solid var(--accent); }
.mcard-back::after { content: "?"; color: var(--accent); font-weight: 800; font-size: 1.4rem; }
.mcard-front { background: var(--card); border: 1px solid var(--border); transform: rotateY(180deg); }
.mcard.matched .mcard-front { background: #1d4a38; border-color: var(--green); }
.mcard.matched { cursor: default; }

/* ===== Classic Snake ===== */
#snakeCanvas {
  width: min(92vw, 380px);
  height: min(92vw, 380px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  touch-action: none;
  display: block;
  margin: 0 auto;
}
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 52px);
  gap: 6px;
  justify-content: center;
  margin-top: 14px;
}
.dpad button {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.dpad button:active { background: var(--accent); }
.dpad .up { grid-column: 2; grid-row: 1; }
.dpad .left { grid-column: 1; grid-row: 2; }
.dpad .down { grid-column: 2; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }

/* ===== Space Canyon ===== */
#canyonCanvas {
  width: min(92vw, 800px);
  aspect-ratio: 8 / 5;
  height: auto;
  background: #0a0d1c;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  touch-action: none;
  display: block;
  margin: 0 auto;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

/* ----- static pages ----- */
.page-body { max-width: 720px; }
.page-body h2 { color: var(--accent); }
.page-body ul, .page-body ol { padding-left: 22px; margin: 8px 0; }
.page-body li { margin: 4px 0; }

@media (max-width: 480px) {
  .hero h1 { font-size: 1.4rem; }
  .nav-links { gap: 12px; }
  .nav-links a { font-size: 0.85rem; }
}
