:root {
  color-scheme: light;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: #f4f6fb;
  color: #14213d;
}

html,
body {
  min-height: 100%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: linear-gradient(135deg, #eef2ff 0%, #f9fbff 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: calc(16px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

.splash-screen {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 11000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #e9ecf5 0%, #f3f5fb 100%);
  transition: opacity 0.45s ease, visibility 0.45s ease;
}

.splash-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.language-gate {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 12000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  background: linear-gradient(135deg, #1d4ed8 0%, #06b6d4 100%);
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

.language-gate.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.language-gate-card {
  width: min(92vw, 420px);
  padding: 28px 24px;
  border-radius: 24px;
  background: #ffffff;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.35);
  text-align: center;
}

.language-gate-icon {
  font-size: 2.5rem;
  line-height: 1;
  margin-bottom: 8px;
}

.language-gate-title {
  margin: 0 0 6px;
  font-size: clamp(1.15rem, 5vw, 1.4rem);
  font-weight: 800;
  color: #14213d;
}

.language-gate-subtitle {
  margin: 0 0 20px;
  font-size: 0.85rem;
  color: #64748b;
}

.language-gate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.language-gate-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 10px;
  border: 2px solid #e2e8f0;
  border-radius: 16px;
  background: #f8fafc;
  color: #14213d;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.language-gate-btn:first-child {
  grid-column: 1 / -1;
}

.language-gate-btn .flag {
  font-size: 1.6rem;
  line-height: 1;
}

.language-gate-btn:hover,
.language-gate-btn:focus-visible {
  border-color: #1d4ed8;
  background: #eef2ff;
  outline: none;
}

.language-gate-btn:active {
  transform: scale(0.96);
}

.splash-card {
  width: min(92vw, 360px);
  text-align: center;
  color: #1e40af;
}

.splash-title {
  margin: 0;
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 800;
  letter-spacing: 0.02em;
}

.splash-subtitle {
  margin: 2px 0 20px;
  font-size: 1.15rem;
  font-weight: 700;
  color: #0ea5e9;
}

.splash-circuit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 18px;
}

.splash-circuit span {
  width: 64px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, #60a5fa 0%, #a78bfa 50%, #22d3ee 100%);
  opacity: 0.85;
}

.splash-badge {
  display: inline-block;
  margin-bottom: 16px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #dbeafe;
  color: #0284c7;
  font-weight: 700;
  font-size: 0.75rem;
}

.splash-progress-track {
  width: min(80vw, 260px);
  height: 8px;
  margin: 0 auto;
  border-radius: 999px;
  background: #dbe1ea;
  overflow: hidden;
}

#splashProgress {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #7c3aed 0%, #06b6d4 100%);
}

.app {
  width: min(100%, 740px);
  background: #ffffff;
  border-radius: 24px;
  box-shadow: 0 18px 48px rgba(20, 33, 61, 0.16);
  padding: 24px;
}

.header,
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.24em;
  font-size: 0.8rem;
  color: #5b6c8f;
  margin: 0 0 4px;
}

h1 {
  margin: 0;
  font-size: 2rem;
}

button,
select {
  font: inherit;
  touch-action: manipulation;
}

.primary-btn,
.secondary-btn {
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.primary-btn:hover,
.secondary-btn:hover,
.cell:hover {
  transform: translateY(-1px);
}

.primary-btn {
  background: #2563eb;
  color: white;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.2);
}

.secondary-btn {
  background: #e2e8f0;
  color: #14213d;
}

.hint-btn {
  --hint-power: 1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.hint-count {
  padding: 2px 8px;
  border-radius: 999px;
  background: #cbd5e1;
  color: #0f172a;
  font-size: 0.78rem;
  font-weight: 800;
}

.bulb-icon {
  position: relative;
  width: 12px;
  height: 16px;
  border-radius: 8px 8px 6px 6px;
  background: #fef08a;
  border: 1px solid #f59e0b;
  box-shadow: 0 0 calc(16px * var(--hint-power)) rgba(250, 204, 21, 0.85);
}

.bulb-icon::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -4px;
  transform: translateX(-50%);
  width: 8px;
  height: 4px;
  border-radius: 2px;
  background: #64748b;
}

.bulb-icon::after {
  content: '';
  position: absolute;
  top: -6px;
  right: -6px;
  bottom: -6px;
  left: -6px;
  border-radius: 999px;
  border: 1px solid rgba(250, 204, 21, calc(0.85 * var(--hint-power)));
}

.hint-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.hint-btn:disabled .bulb-icon {
  background: #e2e8f0;
  border-color: #94a3b8;
  box-shadow: none;
}

.toolbar {
  margin-top: 20px;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
}

.control select {
  border: 1px solid #d7def2;
  border-radius: 10px;
  padding: 8px 10px;
  background: #f8faff;
}

.status-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #f8faff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px 14px;
  min-width: 88px;
}

#livesValue {
  color: #dc2626;
  letter-spacing: 1px;
  font-size: 1rem;
  line-height: 1;
}

.message {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  font-weight: 600;
}

.message.info {
  background: #eff6ff;
  color: #1d4ed8;
}

.message.success {
  background: #ecfdf3;
  color: #16784d;
}

.message.error {
  background: #fef2f2;
  color: #b91c1c;
}

.game-area {
  margin-top: 18px;
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: center;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 170px;
}

.helper-text {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: #475569;
}

.app-footer {
  margin-top: 8px;
  text-align: center;
  font-size: 0.8rem;
  color: #94a3b8;
}

.app-footer a {
  color: #64748b;
  text-decoration: none;
}

.app-footer a:hover,
.app-footer a:focus-visible {
  color: #1d4ed8;
  text-decoration: underline;
}

.app-footer span {
  margin: 0 6px;
}

.board {
  margin-top: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 2px;
  background: #14213d;
  padding: 4px;
  border-radius: 16px;
  flex: 1 1 0;
  max-width: 560px;
  box-sizing: border-box;
}

.cell {
  flex: 0 0 auto;
  aspect-ratio: 1;
  box-sizing: border-box;
  border: 1px solid #d7def2;
  border-radius: 8px;
  background: white;
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.12s ease;
}

.cell.fixed {
  background: #e7ecf7;
  color: #0f172a;
  cursor: default;
}

.cell.selected {
  background: #dbeafe;
  border: 3px solid #60a5fa;
}

.cell.error {
  background: #ef4444 !important;
  border: 3px solid #b91c1c !important;
  color: #ffffff;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25);
  animation: cell-error-flash 0.55s ease;
}

@keyframes cell-error-flash {
  0%,
  65% {
    background: #ef4444;
    border-color: #b91c1c;
    color: #ffffff;
  }
  100% {
    background: white;
    border-color: #d7def2;
    color: #0f172a;
  }
}

.cell.empty {
  color: #64748b;
}

.cell:nth-child(9n + 3),
.cell:nth-child(9n + 6) {
  border-right: 3px solid #14213d;
}

.cell:nth-child(n + 19):nth-child(-n + 27),
.cell:nth-child(n + 46):nth-child(-n + 54),
.cell:nth-child(n + 73):nth-child(-n + 81) {
  border-bottom: 3px solid #14213d;
}

.number-pad {
  margin-top: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.number-pad button {
  box-sizing: border-box;
  flex: 1 1 calc(33.333% - 7px);
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #d7def2;
  background: #f8faff;
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
}

.number-pad .clear {
  background: #fee2e2;
  color: #b91c1c;
}

@media (max-width: 780px) {
  .game-area {
    flex-direction: column;
    align-items: stretch;
  }

  .side-panel {
    min-width: 0;
  }

  .number-pad button {
    flex-basis: calc(20% - 8px);
  }
}

@media (max-width: 640px) {
  body {
    padding: calc(8px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
  }

  .app {
    padding: 16px;
    border-radius: 16px;
  }

  h1 {
    font-size: 1.45rem;
  }

  .cell {
    font-size: 0.95rem;
  }

  .number-pad button {
    min-height: 52px;
  }
}

#celebrationCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  display: block;
}

.game-over-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(15, 23, 42, 0.62);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 16px;
}

.game-over-overlay.visible {
  display: flex;
}

.game-over-card {
  width: min(100%, 360px);
  background: #ffffff;
  border-radius: 18px;
  padding: 22px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.28);
}

.game-over-card h2 {
  margin: 0 0 10px;
  color: #b91c1c;
}

.game-over-card p {
  margin: 0 0 18px;
  color: #334155;
  font-weight: 600;
}
