/* ===== DESIGN TOKENS ===== */
:root {
  /* Colours */
  --bg-primary: #0a0f1e;
  --bg-secondary: #111827;
  --bg-card: #1a2235;
  --bg-elevated: #1f2a40;
  --bg-hover: #253250;

  --accent-blue: #4f8ff7;
  --accent-blue-glow: rgba(79, 143, 247, 0.3);
  --accent-gold: #f5c542;
  --accent-gold-glow: rgba(245, 197, 66, 0.25);
  --accent-green: #34d399;
  --accent-red: #f87171;
  --accent-red-glow: rgba(248, 113, 113, 0.3);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --border: rgba(148, 163, 184, 0.1);
  --border-light: rgba(148, 163, 184, 0.06);

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Spacing */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== RESET & BASE ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  background-image:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(79, 143, 247, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(245, 197, 66, 0.04) 0%, transparent 50%);
}

/* ===== VIEWS ===== */
.view {
  display: none;
  min-height: 100vh;
  animation: fadeIn 0.3s var(--ease);
}

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

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

/* ===== BUTTONS ===== */
.btn {
  font-family: var(--font);
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.9rem;
  -webkit-user-select: none;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-blue), #3b6fd4);
  color: white;
  padding: 12px 28px;
  box-shadow: 0 4px 20px var(--accent-blue-glow);
}

.btn-primary:hover {
  box-shadow: 0 6px 30px var(--accent-blue-glow);
  transform: translateY(-1px);
}

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

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

.btn-large {
  padding: 16px 40px;
  font-size: 1.1rem;
  border-radius: var(--radius-lg);
}

.btn-icon-only {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.2rem;
  border: 1px solid var(--border);
}

.btn-icon-only:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-hint-action {
  background: var(--bg-elevated);
  color: var(--accent-gold);
  padding: 8px 16px;
  border: 1px solid rgba(245, 197, 66, 0.2);
  font-size: 0.85rem;
}

.btn-hint-action:hover:not(:disabled) {
  background: rgba(245, 197, 66, 0.1);
}

.btn-hint-action:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-resume {
  background: var(--accent-blue);
  color: white;
  padding: 6px 16px;
  font-size: 0.8rem;
}

.btn-delete {
  background: transparent;
  color: var(--text-muted);
  padding: 6px 10px;
  font-size: 0.8rem;
}

.btn-delete:hover {
  color: var(--accent-red);
  background: var(--accent-red-glow);
}

/* ===== HOME VIEW ===== */
.home-header {
  padding: 40px 24px 20px;
  text-align: center;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 16px;
}

.logo-icon {
  font-size: 3rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
}

.logo h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: left;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 400;
  text-align: left;
}

.home-main {
  flex: 1;
  padding: 24px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
}

.btn-icon {
  font-size: 0.8em;
}

/* ===== HISTORY ===== */
.history-section {
  width: 100%;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 16px;
}

.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 32px 16px;
  font-size: 0.9rem;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  transition: border-color 0.2s var(--ease);
}

.history-card:hover {
  border-color: rgba(79, 143, 247, 0.2);
}

.history-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.difficulty-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.difficulty-badge.difficulty-1,
.difficulty-badge[class*="Easy"] {
  background: rgba(52, 211, 153, 0.1);
  color: var(--accent-green);
}

.difficulty-badge.difficulty-2 {
  background: rgba(79, 143, 247, 0.1);
  color: var(--accent-blue);
}

.difficulty-badge.difficulty-3 {
  background: rgba(245, 197, 66, 0.1);
  color: var(--accent-gold);
}

.history-date {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.history-card-body {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.history-progress {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-primary);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-gold));
  border-radius: 3px;
  transition: width 0.4s var(--ease);
}

.progress-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.history-time {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.history-card-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.status-complete {
  font-size: 0.8rem;
  color: var(--accent-green);
  font-weight: 600;
  margin-right: auto;
}

/* ===== GAME VIEW ===== */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
}

.game-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.timer {
  font-size: 1.1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.progress-badge {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-blue);
  background: rgba(79, 143, 247, 0.1);
  padding: 4px 10px;
  border-radius: 20px;
}

.game-main {
  flex: 1;
  padding: 20px;
}

.game-layout {
  display: flex;
  gap: 24px;
  max-width: 900px;
  margin: 0 auto;
  align-items: flex-start;
}

.grid-container {
  flex: 1;
  min-width: 0;
}

/* ===== GRID ===== */
.game-grid {
  display: grid;
  gap: 3px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.grid-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.9rem, 3.5vw, 1.2rem);
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s var(--ease);
  position: relative;
  min-width: 0;
}

.grid-cell:hover {
  background: var(--bg-hover);
  transform: scale(1.05);
}

.grid-cell.selected {
  background: var(--accent-blue);
  color: white;
  box-shadow: 0 0 12px var(--accent-blue-glow);
  transform: scale(1.08);
  z-index: 2;
}

.grid-cell.found {
  background: rgba(245, 197, 66, 0.12);
  color: var(--accent-gold);
  border: 1px solid rgba(245, 197, 66, 0.2);
}

.grid-cell.just-found {
  animation: cellFound 0.6s var(--ease);
}

@keyframes cellFound {
  0% { transform: scale(1.08); background: var(--accent-blue); }
  50% { transform: scale(1.2); background: var(--accent-gold); box-shadow: 0 0 20px var(--accent-gold-glow); }
  100% { transform: scale(1); }
}

.grid-cell.wrong {
  animation: cellWrong 0.4s var(--ease);
}

@keyframes cellWrong {
  0%, 100% { background: var(--bg-secondary); }
  50% { background: rgba(248, 113, 113, 0.3); box-shadow: 0 0 12px var(--accent-red-glow); }
}

.grid-cell.hint {
  background: rgba(245, 197, 66, 0.08);
  box-shadow: inset 0 0 0 2px rgba(245, 197, 66, 0.4);
}

.grid-cell.hint-pulse {
  animation: hintPulse 1.5s var(--ease);
}

@keyframes hintPulse {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(245, 197, 66, 0.4); }
  25% { box-shadow: inset 0 0 0 3px rgba(245, 197, 66, 0.8), 0 0 16px var(--accent-gold-glow); }
  50% { box-shadow: inset 0 0 0 2px rgba(245, 197, 66, 0.6), 0 0 8px var(--accent-gold-glow); }
  75% { box-shadow: inset 0 0 0 3px rgba(245, 197, 66, 0.8), 0 0 16px var(--accent-gold-glow); }
}

/* ===== WORD LIST PANEL ===== */
.word-list-panel {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.panel-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

.word-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.word-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  transition: all 0.3s var(--ease);
}

.word-item.found {
  background: rgba(245, 197, 66, 0.08);
  border-left: 3px solid var(--accent-gold);
}

.word-greek {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: all 0.3s var(--ease);
}

.word-item.found .word-greek {
  text-decoration: line-through;
  color: var(--accent-gold);
  opacity: 0.7;
}

.word-translation {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===== MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
}

.modal-overlay.active {
  display: block;
  animation: fadeIn 0.2s var(--ease);
}

.modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 28px;
  z-index: 101;
  width: 90%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal.active {
  display: block;
  animation: modalIn 0.3s var(--ease);
}

@keyframes modalIn {
  from { opacity: 0; transform: translate(-50%, -48%); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

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

.modal-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

.modal-close-btn {
  font-size: 0.9rem;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.difficulty-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  color: var(--text-primary);
  font-family: var(--font);
  text-align: left;
  width: 100%;
}

.difficulty-btn:hover {
  border-color: var(--accent-blue);
  background: var(--bg-hover);
  transform: translateX(4px);
}

.difficulty-btn:active {
  transform: translateX(2px) scale(0.99);
}

.diff-icon {
  font-size: 1.5rem;
  font-weight: 700;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: rgba(79, 143, 247, 0.1);
  color: var(--accent-blue);
  flex-shrink: 0;
}

.difficulty-btn[data-difficulty="2"] .diff-icon {
  background: rgba(245, 197, 66, 0.1);
  color: var(--accent-gold);
}

.difficulty-btn[data-difficulty="3"] .diff-icon {
  background: rgba(248, 113, 113, 0.1);
  color: var(--accent-red);
}

.diff-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.diff-info strong {
  font-size: 0.95rem;
}

.diff-info span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===== COMPLETION VIEW ===== */
.completion-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 40px 24px;
  text-align: center;
  gap: 20px;
}

.completion-icon {
  font-size: 4rem;
  animation: trophy 1s var(--ease);
}

@keyframes trophy {
  0% { transform: scale(0) rotate(-20deg); opacity: 0; }
  60% { transform: scale(1.2) rotate(5deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.completion-title {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-gold), #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.completion-subtitle {
  color: var(--text-secondary);
  font-size: 1rem;
}

.completion-stats {
  display: flex;
  gap: 24px;
  margin: 20px 0;
  flex-wrap: wrap;
  justify-content: center;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-width: 100px;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent-blue);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.completion-actions {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}

/* ===== RESPONSIVE — MOBILE (tablets + phones) ===== */
@media (max-width: 700px) {
  /* Layout: stack vertically, grid on top */
  .game-layout {
    flex-direction: column;
    gap: 10px;
  }

  .grid-container {
    order: 1;
    width: 100%;
  }

  .word-list-panel {
    width: 100%;
    order: 2;
  }

  /* Grid: full width, minimal padding, fills the screen */
  .game-main {
    padding: 6px;
  }

  .game-grid {
    padding: 5px;
    gap: 2px;
    border-radius: 8px;
    width: 100%;
    border: none;
  }

  .grid-cell {
    font-size: min(5vw, 1.15rem);
    border-radius: 3px;
    font-weight: 700;
    aspect-ratio: 1;
  }

  /* Disable hover on touch devices */
  .grid-cell:hover {
    transform: none;
    background: var(--bg-secondary);
  }
  .grid-cell.selected:hover {
    background: var(--accent-blue);
  }
  .grid-cell.found:hover {
    background: rgba(245, 197, 66, 0.12);
  }

  /* Compact header */
  .game-header {
    padding: 8px 10px;
    gap: 4px;
    flex-wrap: nowrap;
  }

  .game-info {
    gap: 8px;
    flex: 1;
    justify-content: center;
    order: 2;
  }

  #btn-back {
    order: 1;
  }

  .btn-hint-action {
    order: 3;
    flex-shrink: 0;
    white-space: nowrap;
  }

  .timer {
    font-size: 1rem;
  }

  .difficulty-badge {
    font-size: 0.65rem;
    padding: 2px 7px;
  }

  .progress-badge {
    font-size: 0.65rem;
    padding: 2px 7px;
  }

  .btn-icon-only {
    width: 36px;
    height: 36px;
    font-size: 1rem;
    flex-shrink: 0;
  }

  .btn-hint-action {
    font-size: 0.78rem;
    padding: 6px 12px;
  }

  /* Word list: compact horizontal wrap */
  .word-list-panel {
    padding: 10px;
    border-radius: 8px;
  }

  .panel-title {
    font-size: 0.7rem;
    margin-bottom: 6px;
  }

  .word-list {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 5px;
  }

  .word-item {
    padding: 5px 8px;
    flex-direction: row;
    align-items: center;
    gap: 5px;
    flex: 0 0 auto;
    border-radius: 6px;
  }

  .word-greek {
    font-size: 0.85rem;
  }

  .word-translation {
    font-size: 0.65rem;
  }

  /* Home */
  .home-header {
    padding: 28px 16px 16px;
  }

  .logo-icon {
    font-size: 2.4rem;
  }

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

  .home-main {
    padding: 16px;
    gap: 28px;
  }

  .btn-large {
    width: 100%;
  }

  .completion-stats {
    gap: 12px;
  }

  .stat {
    min-width: 80px;
    padding: 12px 14px;
  }
}

/* ===== RESPONSIVE — SMALL PHONES ===== */
@media (max-width: 400px) {
  .game-main {
    padding: 4px;
  }

  .game-grid {
    padding: 3px;
    gap: 1px;
  }

  .grid-cell {
    font-size: min(6vw, 1rem);
    border-radius: 2px;
  }

  .home-header {
    padding: 20px 10px 10px;
  }

  .logo-icon {
    font-size: 2rem;
  }

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

  .home-main {
    padding: 10px;
    gap: 20px;
  }
}

/* ===== RESPONSIVE — VERY SMALL PHONES ===== */
@media (max-width: 360px) {
  .grid-cell {
    font-size: clamp(0.75rem, 6.5vw, 1.1rem);
    border-radius: 3px;
  }

  .game-grid {
    gap: 1px;
    padding: 3px;
  }

  .word-item {
    padding: 4px 8px;
  }

  .word-greek {
    font-size: 0.78rem;
  }

  .word-translation {
    font-size: 0.65rem;
  }
}

/* ===== SAFE AREA — NOTCHED PHONES ===== */
@supports (padding: env(safe-area-inset-top)) {
  .game-header {
    padding-top: max(12px, env(safe-area-inset-top));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  .game-main {
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }

  .home-header {
    padding-top: max(40px, env(safe-area-inset-top));
  }
}
