@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;700;900&display=swap');

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

html, body {
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  font-family: 'Noto Sans KR', sans-serif;
  background: #1a1a2e;
  color: #eee;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

img { -webkit-user-drag: none; user-select: none; pointer-events: none; }

.screen {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
}

/* Setup 화면: 콘텐츠가 길면 자연스럽게 스크롤되도록 위쪽부터 정렬 */
#setup.screen {
  justify-content: flex-start;
  padding-top: clamp(1.2rem, 5vh, 3rem);
  padding-bottom: clamp(1.2rem, 5vh, 3rem);
}

/* Game 화면은 board 가 정확한 높이를 잡으므로 viewport 고정 */
#game.screen {
  min-height: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Setup ── */
#setup h1 {
  font-size: 6rem;
  font-weight: 900;
  letter-spacing: 0.3em;
  margin-bottom: 3rem;
  background: linear-gradient(135deg, #e94560, #0f3460);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.setup-form {
  background: #16213e;
  border-radius: 28px;
  padding: 4rem;
  width: 100%;
  max-width: 820px;
}

.field-row {
  display: flex;
  gap: 2.5rem;
}
.field-row > * { flex: 1; }

.field { margin-bottom: 2.5rem; }

.field label {
  display: block;
  font-weight: 700;
  margin-bottom: 1rem;
  font-size: 1.7rem;
}

.hint {
  font-size: 1.2rem;
  color: #888;
  margin-top: 0.6rem;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.stepper button {
  width: 78px;
  height: 78px;
  border: 3px solid #e94560;
  border-radius: 14px;
  background: transparent;
  color: #e94560;
  font-size: 2.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

.stepper button:hover {
  background: rgba(233, 69, 96, 0.15);
}

.stepper span {
  font-size: 2.6rem;
  font-weight: 900;
  min-width: 4rem;
  text-align: center;
}

.toggle-btn-group {
  display: flex;
  gap: 0.8rem;
}

.toggle-btn {
  flex: 1;
  padding: 1.2rem 1.4rem;
  border: 3px solid #444;
  border-radius: 14px;
  background: transparent;
  color: #aaa;
  font-family: inherit;
  font-size: 1.6rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-btn.active {
  border-color: #e94560;
  background: rgba(233, 69, 96, 0.2);
  color: #e94560;
}

hr {
  border: none;
  border-top: 2px solid #2a2a4a;
  margin: 2.5rem 0;
}

.mode-select {
  display: flex;
  gap: 1rem;
  margin-bottom: 2.5rem;
  flex-direction: row;
}

.mode-btn {
  flex: 1;
  padding: 1.6rem;
  border: 3px solid #555;
  border-radius: 16px;
  background: transparent;
  color: #aaa;
  font-family: inherit;
  font-size: 1.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn.active.solo {
  border-color: #0f3460;
  background: rgba(15, 52, 96, 0.3);
  color: #4fc3f7;
}

.mode-btn.active.vs {
  border-color: #e94560;
  background: rgba(233, 69, 96, 0.2);
  color: #e94560;
}

.start-btn {
  width: 100%;
  padding: 2rem;
  border: none;
  border-radius: 18px;
  background: #e94560;
  color: #fff;
  font-family: inherit;
  font-size: 2rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
  margin-top: 1rem;
  min-height: 100px;
}

.start-btn:hover { opacity: 0.85; }

.start-btn.secondary {
  background: #2a2a4a;
  margin-top: 1.2rem;
}

/* ── Top Bar ── */
.top-bar {
  width: 100%;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  flex-shrink: 0;
}

.top-actions {
  display: flex;
  gap: 0.8rem;
  flex-shrink: 0;
}

.icon-btn {
  width: 78px;
  height: 78px;
  border: 3px solid #444;
  border-radius: 14px;
  background: transparent;
  color: #aaa;
  font-size: 2.2rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  border-color: #e94560;
  color: #e94560;
  background: rgba(233, 69, 96, 0.1);
}

.go-btn {
  padding: 0.8rem 2.2rem;
  border: 3px solid #e94560;
  border-radius: 14px;
  background: #e94560;
  color: #fff;
  font-family: inherit;
  font-size: 1.6rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.1em;
  transition: opacity 0.15s;
  min-height: 78px;
}

.go-btn:hover { opacity: 0.85; }
.go-btn.hidden { display: none; }

/* ── HUD ── */
.hud {
  display: flex;
  justify-content: center;
  gap: 1.2rem;
  flex-wrap: wrap;
  flex: 1;
}

.hud-item {
  background: #16213e;
  border-radius: 16px;
  padding: 1rem 1.6rem;
  text-align: center;
  min-width: 140px;
  border: 3px solid transparent;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.hud-item.active {
  border-color: #e94560;
  box-shadow: 0 0 22px rgba(233, 69, 96, 0.35);
}

.hud-item .label {
  font-size: 1.1rem;
  color: #888;
}

.hud-item .value {
  font-size: 2rem;
  font-weight: 900;
}

/* ── Game screen layout ── */
#game {
  justify-content: flex-start;
  padding: 0;
}

/* ── Board ── */
.board {
  display: grid;
  gap: 12px;
  padding: 1rem 2rem 2rem;
  width: 100%;
  height: calc(100vh - 120px);
  height: calc(100dvh - 120px);
  overflow: hidden;
}

/* ── Card ── */
.card {
  perspective: 800px;
  cursor: pointer;
  min-height: 0;
}

.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.4s;
  border-radius: 18px;
}

.card.flipped .card-inner,
.card.matched .card-inner {
  transform: rotateY(180deg);
}

.card.matched { pointer-events: none; }

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
}

.card-back {
  background: #fff;
  border: 3px solid #ddd;
  background-image: var(--card-back-image, url('images/sdg-back.png'));
  background-size: 70%;
  background-position: center;
  background-repeat: no-repeat;
}

.card-front {
  background: #fff;
  transform: rotateY(180deg);
  border: 3px solid #ddd;
  overflow: hidden;
}

.card-front img {
  width: 85%;
  height: 85%;
  object-fit: contain;
}

.card.matched .card-front { opacity: 0.5; }

.card.match-anim .card-inner {
  animation: matchPop 0.4s ease;
}
@keyframes matchPop {
  0%   { transform: rotateY(180deg) scale(1); }
  50%  { transform: rotateY(180deg) scale(1.1); }
  100% { transform: rotateY(180deg) scale(1); }
}

/* ── Result (overlay) ── */
#result {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
  backdrop-filter: blur(4px);
}

#result-content {
  background: #16213e;
  border-radius: 28px;
  padding: 4rem;
  text-align: center;
  max-width: 720px;
  width: 100%;
}

.result-actions {
  display: flex;
  gap: 1.2rem;
  margin-top: 2.5rem;
}

.result-btn {
  flex: 1;
  padding: 1.5rem;
  border: none;
  border-radius: 14px;
  background: #e94560;
  color: #fff;
  font-family: inherit;
  font-size: 1.7rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
  min-height: 90px;
}
.result-btn:hover { opacity: 0.85; }
.result-btn.secondary { background: #2a2a4a; }

#result-content h2 {
  font-size: 3.6rem;
  margin-bottom: 1.6rem;
}

#result-content .stats {
  font-size: 1.8rem;
  line-height: 2;
}

#result-content .winner {
  font-size: 2.4rem;
  font-weight: 900;
  color: #e94560;
  margin-top: 1.6rem;
}

.player-scores { margin-top: 1.6rem; }

.player-scores .row {
  display: flex;
  justify-content: space-between;
  padding: 0.8rem 0;
  border-bottom: 2px solid #2a2a4a;
  font-size: 1.8rem;
}

.player-scores .row.winner-row {
  color: #e94560;
  font-weight: 700;
}

/* ── Responsive: tablet ── */
@media (max-width: 1024px) {
  .screen { padding: 1.8rem; }
  #setup h1 { font-size: 4.4rem; margin-bottom: 2rem; letter-spacing: 0.2em; }
  .setup-form { padding: 2.4rem; border-radius: 22px; }
  .field-row { gap: 1.6rem; }
  .field { margin-bottom: 1.8rem; }
  .field label { font-size: 1.35rem; margin-bottom: 0.7rem; }
  .hint { font-size: 1.05rem; }
  .stepper { gap: 1rem; }
  .stepper button { width: 62px; height: 62px; font-size: 1.8rem; border-width: 2px; border-radius: 12px; }
  .stepper span { font-size: 2.1rem; min-width: 3rem; }
  .toggle-btn { padding: 1rem 1.1rem; font-size: 1.3rem; border-width: 2px; border-radius: 12px; }
  hr { margin: 1.8rem 0; }
  .mode-select { gap: 0.9rem; margin-bottom: 1.8rem; }
  .mode-btn { padding: 1.3rem; font-size: 1.55rem; border-width: 2px; border-radius: 14px; }
  .start-btn { padding: 1.5rem; font-size: 1.6rem; min-height: 78px; border-radius: 16px; }

  .top-bar { height: 92px; padding: 0.8rem 1.2rem; }
  .top-actions { gap: 0.6rem; }
  .icon-btn { width: 60px; height: 60px; font-size: 1.7rem; border-width: 2px; border-radius: 12px; }
  .go-btn { padding: 0.6rem 1.6rem; font-size: 1.3rem; min-height: 60px; border-width: 2px; border-radius: 12px; }
  .hud { gap: 0.8rem; }
  .hud-item { padding: 0.7rem 1.1rem; min-width: 108px; border-width: 2px; border-radius: 12px; }
  .hud-item .label { font-size: 0.95rem; }
  .hud-item .value { font-size: 1.55rem; }

  .board { padding: 0.8rem 1.2rem 1.2rem; gap: 10px; height: calc(100dvh - 92px); }
  .card-inner, .card-face { border-radius: 14px; }

  #result-content { padding: 2.4rem; border-radius: 22px; }
  #result-content h2 { font-size: 2.6rem; margin-bottom: 1.2rem; }
  #result-content .stats { font-size: 1.4rem; line-height: 1.9; }
  #result-content .winner { font-size: 1.9rem; }
  .result-actions { margin-top: 1.8rem; gap: 0.9rem; }
  .result-btn { padding: 1.1rem; font-size: 1.35rem; min-height: 68px; border-radius: 12px; }
  .player-scores .row { font-size: 1.4rem; padding: 0.6rem 0; }
}

/* ── Responsive: mobile ── */
@media (max-width: 640px) {
  .screen { padding: 1rem; }
  #setup h1 { font-size: 2.6rem; margin-bottom: 1.4rem; letter-spacing: 0.15em; }
  .setup-form { padding: 1.4rem; border-radius: 16px; }
  .field-row { flex-direction: column; gap: 1rem; }
  .field { margin-bottom: 1.1rem; }
  .field label { font-size: 1.05rem; margin-bottom: 0.5rem; }
  .hint { font-size: 0.85rem; margin-top: 0.35rem; }
  .stepper { gap: 0.7rem; }
  .stepper button { width: 44px; height: 44px; font-size: 1.3rem; border-width: 2px; border-radius: 10px; }
  .stepper span { font-size: 1.5rem; min-width: 2.4rem; }
  .toggle-btn { padding: 0.7rem 0.6rem; font-size: 0.95rem; border-width: 2px; border-radius: 10px; }
  hr { margin: 1.1rem 0; border-top-width: 1px; }
  .mode-select { gap: 0.6rem; margin-bottom: 1.2rem; }
  .mode-btn { padding: 0.9rem; font-size: 1.15rem; border-width: 2px; border-radius: 12px; }
  .start-btn { padding: 1rem; font-size: 1.2rem; min-height: 56px; border-radius: 12px; margin-top: 0.6rem; }

  .top-bar { height: 64px; padding: 0.4rem 0.6rem; }
  .top-actions { gap: 0.35rem; }
  .icon-btn { width: 44px; height: 44px; font-size: 1.2rem; border-width: 2px; border-radius: 10px; }
  .go-btn { padding: 0.4rem 1rem; font-size: 0.95rem; min-height: 44px; border-width: 2px; border-radius: 10px; }
  .hud { gap: 0.3rem; flex-wrap: wrap; }
  .hud-item { padding: 0.3rem 0.55rem; min-width: 62px; border-width: 2px; border-radius: 8px; }
  .hud-item .label { font-size: 0.65rem; }
  .hud-item .value { font-size: 1rem; }

  .board { padding: 0.5rem; gap: 6px; height: calc(100dvh - 64px); }
  .card-inner, .card-face { border-radius: 10px; }
  .card-back { background-size: 55%; }
  .card-front img { width: 90%; height: 90%; }

  #result-content { padding: 1.6rem 1.3rem; border-radius: 18px; max-width: 92vw; }
  #result-content h2 { font-size: 1.9rem; margin-bottom: 0.9rem; }
  #result-content .stats { font-size: 1.1rem; line-height: 1.7; }
  #result-content .winner { font-size: 1.4rem; margin-top: 0.9rem; }
  .result-actions { flex-direction: column; gap: 0.6rem; margin-top: 1.4rem; }
  .result-btn { padding: 0.85rem; font-size: 1.05rem; min-height: 50px; border-radius: 10px; }
  .player-scores .row { font-size: 1.05rem; padding: 0.45rem 0; }
}

/* ── Landscape phones: shrink heading further to keep form visible ── */
@media (max-height: 480px) and (orientation: landscape) {
  .screen { padding: 0.6rem; justify-content: flex-start; overflow-y: auto; }
  #setup h1 { font-size: 1.8rem; margin-bottom: 0.6rem; }
  .setup-form { padding: 0.9rem 1.2rem; }
  .field { margin-bottom: 0.7rem; }
  hr { margin: 0.7rem 0; }
  .mode-select { flex-direction: row; margin-bottom: 0.8rem; }
}
