:root {
  --bg: #0f1220;
  --card: #181c2f;
  --cell: #2b314f;
  --cell-border: #3b4267;
  --ink: #f7f7fb;
  --muted: #9aa3c7;
  --accent: #f3c969;
  --correct: #47d18c;
  --extra: #ff637d;
  --missed: #5fa8ff;
  --ui-scale: 1;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at top, #23294a, var(--bg));
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  width: min(94vw, 520px);
  padding: 28px 0;
  zoom: var(--ui-scale);
}

.hero {
  text-align: center;
  margin-bottom: 18px;
}

.eyebrow {
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .14em;
  font-size: 11px;
  font-weight: 800;
  margin: 0 0 9px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.app-icon {
  display: block;
  width: 50px;
  height: 50px;
  flex: 0 0 auto;
  filter: drop-shadow(0 8px 18px rgba(243, 201, 105, .16));
}

h1 {
  font-size: clamp(38px, 10vw, 46px);
  line-height: 1;
  letter-spacing: -.035em;
  margin: 0;
}

.subtitle {
  max-width: 390px;
  color: var(--muted);
  line-height: 1.45;
  margin: 9px auto 0;
}


.mode-switch {
  width: fit-content;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 17px auto 0;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 999px;
  background: rgba(14, 17, 31, .66);
}

.mode-option {
  min-width: 108px;
  padding: 10px 18px;
  background: transparent;
  color: var(--muted);
}

.mode-option[aria-pressed="true"] {
  background: var(--accent);
  color: #141414;
  box-shadow: 0 6px 18px rgba(243, 201, 105, .18);
}

.floating-view-scale {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 20;

  opacity: .7;
  transition: opacity .2s;
}

.floating-view-scale:hover {
  opacity: 1;
}

.view-scale {
  display: flex;
  align-items: center;
  gap: 2px;

  padding: 2px 6px;
  border-radius: 999px;

  background: transparent;
  border: none;
}

.view-scale button {
  min-width: 0;
  height: 28px;
  padding: 0;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}

.view-scale button:hover:not(:disabled) {
  transform: none;
  background: rgba(255, 255, 255, .06);
}

.scale-button {
  width: 24px;
  font-size: 15px;
}

.scale-value {
  width: 40px;
  font-size: 11px;
  text-align: center;
}

@supports not (zoom: 1) {
  .app {
    width: min(calc(94vw / var(--ui-scale)), calc(520px / var(--ui-scale)));
    transform: scale(var(--ui-scale));
    transform-origin: center top;
  }
}

.card {
  background: rgba(24, 28, 47, .92);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 24px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 16px;
  margin-bottom: 14px;
}

.puzzle-heading {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 4px;
}


.puzzle-name {
  font-size: 20px;
  font-weight: 800;
  margin: 0;
}

.muted {
  color: var(--muted);
  margin: 0;
  line-height: 1.35;
}

.level-info {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.score-box {
  font-size: 24px;
  font-weight: 900;
  color: var(--accent);
}

.grid {
  --cell-size: 46px;
  display: grid;
  gap: 7px;
  justify-content: center;
  /* Keep one-finger drawing while allowing two-finger browser zoom. */
  touch-action: pinch-zoom;
  margin: 20px auto;
  user-select: none;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 9px;
  background: var(--cell);
  border: 1px solid var(--cell-border);
  cursor: pointer;
  transition: transform .08s, background .12s, opacity .2s;
}

.cell:hover { transform: scale(1.04); }
.cell.target, .cell.selected { background: var(--accent); }
.cell.correct { background: var(--correct); }
.cell.extra { background: var(--extra); }
.cell.missed { background: var(--missed); }
.cell.locked { cursor: default; }
.cell.locked:hover { transform: none; }

.message {
  min-height: 28px;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
}

.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 12px 20px;
  background: var(--accent);
  color: #141414;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: transform .12s ease, opacity .2s ease, background .2s ease;
}

button:hover:not(:disabled) { transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(0); }

button.secondary {
  background: #2b314f;
  color: var(--ink);
}

button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.legend {
  display: flex;
  justify-content: center;
  gap: 18px;
  color: var(--muted);
  font-size: 13px;
  margin-top: 14px;
}

.legend b {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 3px;
  margin-right: 6px;
}

.green { background: var(--correct); }
.red { background: var(--extra); }
.blue { background: var(--missed); }

.share-button {
  width: 100%;
  margin-top: 18px;
  padding: 14px 22px;
  border: 1px solid rgba(255, 255, 255, .08);
}

@media (max-width: 420px) {
  .floating-view-scale {
    top: 10px;
    right: 10px;
  }

  .topbar { gap: 10px; }
  .level-info { font-size: 12px; }
  .app { padding: 28px 0 20px; }
  .brand-lockup { gap: 10px; }
  .app-icon { width: 46px; height: 46px; }
  h1 { font-size: clamp(36px, 10.5vw, 42px); }
  .subtitle { padding: 0 12px; }
  .card { padding: 18px 14px; }
  .mode-option { min-width: 92px; }
  .legend { gap: 12px; }
}


.share-panel {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, .10);
  border-radius: 20px;
  background: rgba(24, 28, 47, .92);
}

.share-panel[hidden] {
  display: none;
}

.share-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.share-panel-title {
  margin: 0 0 4px;
  color: var(--ink);
  font-weight: 800;
}

.share-panel-message {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.icon-button {
  min-width: 38px;
  width: 38px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  background: #2b314f;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.result-preview {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, .08);
  background: var(--card);
}

.share-destinations {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.share-destination {
  display: grid;
  place-items: center;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .09);
  background: #2b314f;
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  transition: transform .12s ease, background .2s ease;
}

.share-destination:hover {
  transform: translateY(-1px);
  background: #363d61;
}

.share-panel-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.share-panel-actions button {
  width: 100%;
}

@media (max-width: 520px) {
  .share-destinations {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  .share-panel-actions {
    grid-template-columns: 1fr;
  }
}
