/* Shared Layout for Puzzle Collection - Full Screen Fix */
:root {
  --bg-primary: #f8f9fa;
  --bg-secondary: #f1f2f6;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --panel-bg: #ffffff;
  --border-color: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --game-accent: #3b82f6;
  --font-family: 'Outfit', sans-serif;
  --border-radius-lg: 16px;
  --border-radius-md: 12px;
}

[data-theme='dark'] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --panel-bg: #1e293b;
  --border-color: #334155;
}

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

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  position: fixed;
  /* iOS bounce 방지 */
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* Vite/React/Vue 등 app root 대응 */
#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.game-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center; /* Center content vertically */
  max-width: 500px;
  width: 100%;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px 8px;
  min-height: 0;
  /* 중요: flex 자식의 overflow 방지 */
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  flex-shrink: 0;
  position: relative;
  z-index: 1002; /* Higher than menu-backdrop (1000) */
}

.header-left {
  position: relative;
}

.game-title {
  font-size: 22px;
  font-weight: 800;
  text-transform: lowercase;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
}

.icon-btn:active {
  background: var(--bg-secondary);
}

.icon-btn svg {
  width: 24px;
  height: 24px;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.menu-dropdown {
  position: absolute;
  top: 50px;
  left: 0;
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 8px 0;
  z-index: 1001;
  min-width: 160px;
  max-height: min(72dvh, 420px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.menu-item {
  display: block;
  padding: 12px 20px;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 500;
  font-size: 14px;
}

.menu-dropdown .menu-button {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.stats-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 4px; /* Reduced from 8px */
  flex-shrink: 0;
}

.stat-card {
  flex: 1;
  background: var(--bg-secondary);
  padding: 6px 2px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.stat-card[data-action] {
  cursor: pointer;
}

.stat-label {
  font-size: 8px;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-weight: 700;
  margin-bottom: 1px;
}

.stat-value {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.stat-value svg {
  width: 16px;
  height: 16px;
}

.mode-selector {
  padding: 4px 4px;
}

.stat-select {
  width: 100%;
  max-width: 96px;
  border: 1px solid var(--border-color);
  background: var(--panel-bg);
  color: var(--text-primary);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  padding: 4px 6px;
  outline: none;
}

.stat-select:focus {
  border-color: var(--game-accent);
}

.game-surface {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px 0;
  min-height: 0;
  position: relative;
  width: 100%;
}

.controls-area {
  padding: 4px 0; /* Reduced from 8px 0 */
  flex-shrink: 0;
}

.action-bar {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 4px; /* Reduced from 8px */
}

.action-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px 2px;
  cursor: pointer;
  color: var(--text-primary);
}

.action-btn svg {
  width: 20px;
  height: 20px;
}

.action-label {
  font-size: 9px;
  font-weight: 600;
  color: var(--text-secondary);
}

.primary-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: var(--text-primary);
  color: var(--bg-primary);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: var(--panel-bg);
  width: 100%;
  max-width: 340px;
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

@media (max-height: 600px) {
  .game-header {
    padding: 4px 0;
  }

  .stats-bar {
    margin-bottom: 4px;
  }

  .controls-area {
    padding: 4px 0;
  }
}

@media (max-height: 720px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    position: static;
  }

  body {
    min-height: 100svh;
    touch-action: pan-y;
  }

  #app {
    height: auto;
    min-height: 100svh;
  }

  .game-container {
    flex: 0 0 auto;
    height: auto;
    min-height: 100svh;
    justify-content: flex-start;
    justify-content: safe center;
  }
}
