/* First-run tutorial */
.tutorial-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 39, 51, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 250;
  padding: 1rem;
  animation: fade-in-tut 0.25s ease-out;
}
@keyframes fade-in-tut {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.tutorial-card {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 1.75rem 1.25rem 1.25rem;
  width: 100%;
  max-width: 22rem;
  text-align: center;
}
.tut-icon { font-size: 3rem; }
.tut-title {
  font-size: 1.4rem;
  font-weight: 800;
  margin: 0.5rem 0 0.4rem;
  color: var(--primary);
}
.tut-body {
  font-size: 0.95rem;
  line-height: 1.5;
  margin: 0 0 1rem;
}
.tut-dots {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  margin-bottom: 1rem;
}
.tut-dot {
  width: 0.5rem;
  height: 0.5rem;
  background: var(--border);
  border-radius: 50%;
  transition: background 0.2s, transform 0.2s;
}
.tut-dot.active {
  background: var(--primary);
  transform: scale(1.4);
}
.tut-actions {
  display: flex;
  gap: 0.6rem;
}
.tut-actions .btn { flex: 1; padding: 0.7rem; font-size: 0.95rem; }

/* Profile page */
.profile-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.25rem 2rem;
}
.profile-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem 1rem 0.5rem;
}
.profile-avatar {
  width: 5rem;
  height: 5rem;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: var(--shadow-md);
  border: 3px solid var(--surface);
}
.profile-avatar.placeholder {
  background: var(--primary);
  color: var(--primary-contrast);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 800;
}
.profile-name {
  font-size: 1.4rem;
  font-weight: 700;
  margin-top: 0.6rem;
  letter-spacing: -0.01em;
}
.profile-anon {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}
.profile-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin: 1.2rem 0.5rem;
}
.profile-stats .stat {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.4rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.profile-stats .stat-num {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--primary);
}
.profile-stats .stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 0.1rem;
}

.badge-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
  padding: 0 0.5rem;
}
.badge {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.75rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s;
}
.badge.got { border-left: 4px solid var(--primary); }
.badge.locked { opacity: 0.5; }
.badge-icon {
  font-size: 1.8rem;
}
.badge-name {
  font-size: 0.85rem;
  font-weight: 700;
  margin-top: 0.25rem;
}
.badge-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
  line-height: 1.3;
}

/* Leaderboard podium for top 3 + your-position pinned card */
.podium {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  gap: 0.6rem;
  align-items: end;
  margin: 1rem 0 0.75rem;
  padding: 0 0.25rem;
}
.podium-slot {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 0.75rem 0.5rem 0.85rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
}
.podium-slot.rank-1 { padding-top: 1.5rem; transform: translateY(-0.4rem); }
.podium-slot.rank-2 { padding-top: 1.2rem; }
.podium-slot.rank-3 { padding-top: 1.0rem; }
.podium-slot.empty  { visibility: hidden; }
.podium-slot.me {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}
.podium-slot .medal {
  font-size: 1.6rem;
  margin-bottom: 0.35rem;
}
.podium-slot .lb-avatar.large {
  width: 3.2rem; height: 3.2rem;
}
.podium-slot .p-name {
  font-size: 0.78rem;
  font-weight: 600;
  margin-top: 0.4rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width: 100%;
}
.podium-slot .p-score {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--primary);
  margin-top: 0.15rem;
}

.lb-your-position {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: var(--primary);
  color: var(--primary-contrast);
  border-radius: var(--radius-md);
  position: sticky;
  bottom: 0.5rem;
  box-shadow: var(--shadow-lg);
  flex-wrap: wrap;
}
.lb-your-position .lb-yp-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.2rem 0.5rem;
  background: rgba(255,255,255,0.18);
  border-radius: 4px;
}
.lb-your-position .lb-name, .lb-your-position .lb-score { color: var(--primary-contrast); }
.lb-your-position .lb-yp-hint {
  flex-basis: 100%;
  font-size: 0.78rem;
  opacity: 0.9;
  margin-top: 0.2rem;
}

/* Animated intro screen ------------------------------------------------ */
#intro {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0d9488 0%, #22d3ee 100%);
  pointer-events: none;
  /* Overall fade-out at the end */
  transition: opacity 0.45s ease;
}
#intro.gone { opacity: 0; }
#intro-owl {
  /* Matches the Android 12+ system splash icon position + size so the
     transition from OS splash → JS intro is invisible. */
  width: 12rem;
  height: 12rem;
  object-fit: contain;
  border-radius: 2.4rem;
  /* No fade-in: same frame as the OS splash that just preceded us. */
}
#intro-title {
  font-size: 3.2rem;
  font-weight: 800;
  color: #fefcf7;
  letter-spacing: -0.03em;
  margin-top: 1.2rem;
  opacity: 0;
  transform: translateY(20px);
  animation: intro-fade-up 0.55s 0.2s ease-out forwards;
  text-shadow: 0 4px 16px rgba(0,0,0,0.15);
}
#intro-tag {
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: rgba(255,255,255,0.92);
  margin-top: 0.4rem;
  opacity: 0;
  transform: translateY(20px);
  animation: intro-fade-up 0.5s 0.5s ease-out forwards;
}
@keyframes intro-owl-in {
  to { opacity: 1; transform: scale(1); }
}
@keyframes intro-fade-up {
  to { opacity: 1; transform: translateY(0); }
}

:root {
  --bg: #f0f9ff;
  --surface: #ffffff;
  --surface-2: #e0f2fe;
  --text: #0c2733;
  --text-muted: #547585;
  --primary: #0891b2;
  --primary-hover: #0e7490;
  --primary-contrast: #ffffff;
  --success: #059669;
  --error: #dc2626;
  --border: #bae6fd;
  --brand-end: #0d9488;
  --shadow-sm: 0 1px 2px rgba(12, 39, 51, 0.06);
  --shadow-md: 0 4px 12px rgba(8, 145, 178, 0.12);
  --shadow-lg: 0 12px 28px rgba(8, 145, 178, 0.18);
  --radius-sm: 0.5rem;
  --radius-md: 0.875rem;
  --radius-lg: 1.25rem;
}

[data-theme='dark'] {
  --bg: #0c1f2b;
  --surface: #14303f;
  --surface-2: #1c3e51;
  --text: #e0f2fe;
  --text-muted: #93b8c8;
  --primary: #22d3ee;
  --primary-hover: #67e8f9;
  --primary-contrast: #0c1f2b;
  --success: #34d399;
  --error: #f87171;
  --border: #2a5063;
  --brand-end: #5eead4;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 32px rgba(0, 0, 0, 0.55);
}

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

html,
body,
#root {
  height: 100%;
  width: 100%;
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overflow: hidden;
  transition: background 0.2s ease, color 0.2s ease;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.screen {
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(env(safe-area-inset-top), 0.5rem) 1rem max(env(safe-area-inset-bottom), 0.75rem);
  max-width: 560px;
  margin: 0 auto;
  position: relative;
}

.header {
  display: flex;
  align-items: center;
  padding: 0.75rem 0;
  gap: 0.75rem;
  min-height: 4rem;
}

.header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  flex: 1;
  text-align: center;
  letter-spacing: -0.01em;
}

.icon-btn {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, background 0.2s;
  flex-shrink: 0;
}

.icon-btn:active { transform: scale(0.94); }

.icon-spacer { width: 2.75rem; flex-shrink: 0; }

.btn {
  padding: 1rem 1.5rem;
  background: var(--primary);
  color: var(--primary-contrast);
  border-radius: var(--radius-md);
  font-size: 1.125rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  transition: transform 0.1s, background 0.2s, box-shadow 0.2s;
}

.btn:active {
  transform: scale(0.98);
  box-shadow: var(--shadow-sm);
}

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
}

.btn-danger {
  background: var(--error);
  color: white;
}

/* Home */
.home-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  text-align: center;
}

.home-hero h1 {
  font-size: 4.5rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  margin: 0 0 0.4rem;
  background: linear-gradient(135deg, var(--primary), var(--brand-end));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.home-mark {
  width: 7rem;
  height: 7rem;
  border-radius: 1.6rem;
  display: block;
  object-fit: contain;
  box-shadow: 0 10px 30px rgba(13, 148, 136, 0.35);
}

.home-hero .tagline {
  color: var(--text-muted);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  margin-bottom: 1.5rem;
}

.home-stats {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.home-stats .stat {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 0.6rem 1rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 4.5rem;
}
.home-stats .stat-num {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.1;
}
.home-stats .stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 0.1rem;
}

.home-hero .ver {
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-top: 0.5rem;
}

.home-menu {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-bottom: 2rem;
}

.home-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
  transition: transform 0.1s, box-shadow 0.1s;
  text-align: left;
  width: 100%;
}

.home-menu-item:active {
  transform: scale(0.97);
  box-shadow: var(--shadow-sm);
}

.home-menu-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  color: white;
}

.home-menu-arrow {
  margin-left: auto;
  font-size: 1.4rem;
  color: var(--text-muted);
  font-weight: 300;
  line-height: 1;
}

/* Levels map grid */
.levels-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  overflow-y: auto;
  padding: 0.25rem 0 0.5rem;
  flex: 1;
}

.level-cell {
  position: relative;
  aspect-ratio: 1;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: transform 0.08s, background 0.15s;
  cursor: pointer;
}

.level-cell:active { transform: scale(0.93); }

.level-cell.completed {
  background: var(--surface-2);
  color: var(--text-muted);
}

.level-cell.current {
  border: 2px solid var(--primary);
  color: var(--primary);
}

.level-cell.locked {
  background: var(--surface-2);
  color: var(--text-muted);
  opacity: 0.55;
  cursor: not-allowed;
}

/* Leaderboard */
.lb-locked { opacity: 0.35; }

.lb-header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.lb-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.25rem 0 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.lb-row.lb-me {
  background: var(--primary);
  color: var(--primary-contrast);
  box-shadow: var(--shadow-md);
}
.lb-row.lb-me .lb-rank,
.lb-row.lb-me .lb-name,
.lb-row.lb-me .lb-score { color: var(--primary-contrast); }
.lb-row.lb-me .lb-rank::after { content: ' (you)'; font-weight: 600; opacity: 0.85; }

.lb-rank {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  width: 2rem;
  flex-shrink: 0;
  text-align: center;
}


.lb-avatar {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}

.lb-avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-muted);
}

.lb-name {
  flex: 1;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
}

/* Score timer */
.score-timer-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0 0.5rem;
}

.score-timer-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.score-timer-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: background 0.3s;
}

.score-timer-fill.warn { background: var(--error); }

.score-timer-text {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  transition: color 0.3s;
}

.score-timer-text.warn { color: var(--error); }

/* Score screen */
.problem {
  text-align: center;
  font-size: 2.75rem;
  font-weight: 700;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  letter-spacing: -0.02em;
  word-break: break-word;
  line-height: 1.2;
}

.answer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.875rem;
  padding-bottom: 0.5rem;
}

.answer-btn {
  padding: 1.75rem 1rem;
  font-size: 1.5rem;
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-md);
  font-weight: 600;
  transition: transform 0.1s, background 0.25s, color 0.25s;
}

.answer-btn:active { transform: scale(0.96); }

.answer-btn.correct {
  background: var(--success);
  color: white;
  animation: pulse 0.4s ease-out;
}

.answer-btn.wrong {
  background: var(--error);
  color: white;
  animation: shake 0.4s ease-out;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  60% { transform: translateX(8px); }
  80% { transform: translateX(-4px); }
}

/* Levels screen */
.puzzle-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  min-height: 0;
}

.puzzle-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  font-size: 1.85rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.3;
}

.puzzle-text.single {
  font-size: 2.1rem;
  font-weight: 700;
}

.puzzle-grid-3x3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(3.5rem, 5rem));
  background: var(--surface);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.puzzle-grid-3x3 > div {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.375rem;
  font-weight: 600;
}

.puzzle-hex {
  position: relative;
  width: min(280px, 75vw);
  aspect-ratio: 1;
}

.puzzle-hex svg {
  width: 100%;
  height: 100%;
  display: block;
}

.puzzle-hex polygon {
  fill: var(--surface);
  stroke: var(--text);
  stroke-width: 2;
}

.puzzle-hex .hex-cell {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface);
  padding: 0.1rem 0.35rem;
  border-radius: 0.4rem;
}

.input-display {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  padding: 0.4rem 0.8rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  margin: 0 auto 0.4rem;
  width: 100%;
  max-width: 22rem;
  min-height: 2.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  letter-spacing: 0.08em;
}

.input-display .placeholder {
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0;
  font-size: 0.9rem;
}

.input-display.timer { color: var(--error); }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
  padding-bottom: 0.3rem;
  max-width: 22rem;
  margin: 0 auto;
  width: 100%;
}

.keypad button {
  padding: 0.4rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-size: 1.15rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  min-height: 2.4rem;
  transition: transform 0.08s, background 0.2s;
}

.keypad button:active {
  transform: scale(0.95);
  background: var(--surface-2);
}

.keypad button.submit {
  background: var(--primary);
  color: var(--primary-contrast);
}

.keypad button.clear { color: var(--error); }

.keypad button:disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* Settings */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  padding: 1rem 0;
  overflow-y: auto;
  flex: 1;
}

.settings-spacer { min-height: 0.5rem; }

/* 3-state segmented control (used for Theme: Auto / Light / Dark) */
.segmented {
  display: flex;
  margin-top: 0.5rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 0.2rem;
  gap: 0.2rem;
}
.seg-btn {
  flex: 1;
  padding: 0.45rem 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: calc(var(--radius-sm) - 0.15rem);
  color: var(--text-muted);
  background: transparent;
  transition: background 0.18s, color 0.18s;
}
.seg-btn.active {
  background: var(--primary);
  color: var(--primary-contrast);
}

/* Color-blind matrix: orange op-blanks get a + marker overlay so the
   distinction (numbers vs operators) doesn't rely on hue alone. */
html[data-colorblind="on"] .cw-cell.blank.op-blank {
  background-image: repeating-linear-gradient(45deg,
    transparent 0 6px,
    rgba(0,0,0,0.18) 6px 8px);
}
html[data-colorblind="on"] .cw-tile.op-tile {
  outline: 3px dashed var(--text);
  outline-offset: -3px;
}

.about-links {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.about-links a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}
.about-links a:hover { text-decoration: underline; }
.about-sep { color: var(--text-muted); }

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  gap: 1rem;
}

.setting-row .label { font-weight: 500; }

.setting-row .desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  line-height: 1.4;
}

.setting-row.column {
  flex-direction: column;
  align-items: stretch;
  text-align: left;
}

.toggle {
  width: 3rem;
  height: 1.625rem;
  background: var(--border);
  border-radius: 1rem;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle.on { background: var(--primary); }

.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1.25rem;
  height: 1.25rem;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle.on::after { transform: translateX(1.375rem); }

.settings-section-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0.5rem 0 -0.25rem 0.25rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  padding: 0.85rem 1.2rem;
  border-radius: var(--radius-md);
  border-left: 4px solid var(--primary);
  box-shadow: var(--shadow-lg);
  font-weight: 600;
  font-size: 0.95rem;
  z-index: 100;
  max-width: 88%;
  text-align: left;
  white-space: pre-line;
  line-height: 1.45;
  animation: toast-in 0.22s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* Σωστό/Λάθος feedback overlay — μεγάλη κάρτα στο κέντρο της οθόνης */
.feedback-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 300;
  padding: 1rem;
}

.feedback-card {
  font-size: 2.5rem;
  font-weight: 800;
  padding: 1.4rem 2.4rem;
  border-radius: 1.4rem;
  background: var(--surface);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.28);
  border: 3px solid;
  letter-spacing: -0.02em;
  text-align: center;
  max-width: 92vw;
  animation: feedback-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.feedback-card.correct {
  color: var(--success);
  border-color: var(--success);
}

.feedback-card.wrong {
  color: var(--error);
  border-color: var(--error);
}

@keyframes feedback-pop {
  0%   { transform: scale(0.5); opacity: 0; }
  55%  { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* Crossword mode */
.cw-scroll {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
  overflow-y: auto;
  padding: 0.5rem 0;
}
.cw-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.5rem;
  overflow-x: auto;
  max-width: 100%;
}
.cw-grid {
  display: grid;
  gap: 4px;
  flex-shrink: 0;
  margin: 0 auto;
}
.cw-cell, .cw-op {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  border-radius: 8px;
}
.cw-cell {
  font-size: 1rem;
}
.cw-cell.clue {
  background: var(--surface-2);
  color: var(--text);
  border: 2px solid var(--border);
}
.cw-cell.blank {
  background: var(--surface);
  border: 2px dashed var(--text-muted);
  cursor: pointer;
}
.cw-cell.blank.open {
  border-color: var(--primary);
  border-style: solid;
}
.cw-cell.blank.op-blank {
  border-color: #e8870c;
  background: rgba(232, 135, 12, 0.16);
}
.cw-cell.filled {
  background: var(--primary);
  color: #fff;
  border: 2px solid var(--primary);
  cursor: pointer;
}
.cw-op {
  color: var(--text-muted);
  font-size: 0.95rem;
}
.cw-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0.6rem 1rem 0;
}
.cw-bank {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.5rem;
  max-width: 95%;
}
.cw-tile {
  min-width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 800;
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--text);
  border: 2px solid var(--border);
  cursor: pointer;
}
.cw-tile.op-tile {
  background: rgba(232, 135, 12, 0.18);
  border-color: #e8870c;
  color: #e8870c;
}
.cw-tile.sel {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  transform: translateY(-3px);
}
.cw-tile.used {
  opacity: 0.18;
  pointer-events: none;
}

/* How-to-play panel — no animation to avoid flicker on re-render */
.help-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 31, 43, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.dialog-panel {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 1.5rem 1.5rem 1.25rem;
  width: 100%;
  max-width: 22rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.dialog-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
}
.dialog-body {
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--text);
  white-space: pre-line;
}
.dialog-input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  box-sizing: border-box;
}

/* Custom share modal (desktop fallback when no native share sheet) */
.share-preview {
  background: var(--surface-2);
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 8rem;
  overflow-y: auto;
}
.share-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}
.share-btn {
  padding: 0.7rem 0.6rem;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, transform 0.05s;
}
.share-btn:hover { background: var(--surface); }
.share-btn:active { transform: scale(0.97); }
.dialog-input:focus {
  outline: none;
  border-color: var(--primary);
}
.dialog-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.25rem;
}
/* For 3-button dialogs, stack vertically — long labels don't fit side-by-side */
.dialog-actions-stack {
  flex-direction: column;
  gap: 0.5rem;
}
.dialog-actions-stack .dialog-btn { flex: 0 0 auto; width: 100%; }
.dialog-btn {
  flex: 1;
  padding: 0.7rem 0.6rem;
  font-size: 0.95rem;
}

.help-panel {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 24rem;
  max-height: 85vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.help-title {
  margin: 0;
  font-size: 1.3rem;
  text-align: center;
}
.help-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.92rem;
  line-height: 1.5;
}
.help-body p {
  margin: 0;
}
.help-sub {
  font-weight: 700;
  color: var(--text-muted);
  margin-top: 0.4rem !important;
}
/* End card */
.end-card {
  background: var(--surface);
  padding: 2rem;
  border-radius: var(--radius-lg);
  text-align: center;
  box-shadow: var(--shadow-md);
  margin: auto;
  max-width: 26rem;
}

.end-card h2 {
  font-size: 1.5rem;
  margin-bottom: 0.75rem;
}

.end-card p {
  color: var(--text-muted);
  line-height: 1.5;
}
