:root {
  color-scheme: light;
  --bg: #f8f4ee;
  --card: #ffffff;
  --card-soft: #f4ece4;
  --stroke: #e4d7cc;
  --stroke-strong: #c8b7a9;
  --text: #242220;
  --muted: #6e645e;
  --accent: #1e5a52;
  --accent-light: #e4efec;
  --terracotta: #b86964;
  --terracotta-light: #fbeee8;
  --emerald: #1e5a52;
  --danger: #b86964;
  --amber: #d97706;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

body.playing-screen {
  height: 100dvh;
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button, input {
  font: inherit;
}

/* Persistent Top Navigation Bar with Back to Wonderworld Games */
.site-topbar {
  height: 54px;
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--stroke);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
  z-index: 30;
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.ww-home-link {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
  padding: 6px 10px;
  border-radius: 9px;
  background: var(--card-soft);
  border: 1px solid var(--stroke);
  white-space: nowrap;
  transition: transform 0.12s, background 0.12s, border-color 0.12s;
}

.ww-home-link span {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

.ww-home-link:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.brand-sep {
  color: var(--stroke-strong);
  font-weight: 600;
}

.game-brand-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 0;
  padding: 4px 6px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  font-size: 15px;
}

.game-brand-btn:hover {
  background: var(--card-soft);
}

.game-brand-btn img {
  border-radius: 7px;
  display: block;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-pill {
  min-height: 34px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: var(--card);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background 0.12s, border-color 0.12s, transform 0.1s;
}

.nav-pill:hover {
  background: var(--card-soft);
  border-color: var(--stroke-strong);
}

.nav-pill[aria-current="page"],
.nav-pill.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

main {
  flex: 1;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

body.playing-screen main {
  padding: 10px 14px;
  height: calc(100dvh - 54px);
  justify-content: space-between;
}

/* Play Screen Layout */
.play-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  gap: 8px;
}

.play-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: 16px;
  padding: 8px 14px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(24, 21, 40, 0.04);
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.level-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 17px;
  color: var(--text);
}

.level-nav-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--stroke);
  background: var(--card-soft);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  min-height: 0;
}

.level-nav-btn:hover:not(:disabled) {
  background: var(--accent-light);
  border-color: var(--accent);
}

.hud-center {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  background: var(--card-soft);
  padding: 4px 12px;
  border-radius: 999px;
}

.hud-center b {
  color: var(--accent);
}

.lives-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 17px;
  color: var(--danger);
  letter-spacing: 2px;
}

/* Interactive Puzzle Board Container */
.board-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background: radial-gradient(circle at 50% 35%, #ffffff 0%, #f6eee5 100%);
  border: 2px solid var(--stroke);
  border-radius: 22px;
  box-shadow: inset 0 2px 10px rgba(30, 90, 82, 0.04), 0 8px 24px rgba(45, 30, 25, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 8px;
  touch-action: none;
  user-select: none;
}

.board-stage {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
  transition: transform 0.18s cubic-bezier(0.2, 0, 0, 1);
  will-change: transform;
}

.board-stage.is-panning {
  transition: none !important;
  cursor: grab;
}

.board-stage.is-panning:active {
  cursor: grabbing;
}

.board {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  user-select: none;
  touch-action: none;
}

.zoom-reset-btn {
  font-size: 12px !important;
  font-weight: 700 !important;
  padding: 6px 11px !important;
  background: var(--accent) !important;
  color: #ffffff !important;
  border-radius: 999px !important;
  border: none !important;
  cursor: pointer !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.zoom-reset-btn:hover {
  background: #14423b !important;
  transform: translateY(-1px) !important;
}

/* Tactile 3D-style SVG Arrows */
.board .arrow {
  cursor: pointer;
  will-change: transform, opacity;
}

.board .arrow .shaft-shadow {
  fill: none;
  stroke: rgba(15, 23, 42, 0.16);
  stroke-width: 0.42;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform: translateY(0.06px);
}

.board .arrow .shaft-border {
  fill: none;
  stroke: var(--arrow-dark, #4c1d95);
  stroke-width: 0.40;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.board .arrow .shaft-core {
  fill: none;
  stroke: var(--arrow-main, #7c3aed);
  stroke-width: 0.28;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke 0.15s, filter 0.15s;
}

.board .arrow .shaft-shine {
  fill: none;
  stroke: rgba(255, 255, 255, 0.45);
  stroke-width: 0.08;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.board .arrow .tail-dot {
  fill: #ffffff;
  opacity: 0.85;
}

.board .arrow .hit {
  fill: none;
  stroke: transparent;
  stroke-width: 0.78;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.board .arrow:hover .shaft-core {
  filter: brightness(1.12);
}

.board .arrow:focus {
  outline: none;
}

.board .arrow:focus-visible .shaft-border {
  stroke: #111827;
  stroke-width: 0.46;
}

/* Flying Escape Animation when unblocked! */
.board .arrow.flying {
  pointer-events: none;
}

.board .arrow.removed {
  opacity: 0;
  pointer-events: none;
}

/* Blocked Shake Animation */
.board .arrow.blocked .shaft-border {
  stroke: #9f1239;
}

.board .arrow.blocked .shaft-core {
  stroke: #f43f5e;
}

.board .arrow.shake-blocked {
  animation: arrowBump 0.34s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes arrowBump {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(calc(var(--bump-dx, 0.18) * 1px), calc(var(--bump-dy, 0) * 1px)); }
  55% { transform: translate(calc(var(--bump-dx, 0.18) * -0.5px), calc(var(--bump-dy, 0) * -0.5px)); }
}

/* Hint Pulse */
.board .arrow.hint .shaft-border {
  stroke: #b45309;
  stroke-width: 0.46;
}

.board .arrow.hint .shaft-core {
  stroke: #f59e0b;
  filter: drop-shadow(0 0 0.25px #fbbf24);
}

/* Bottom Controls Toolbar */
.play-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

button, .button {
  min-height: 40px;
  border-radius: 12px;
  border: 1px solid var(--stroke-strong);
  padding: 8px 14px;
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.12s, transform 0.08s, border-color 0.12s;
}

button:hover:not(:disabled), .button:hover {
  background: var(--card-soft);
  border-color: var(--accent);
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

button.primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(109, 40, 217, 0.25);
}

button.primary:hover:not(:disabled) {
  background: #5b21b6;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

/* Victory / Retry Overlay Banner inside Board */
.overlay-card {
  position: absolute;
  inset: 16px;
  margin: auto;
  max-width: 360px;
  max-height: 250px;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(10px);
  border: 2px solid var(--accent);
  border-radius: 24px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: 0 20px 50px rgba(24, 21, 40, 0.18);
  z-index: 15;
  animation: popCard 0.25s cubic-bezier(0.2, 1.3, 0.4, 1);
}

@keyframes popCard {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.overlay-card h2 {
  margin: 6px 0 8px;
  font-size: 26px;
}

.overlay-card p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14.5px;
}

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

/* Secondary Pages (Levels, Daily Calendar, Stats, Settings) */
.card {
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: 20px;
  padding: 20px;
  margin: 12px 0;
  box-shadow: 0 4px 14px rgba(24, 21, 40, 0.04);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

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

h1 {
  font-size: clamp(28px, 5vw, 42px);
  line-height: 1.12;
  margin: 8px 0 14px;
  letter-spacing: -0.8px;
}

h2 {
  font-size: 22px;
  margin: 0 0 6px;
}

p {
  color: var(--muted);
  margin: 6px 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.calendar {
  grid-template-columns: repeat(7, 1fr);
}

.calendar span {
  text-align: center;
  font-weight: 700;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 0;
}

.calendar button, .grid button {
  padding: 8px 4px;
  font-size: 13.5px;
}

.calendar .done, .grid .done {
  background: #d1fae5;
  border-color: #10b981;
  color: #065f46;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  text-align: center;
}

.stats b {
  font-size: 26px;
  color: var(--accent);
  display: block;
}

.settings label:not(.button) {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
  padding: 12px 0;
  border-bottom: 1px solid var(--stroke);
  font-weight: 500;
}

input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

input[type="month"] {
  border: 1px solid var(--stroke-strong);
  padding: 7px 10px;
  border-radius: 10px;
  background: var(--card);
}

.settings-backup-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 20px;
  width: 100%;
}

.settings-backup-row button,
.settings-backup-row .button,
.backup-btn {
  width: 100%;
  min-height: 42px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  justify-content: center;
  border-radius: 12px;
  margin: 0;
  border: 1px solid var(--stroke-strong);
  background: var(--card);
  display: inline-flex;
  align-items: center;
  box-sizing: border-box;
}

.calendar .active-today {
  background: #e6f4f1;
  border: 2px solid var(--accent);
  color: var(--accent);
  font-weight: 700;
}

.calendar .locked {
  background: #f4ece4;
  border-color: var(--stroke);
  color: var(--muted);
  opacity: 0.85;
}

.calendar .unlocked {
  background: #fffbf5;
  border: 1.5px dashed var(--accent);
  color: var(--accent);
}
.calendar .locked:hover {
  background: #faede2;
  border-color: var(--accent);
  cursor: pointer;
  transform: translateY(-1px);
}
.calendar .unlocked:hover {
  background: #fdf6ec;
  border-style: solid;
  cursor: pointer;
  transform: translateY(-1px);
}
.calendar button.future {
  opacity: 0.35;
  cursor: not-allowed;
  background: transparent;
  border-color: var(--stroke);
}
.grid button.locked {
  opacity: 0.45;
  cursor: not-allowed;
  background: #f1f5f9;
  color: #94a3b8;
  border-color: #e2e8f0;
}
.grid button.current {
  border: 2px solid var(--accent);
  font-weight: 700;
  color: var(--accent);
  background: #e6f4f1;
  box-shadow: 0 0 0 2px rgba(30, 90, 82, 0.15);
}


.daily-today-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card-soft);
  border: 1.5px solid var(--stroke);
  border-radius: 14px;
  margin: 14px 0 16px;
  flex-wrap: wrap;
}

.daily-credits-pill {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--accent);
}

.badge {
  padding: 12px;
  border-bottom: 1px solid var(--stroke);
  font-weight: 500;
}

.badge.locked {
  opacity: 0.5;
}

#notice {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: #181528;
  color: #ffffff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  pointer-events: none;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.2s;
}

#notice:not(:empty) {
  opacity: 1;
}

dialog {
  max-width: 420px;
  border: 1px solid var(--stroke-strong);
  border-radius: 20px;
  padding: 24px;
  color: var(--text);
  background: var(--card);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

dialog::backdrop {
  background: rgba(24, 21, 40, 0.45);
}

@media (max-width: 600px) {
  .site-topbar {
    height: 48px;
    padding: 0 8px;
    gap: 6px;
  }
  .ww-home-link {
    font-size: 13.5px;
    padding: 5px 8px;
    font-weight: 700;
  }
  .ww-home-link span {
    display: none;
  }
  .brand-sep {
    display: none;
  }
  .game-brand-btn strong {
    display: none;
  }
  .nav-pill {
    padding: 4px 8px;
    font-size: 11.5px;
    min-height: 28px;
  }
  body.playing-screen main {
    height: calc(100dvh - 48px);
    padding: 8px 10px;
  }
  .play-hud {
    padding: 6px 10px;
  }
  .level-badge {
    font-size: 15px;
  }
  .hud-center {
    font-size: 12px;
    padding: 3px 8px;
  }
  .play-toolbar button {
    min-height: 36px;
    padding: 6px 10px;
    font-size: 12.5px;
  }
}


/* Unified Wonderworld Games Brand Pill */
.ww-home-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: -0.2px;
  padding: 5px 12px 5px 6px;
  border-radius: 999px;
  background: color-mix(in srgb, currentColor 8%, transparent);
  border: 1px solid color-mix(in srgb, currentColor 18%, transparent);
  color: inherit;
  transition: all 0.18s ease;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1;
}
.ww-home-pill:hover {
  background: color-mix(in srgb, currentColor 14%, transparent);
  border-color: color-mix(in srgb, currentColor 32%, transparent);
  transform: translateY(-1px);
  color: inherit;
}
.ww-home-pill .ww-logo-icon {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  flex-shrink: 0;
  display: block;
}
.ww-home-pill .ww-text-short {
  display: none;
}
@media (max-width: 600px) {
  .ww-home-pill {
    padding: 5px 9px 5px 5px;
    gap: 5px;
    font-size: 12.5px;
  }
  .ww-home-pill .ww-text-full {
    display: none;
  }
  .ww-home-pill .ww-text-short {
    display: inline;
  }
}
