/* ===== CSS Variables ===== */
:root {
  /* Light Theme */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-accent: #e2e8f0;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-accent: #0f172a;
  --border-color: #e2e8f0;
  --shadow: rgba(0, 0, 0, 0.1);
  
  /* Colors */
  --primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --secondary: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  --success: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  --warning: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
  --danger: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
  --info: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
  
  /* Game Colors */
  --cell-white: #ffffff;
  --cell-black: #2d3748;
  --cell-selected: #667eea;
  --cell-completed: #4facfe;
  --cell-hover: #f1f5f9;
  --cell-error: #fc8181;
  
  /* Panel Colors */
  --panel-bg: #1a202c;
  --panel-text: #ffffff;
  
  /* Animation */
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Dark Theme */
[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-accent: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-accent: #ffffff;
  --border-color: #475569;
  --shadow: rgba(0, 0, 0, 0.5);
  --cell-white: #334155;
  --cell-black: #0f172a;
  --cell-hover: #475569;
  --panel-bg: #0f172a;
}

/* ===== Reset & Base ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Poppins', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
  transition: var(--transition);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ===== Header ===== */
.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  box-shadow: 0 2px 10px var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo i {
  font-size: 2rem;
  background: var(--primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo h1 {
  font-size: 1.8rem;
  font-weight: 700;
  background: var(--primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-controls {
  display: flex;
  gap: 0.5rem;
}

/* ===== Main Container ===== */
.main-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: auto;
}

/* ===== Screens ===== */
.screen {
  display: none;
  flex: 1;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* ===== Start Screen ===== */
.start-screen {
  justify-content: center;
  align-items: center;
  padding: 2rem;
}

.welcome-container {
  width: 100%;
  max-width: 800px;
}

.welcome-card {
  background: var(--bg-secondary);
  border-radius: 20px;
  padding: 3rem;
  box-shadow: 0 20px 60px var(--shadow);
  border: 1px solid var(--border-color);
  text-align: center;
}

.welcome-card h2 {
  font-size: 2.2rem;
  margin-bottom: 1rem;
  background: var(--primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-card p {
  color: var(--text-secondary);
  margin-bottom: 3rem;
  font-size: 1.1rem;
}

/* ===== Settings ===== */
.settings-container {
  margin-bottom: 3rem;
}

.settings-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-bottom: 1.5rem;
}

.setting-group {
  text-align: left;
}

.setting-group.full-width {
  grid-column: 1 / -1;
}

.setting-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: var(--text-accent);
}

.select-modern, .input-select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border-color);
  border-radius: 12px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  transition: var(--transition);
}

.select-modern:focus, .input-select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.difficulty-slider {
  position: relative;
}

.slider {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: var(--bg-accent);
  outline: none;
  -webkit-appearance: none;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: none;
}

.slider-value {
  position: absolute;
  top: -35px;
  right: 0;
  background: var(--primary);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
}

.word-db-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.word-count {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* ===== Buttons ===== */
.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 12px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  font-size: 0.95rem;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6);
}

.btn-secondary {
  background: var(--bg-accent);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--border-color);
  transform: translateY(-1px);
}

.btn-large {
  padding: 1.2rem 2.5rem;
  font-size: 1.1rem;
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-accent);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--primary);
  color: white;
  transform: scale(1.1);
}

.button-group {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* ===== Start Screen Controls ===== */
.start-screen-controls {
  display: flex;
  flex-direction: row;
  gap: 1rem;
  justify-content: center;
  align-items: center;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
  flex-wrap: nowrap;
}

/* ===== Game Screen ===== */
.game-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0; /* Added for correct flexbox behavior */
}

.game-content {
  flex: 1;
  display: grid;
  justify-content: center;
  grid-template-columns: max-content 380px;
  gap: 1.5rem;
  padding: 1.5rem;
  overflow: hidden;
  min-height: 0;
}

/* ===== Grid Section ===== */
.grid-section {
  display: flex;
  justify-content: center;
  /* align-items: center; removed */
  padding: 0.5rem;
  min-height: 0; /* Changed from fit-content */
  min-width: 0; /* Added for flexbox shrinking */
  height: 100%;
}

.grid-container {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 8px 30px var(--shadow);
  border: 2px solid var(--border-color);
  display: flex; /* Changed from inline-flex */
  /* justify-content: center; Removed to fix scrolling issue on mobile */
  /* align-items: center; Removed to fix scrolling issue */
  overflow: auto; /* Added for scrolling large grids */
  height: 100%; /* Added to constrain height */
}

.crossword-grid {
  display: grid;
  gap: 2px; /* Increased gap */
  border: 2px solid var(--text-primary);
  /* Let the container handle max-width/height */
}

.crossword-cell {
  --cell-size: clamp(20px, min(4.5vh, 4.5vw), 40px);
  width: var(--cell-size);
  aspect-ratio: 1 / 1;
  position: relative;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: calc(var(--cell-size) * 0.5); /* Dynamic font size */
  transition: var(--transition);
  cursor: pointer;
}

.crossword-cell.white {
  background: var(--cell-white);
  color: var(--text-primary);
}

.crossword-cell.black {
  background: var(--cell-black);
  cursor: default;
}

.crossword-cell.completed {
  background: var(--cell-completed);
  color: white;
  animation: cellComplete 0.6s var(--bounce);
}

.crossword-cell.error {
  background: var(--cell-error);
  color: white;
  animation: cellError 0.3s ease-out;
}

.crossword-cell.highlighted {
  background: #e3f2fd;
  box-shadow: 0 0 0 2px #2196f3;
}

.cell-number {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: calc(var(--cell-size) * 0.3); /* Dynamic font size */
  font-weight: 700;
  color: var(--text-primary);
  z-index: 2;
  pointer-events: none;
}

/* ===== Clues Section ===== */
.clues-section {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 8px 30px var(--shadow);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  min-height: 0; /* flexbox에서 overflow 작동을 위해 */
  max-height: 100%;
  width: 380px; /* Fixed width for this section */
  flex-shrink: 0; /* Prevent shrinking */
}

.clues-container {
  display: flex;
  flex-direction: column;
  flex: 1; /* Make clues-container also fill vertical space */
  min-height: 0; /* Allow it to shrink */
}

.clues-container h3 {
  margin-bottom: 1rem;
  color: var(--text-accent);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0; /* Prevent title from shrinking */
}

.clues-tabs {
  display: flex;
  margin-bottom: 1rem;
  background: var(--bg-accent);
  border-radius: 8px;
  padding: 4px;
  flex-shrink: 0; /* Prevent tabs from shrinking */
}

.clue-tab {
  flex: 1;
  padding: 0.5rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  transition: var(--transition);
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}

.clue-tab.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.clues-content {
  flex: 1;
  overflow-y: auto;
}

.clues-list {
  display: none;
}

.clues-list.active {
  display: block;
}

.clue-item {
  background: var(--bg-accent);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  transition: var(--transition);
  cursor: pointer;
  border-left: 4px solid transparent;
}

.clue-item:hover {
  background: var(--cell-hover);
  transform: translateX(3px);
}

.clue-item.completed {
  background: var(--success);
  color: white;
  border-left-color: #00f2fe;
}

.clue-item.selected,
.clue-item.active {
  background: var(--primary);
  color: white;
  border-left-color: #667eea;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
  transform: translateX(5px);
}

.clue-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.clue-number {
  font-weight: 700;
  color: var(--text-accent);
  min-width: 30px;
}

.clue-item.completed .clue-number,
.clue-item.selected .clue-number {
  color: white;
}

.clue-length {
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--bg-primary);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}

.clue-item.completed .clue-length,
.clue-item.selected .clue-length {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.clue-hints {
  font-size: 0.9rem;
  line-height: 1.4;
}

.clue-hint {
  margin-bottom: 0.25rem;
}

.clue-hint:last-child {
  margin-bottom: 0;
}

/* ===== Bottom Input Panel - Compact Single Line ===== */
.input-panel {
  background: var(--panel-bg);
  color: var(--panel-text);
  padding: 0.5rem 1.5rem; /* Reduced vertical padding */
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1rem; /* Reduced gap */
  align-items: center;
  box-shadow: 0 -4px 20px var(--shadow);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 50;
  min-height: 50px; /* Reduced min-height */
  margin-bottom: 0;
}

.panel-left, .panel-right {
  display: flex;
  align-items: center;
  gap: 0.75rem; /* Reduced gap */
  white-space: nowrap;
}

.panel-center {
  flex: 1;
  min-width: 0; /* 플렉스 아이템이 축소될 수 있도록 */
}

.timer-section {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.timer {
  font-size: 1.2rem; /* Reduced font size */
  font-weight: 700;
  color: #4ade80;
  min-width: 70px; /* Reduced min-width */
}

.timer.warning {
  color: #fbbf24;
  animation: pulse 1s infinite;
}

.timer.danger {
  color: #ef4444;
  animation: pulse 0.5s infinite;
}

/* Compact Input Controls - Single Line */
.input-controls-compact {
  display: flex;
  gap: 0.5rem; /* Reduced gap */
  align-items: center;
  width: 100%;
  position: relative;
}

.input-select-compact {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 0.4rem 0.6rem; /* Reduced padding */
  border-radius: 6px;
  font-size: 0.85rem; /* Reduced font size */
  font-weight: 500;
  min-width: 70px; /* Reduced min-width */
  cursor: pointer;
  transition: var(--transition);
}

.input-select-compact:hover {
  border-color: var(--cell-selected);
}

.input-select-compact:focus {
  outline: none;
  border-color: var(--cell-selected);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* 현재 힌트 표시 영역 */
.current-hint-display {
  flex: 1;
  background: rgba(102, 126, 234, 0.1);
  border: 1px solid rgba(102, 126, 234, 0.3);
  border-radius: 6px;
  padding: 0.4rem 0.8rem; /* Reduced padding */
  min-width: 150px; /* Reduced min-width */
  max-width: 400px;
  overflow: hidden;
}

.current-hint-display .hint-text {
  font-size: 0.8rem; /* Reduced font size */
  color: var(--panel-text);
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.word-input-compact {
  padding: 0.4rem 0.8rem; /* Reduced padding */
  border: 2px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem; /* Reduced font size */
  font-weight: 500;
  min-width: 120px; /* Reduced min-width */
  max-width: 180px;
  transition: var(--transition);
  text-transform: uppercase;
}

.word-input:focus,
.word-input-compact:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.btn-compact {
  padding: 0.4rem 0.8rem !important; /* Reduced padding */
  min-width: auto !important;
  font-size: 0.8rem; /* Reduced font size */
  height: auto;
}

.autocomplete-suggestions {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 -4px 20px var(--shadow);
  max-height: 150px;
  overflow-y: auto;
  z-index: 10;
  display: none;
}

.autocomplete-item {
  padding: 0.75rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  transition: var(--transition);
}

.autocomplete-item:hover {
  background: var(--cell-hover);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.score-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem; /* Reduced gap */
}

.score {
  font-size: 1.5rem; /* Reduced font size */
  font-weight: 700;
  color: #fbbf24;
}

.progress-info {
  font-size: 0.8rem; /* Reduced font size */
  color: var(--panel-text);
  opacity: 0.8;
}

/* ===== High Score Screen ===== */
.high-score-screen {
  justify-content: flex-start;
  align-items: center;
  padding: 2rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.score-container {
  width: 100%;
  max-width: 600px;
  margin: auto 0;
}

.score-card {
  background: var(--bg-secondary);
  border-radius: 20px;
  padding: 3rem;
  box-shadow: 0 20px 60px var(--shadow);
  border: 1px solid var(--border-color);
}

.score-card h2 {
  text-align: center;
  margin-bottom: 2rem;
  color: var(--text-accent);
  font-size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.score-filters {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.filter-btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-color);
  background: var(--bg-accent);
  color: var(--text-primary);
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
}

.filter-btn.active {
  background: var(--primary);
  color: white;
  border-color: transparent;
}

.score-list {
  margin-bottom: 2rem;
  max-height: 400px;
  overflow-y: auto;
}

.score-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: var(--bg-accent);
  margin-bottom: 0.5rem;
  border-radius: 10px;
  transition: var(--transition);
}

.score-item:hover {
  transform: translateX(5px);
}

.score-rank {
  font-weight: 700;
  color: var(--text-accent);
  font-size: 1.2rem;
  min-width: 40px;
}

.score-details {
  flex: 1;
  margin-left: 1rem;
}

.score-name {
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.score-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.score-value {
  font-weight: 700;
  color: #667eea;
  font-size: 1.1rem;
}

/* ===== Game Over Screen ===== */
.game-over-screen {
  justify-content: flex-start;
  align-items: center;
  padding: 2rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.game-over-container {
  width: 100%;
  max-width: 500px;
  margin: auto 0;
}

.game-over-card {
  background: var(--bg-secondary);
  border-radius: 20px;
  padding: 3rem;
  box-shadow: 0 20px 60px var(--shadow);
  border: 1px solid var(--border-color);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.game-over-info {
  flex: 0 1 auto;
}

.game-over-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  align-items: center;
  padding: 1rem 0;
  flex-wrap: wrap;
}

/* Slide-in animations */
.slide-in-left,
.slide-in-right {
  opacity: 0;
  transition: all 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.slide-in-left {
  transform: translateX(-100px);
}

.slide-in-right {
  transform: translateX(100px);
}

.slide-in-left.visible,
.slide-in-right.visible {
  opacity: 1;
  transform: translateX(0);
}

/* ===== Modals ===== */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  backdrop-filter: blur(5px);
}

.modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--bg-secondary);
  padding: 2rem;
  border-radius: 20px;
  max-width: 500px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 60px var(--shadow);
  transform: scale(0.8);
  opacity: 0;
  transition: var(--transition);
}

.modal.active .modal-content {
  transform: scale(1);
  opacity: 1;
}

.modal-content h3 {
  margin-bottom: 1rem;
  color: var(--text-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.modal-content input {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-primary);
  color: var(--text-primary);
  margin: 1rem 0;
  font-family: inherit;
  font-size: 1rem;
}

.modal-content input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.modal-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 1.5rem;
}

.help-content {
  text-align: left;
  margin: 1.5rem 0;
}

.help-section {
  margin-bottom: 1.5rem;
}

.help-section h4 {
  margin-bottom: 0.5rem;
  color: var(--text-accent);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.help-section p {
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

/* Update Progress Modal */
.update-progress {
  margin: 1.5rem 0;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-accent);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 1rem;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s ease;
  width: 0%;
}

/* ===== Celebration Canvas ===== */
#celebrationCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
  display: none;
}

/* ===== Animations ===== */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes cellComplete {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

@keyframes cellError {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

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

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ===== Responsive Design ===== */
@media (max-width: 1024px) {
  .game-screen {
    height: calc(100vh - 60px); /* 모바일에서 헤더 높이 조정 */
  }

  .game-over-screen,
  .high-score-screen,
  .start-screen {
    height: auto;
    min-height: calc(100vh - 60px);
  }
  
  .game-content {
    grid-template-columns: 1fr;
    gap: 1rem;
    padding: 1rem;
  }
  
  .clues-section {
    order: -1;
    max-height: 40vh; /* 힌트 영역의 최대 높이 제한 */
    overflow-y: auto;
  }
  
  .grid-section {
    flex: 1;
    min-height: 0;
  }
  
  .input-panel {
    grid-template-columns: 1fr;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    min-height: auto;
    max-height: none;
  }

  .panel-left, .panel-right {
    justify-content: center;
  }

  .input-controls-compact {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .input-select-compact {
    flex: 1 1 45%;
    min-width: 100px;
  }

  .current-hint-display {
    flex: 1 1 100%;
    order: -1;
  }

  .word-input-compact {
    flex: 1 1 60%;
    min-width: 120px;
  }

  .btn-compact {
    flex: 0 0 auto;
  }
  
  .panel-left, .panel-right {
    justify-content: center;
  }
}

@media (max-width: 768px) {
  .game-screen {
    height: calc(100vh - 60px);
  }

  .game-over-screen,
  .high-score-screen,
  .start-screen {
    height: auto;
    min-height: calc(100vh - 60px);
  }

  .header .container {
    padding: 0.75rem 1rem;
  }

  .logo h1 {
    font-size: 1.5rem;
  }

  .start-screen {
    padding: 1rem;
  }

  .welcome-card {
    padding: 1.5rem;
  }

  .start-screen-controls {
    margin-top: 1rem;
    padding-top: 1rem;
    gap: 0.75rem;
    flex-direction: row;
    flex-wrap: nowrap;
  }

  .welcome-card h2 {
    font-size: 1.8rem;
  }

  .settings-container {
    margin-bottom: 1.5rem;
  }

  .settings-row {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
  }

  .setting-group label {
    margin-bottom: 0.3rem;
    font-size: 0.85rem;
  }

  .select-modern {
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
  }

  .difficulty-slider .slider {
    height: 6px;
  }

  .slider-value {
    font-size: 0.8rem;
    padding: 0.2rem 0.5rem;
    top: -30px;
  }

  .word-db-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .word-db-controls button {
    font-size: 0.85rem;
    padding: 0.5rem 0.75rem;
  }

  .word-count {
    font-size: 0.8rem;
    text-align: center;
  }

  .button-group {
    gap: 0.75rem;
  }

  .btn-large {
    padding: 0.75rem 1.5rem;
    font-size: 0.95rem;
  }

  .btn {
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
  }

  .game-over-screen,
  .high-score-screen {
    padding: 1rem;
    justify-content: flex-start;
  }

  .game-over-card,
  .score-card {
    padding: 1.5rem;
    margin-top: 1rem;
    margin-bottom: 1rem;
  }

  .game-over-actions {
    flex-direction: row;
    gap: 0.75rem;
  }

  .game-over-actions .btn {
    flex: 1;
    min-width: 120px;
  }

  .crossword-cell {
    width: 30px;
    height: 30px;
    font-size: 12px;
  }
  
  .clues-section {
    max-height: 45vh; /* Increased height for clues section on mobile */
    padding: 1rem; /* Adjust padding for better space utilization */
  }
  
  .input-panel {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
    min-height: auto; /* Allow height to shrink */
    display: flex; /* Force single row */
    flex-wrap: nowrap;
    justify-content: space-between;
    overflow-x: auto; /* Allow input panel itself to scroll horizontally if needed */
  }

  .panel-left, .panel-right {
    flex-shrink: 0; /* Prevent these from shrinking too much */
    gap: 0.5rem;
  }
  .panel-center {
    flex: 1; /* Allow input controls to take available space */
    overflow-x: auto; /* Allow controls to scroll if too wide */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling for iOS */
    min-width: 0; /* Important for flex items with overflow */
  }

  .input-controls-compact {
    flex-wrap: nowrap; /* Prevent wrapping */
    gap: 0.5rem;
    /* width: 100%; No need for this, flex will handle it */
  }

  .input-select-compact {
    padding: 0.4rem 0.6rem; /* Smaller padding */
    font-size: 0.8rem; /* Smaller font */
    min-width: 60px; /* Adjust min-width */
  }
  
  .current-hint-display {
    padding: 0.4rem 0.8rem; /* Smaller padding */
    font-size: 0.7rem; /* Smaller font */
    min-width: 120px; /* Adjust min-width */
    flex-shrink: 0; /* Prevent shrinking below min-width */
  }
  
  .word-input-compact {
    padding: 0.4rem 0.8rem; /* Smaller padding */
    font-size: 0.8rem; /* Smaller font */
    min-width: 100px; /* Adjust min-width */
    flex-shrink: 0; /* Prevent shrinking below min-width */
  }

  .btn-compact {
    padding: 0.4rem 0.8rem !important; /* Smaller padding */
    font-size: 0.8rem !important; /* Smaller font */
    flex-shrink: 0;
  }
  
  .timer {
    font-size: 1.2rem;
    min-width: 60px;
  }

  .score {
    font-size: 1.2rem;
  }

  .button-group {
    flex-direction: column;
  }
  
  .btn-large {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .game-screen {
    height: calc(100vh - 50px);
  }

  .game-over-screen,
  .high-score-screen,
  .start-screen {
    height: auto;
    min-height: calc(100vh - 50px);
  }

  .game-content {
    padding: 0.5rem;
    gap: 0.5rem;
  }

  .start-screen {
    padding: 0.5rem;
  }

  .welcome-card {
    padding: 1rem;
  }

  .start-screen-controls {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    gap: 0.5rem;
    flex-direction: row;
    flex-wrap: nowrap;
  }

  .start-screen-controls .btn-icon {
    width: 44px;
    height: 44px;
    font-size: 1rem;
  }

  .settings-container {
    margin-bottom: 1rem;
  }

  .settings-row {
    gap: 0.5rem;
    margin-bottom: 0.5rem;
  }

  .setting-group label {
    margin-bottom: 0.25rem;
    font-size: 0.8rem;
  }

  .select-modern {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
  }

  .slider-value {
    font-size: 0.75rem;
  }

  .word-db-controls button {
    font-size: 0.8rem;
    padding: 0.4rem 0.6rem;
  }

  .word-count {
    font-size: 0.75rem;
  }

  .button-group {
    gap: 0.5rem;
  }

  .btn-large {
    padding: 0.65rem 1.2rem;
    font-size: 0.9rem;
  }

  .btn {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
  }

  .game-over-screen,
  .high-score-screen {
    padding: 0.5rem;
    justify-content: flex-start;
  }

  .game-over-card,
  .score-card {
    padding: 1rem;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
  }

  .game-over-actions {
    flex-direction: column;
    gap: 0.5rem;
  }

  .game-over-actions .btn {
    width: 100%;
  }

  .crossword-cell {
    width: 25px;
    height: 25px;
    font-size: 11px;
  }
  
  .cell-number {
    font-size: 8px;
  }
  
  .clues-section {
    max-height: 40vh; /* Increased for very small screens */
    padding: 0.75rem;
  }
  
  .grid-container {
    padding: 0.75rem;
  }
  
  .input-panel {
    padding: 0.25rem 0.5rem; /* Even smaller padding */
    gap: 0.25rem;
  }
  
  .timer {
    font-size: 1rem;
  }
  
  .score {
    font-size: 1.2rem;
  }
}
/* ===== Toast Notifications ===== */
#toastContainer {
    position: fixed;
    bottom: 80px; /* Above the input panel */
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

.toast {
    background: var(--panel-bg);
    color: var(--panel-text);
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 20px var(--shadow);
    border-left: 5px solid var(--cell-selected);
    opacity: 0;
    transform: translateX(100%);
    animation: slideInRight 0.5s var(--bounce) forwards, fadeOut 0.5s 2.5s forwards;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.error {
    border-left-color: var(--cell-error);
}

.toast.success {
    border-left-color: #4ade80;
}

@keyframes slideInRight {
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
        transform: scale(0.9);
    }
}
