/* ============================================================
   Paint It All!  —  styles
   No external fonts / images. Everything is CSS.
   ============================================================ */

/* ---------------------------- palette ---------------------- */
:root {
  --ink:          #2c2340;
  --ink-soft:     #6b6086;
  --card:         #ffffff;
  --card-edge:    #e6e0f2;

  --easy:         #3ecf6d;
  --easy-deep:    #1fa851;
  --medium:       #ff9f1c;
  --medium-deep:  #e07a00;
  --hard:         #a05cff;
  --hard-deep:    #7132d6;

  --lock:         #cfc9dd;
  --lock-ink:     #8e87a3;

  --sky1:         #7ee8fa;
  --sky2:         #b8f2c9;
  --sky3:         #ffe9a8;
  --sky4:         #ffb3d9;

  --gold:         #ffc93c;

  --r-lg:         26px;
  --r-md:         18px;
  --r-sm:         12px;

  --shadow:       0 6px 0 rgba(44, 35, 64, .16);
  --shadow-soft:  0 10px 26px rgba(44, 35, 64, .14);

  --font: ui-rounded, "SF Pro Rounded", "Hiragino Maru Gothic ProN",
          "Comic Sans MS", "Chalkboard SE", "Segoe UI", system-ui,
          -apple-system, "Helvetica Neue", Arial, sans-serif;
}

/* ---------------------------- reset ------------------------ */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(160deg, var(--sky1) 0%, var(--sky2) 38%, var(--sky3) 68%, var(--sky4) 100%);
  background-attachment: fixed;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  margin: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
button:disabled { cursor: default; }

h1, h2, p { margin: 0; }

/* ------------------------- screen frame -------------------- */
#app {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  overflow: hidden;
}

.screen {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: none;
  flex-direction: column;
  min-height: 0;
}
.screen.is-active { display: flex; }

/* ============================================================
   HOME
   ============================================================ */
.screen--home {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  align-items: center;
  justify-content: center;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
}
.screen--home::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  background:
    radial-gradient(closest-side, rgba(255,255,255,.55), rgba(255,255,255,0)) 12% 18% / 34% 24% no-repeat,
    radial-gradient(closest-side, rgba(255,255,255,.42), rgba(255,255,255,0)) 88% 76% / 40% 28% no-repeat,
    radial-gradient(closest-side, rgba(255,255,255,.35), rgba(255,255,255,0)) 70% 8%  / 26% 20% no-repeat;
}

.home-inner {
  position: relative;
  width: 100%;
  max-width: 520px;
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.home-head { text-align: center; }

.title {
  font-size: clamp(2.1rem, 9vw, 3.2rem);
  line-height: 1.05;
  letter-spacing: .5px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: .3em;
}
.title-brush {
  font-size: 1.05em;
  display: inline-block;
  animation: brushWag 2.6s ease-in-out infinite;
}
@keyframes brushWag {
  0%, 100% { transform: rotate(-12deg); }
  50%      { transform: rotate(14deg) translateY(-4px); }
}
.title-text { display: inline-flex; gap: .28em; flex-wrap: wrap; justify-content: center; }
.tw {
  display: inline-block;
  -webkit-text-stroke: 3px #fff;
  paint-order: stroke fill;
  text-shadow: 0 5px 0 rgba(44, 35, 64, .18);
}
.tw1 { color: #ff4f81; transform: rotate(-4deg); }
.tw2 { color: #ffb020; transform: rotate(3deg); }
.tw3 { color: #6a5cff; transform: rotate(-2deg); }

.tagline {
  margin-top: 12px;
  font-size: clamp(.95rem, 3.6vw, 1.1rem);
  font-weight: 700;
  color: #4a3f66;
  background: rgba(255,255,255,.6);
  border-radius: 999px;
  padding: 8px 16px;
  display: inline-block;
}

.diff-cards { display: flex; flex-direction: column; gap: 14px; }

.diff-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px 18px;
  text-align: left;
  border-radius: var(--r-lg);
  background: var(--card);
  border-bottom: 6px solid var(--accent-deep, #ccc);
  box-shadow: var(--shadow-soft);
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
}
.diff-card--easy   { --accent: var(--easy);   --accent-deep: var(--easy-deep); }
.diff-card--medium { --accent: var(--medium); --accent-deep: var(--medium-deep); }
.diff-card--hard   { --accent: var(--hard);   --accent-deep: var(--hard-deep); }

.diff-card:hover  { transform: translateY(-3px); box-shadow: 0 16px 30px rgba(44,35,64,.2); }
.diff-card:active { transform: translateY(2px); border-bottom-width: 3px; }
.diff-card:focus-visible { outline: 4px solid var(--accent); outline-offset: 3px; }

.diff-emoji {
  font-size: 2rem;
  width: 56px; height: 56px;
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: rgba(0,0,0,.05);   /* overridden per difficulty below */
}
.diff-card--easy   .diff-emoji { background: #e2fbea; }
.diff-card--medium .diff-emoji { background: #fff0d8; }
.diff-card--hard   .diff-emoji { background: #f0e6ff; }

.diff-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.diff-name { font-size: 1.5rem; font-weight: 800; color: var(--accent-deep); line-height: 1.1; }
.diff-sub  { font-size: .85rem; font-weight: 700; color: var(--ink-soft); }

.diff-right { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.diff-count { font-size: 1rem; font-weight: 800; color: var(--ink); white-space: nowrap; }
.diff-bar {
  display: block;
  width: 72px; height: 9px;
  border-radius: 999px;
  background: #eae5f3;
  overflow: hidden;
}
.diff-bar-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
  transition: width .35s ease;
}

.home-hint {
  text-align: center;
  font-size: .88rem;
  font-weight: 700;
  color: #4a3f66;
  opacity: .85;
}

/* ============================================================
   TOP BARS (shared by levels + game)
   ============================================================ */
.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  background: rgba(255,255,255,.82);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(44,35,64,.12);
  position: relative;
  z-index: 2;
}

.icon-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 10px 14px;
  border-radius: 999px;
  font-weight: 800;
  font-size: .95rem;
  background: #f1edf9;
  color: var(--ink);
  border-bottom: 3px solid #ded6ee;
  transition: transform .1s ease, background .12s ease;
}
.icon-btn:hover  { background: #e7e0f6; }
.icon-btn:active { transform: translateY(2px); border-bottom-width: 1px; }
.icon-btn:focus-visible { outline: 3px solid var(--hard); outline-offset: 2px; }
.icon-glyph { font-size: .85em; }

.bar-title {
  flex: 1 1 auto;
  text-align: center;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--ink);
}
.bar-count {
  flex: 0 0 auto;
  font-size: .95rem;
  font-weight: 800;
  color: var(--ink-soft);
  background: #f1edf9;
  border-radius: 999px;
  padding: 8px 12px;
  white-space: nowrap;
}

/* ============================================================
   LEVEL SELECT
   ============================================================ */
.screen--levels { background: linear-gradient(170deg, #eaf6ff 0%, #f6f0ff 55%, #fff0f6 100%); }
.screen--levels.diff-easy   { background: linear-gradient(170deg, #e8fbef 0%, #f4fff7 60%, #eefaf1 100%); }
.screen--levels.diff-medium { background: linear-gradient(170deg, #fff4e0 0%, #fffaf0 60%, #fff1e6 100%); }
.screen--levels.diff-hard   { background: linear-gradient(170deg, #f3ebff 0%, #faf5ff 60%, #f7edff 100%); }

.levels-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 12px max(20px, env(safe-area-inset-bottom));
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 7px;
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
}

.lv {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0;
  border-radius: var(--r-sm);
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  font-size: clamp(.62rem, 2.2vw, .95rem);
  line-height: 1;
  border-bottom: 3px solid var(--card-edge);
  box-shadow: 0 2px 6px rgba(44,35,64,.09);
  overflow: hidden;
  transition: transform .1s ease, box-shadow .12s ease;
}
.lv:not(.lv--locked):hover  { transform: translateY(-2px); box-shadow: 0 8px 14px rgba(44,35,64,.18); }
.lv:not(.lv--locked):active { transform: translateY(2px); border-bottom-width: 1px; }
.lv:focus-visible { outline: 3px solid var(--hard); outline-offset: 2px; z-index: 1; }

.lv--done { color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.28); }
.lv--done .lv-check { font-size: 1.15em; line-height: 1; }
.lv--done .lv-num   { font-size: .78em; opacity: .95; margin-top: 1px; }

.lv--open { background: #fff; }
.lv--open .lv-num { font-size: 1.05em; }

.lv--locked {
  background: var(--lock);
  color: var(--lock-ink);
  border-bottom-color: #bdb6cd;
  box-shadow: none;
  opacity: .78;
  cursor: default;
  filter: saturate(.5);
}
.lv--locked .lv-check { font-size: .95em; }

.lv-star {
  position: absolute;
  top: 1px; right: 2px;
  font-size: .62em;
  line-height: 1;
  text-shadow: 0 1px 1px rgba(0,0,0,.3);
}

.levels-legend {
  max-width: 620px;
  margin: 18px auto 0;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  font-size: .78rem;
  font-weight: 700;
  color: var(--ink-soft);
}
.lg { display: inline-flex; align-items: center; gap: 5px; }
.lg-swatch { width: 14px; height: 14px; border-radius: 5px; display: inline-block; }
.lg-done { background: linear-gradient(135deg, #ff6b9d, #7a5cff); }
.lg-open { background: #fff; border: 2px solid var(--card-edge); }
.lg-lock { background: var(--lock); }
.lg-star { font-style: normal; }

/* ============================================================
   GAME
   ============================================================ */
.screen--game {
  background: linear-gradient(175deg, #f3f7ff 0%, #f8f4ff 55%, #fff4fa 100%);
  touch-action: none;
}

.bar--game { gap: 8px; }

.game-meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.game-label {
  font-size: clamp(.85rem, 3.4vw, 1.1rem);
  font-weight: 800;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.game-stats {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: clamp(.72rem, 3vw, .9rem);
  font-weight: 700;
  color: var(--ink-soft);
}
.game-stats b { color: var(--ink); font-size: 1.1em; }
.stat { white-space: nowrap; }
.stat-sep { opacity: .5; }

#stat-moves.is-over b { color: #ff4f6d; }
#stat-moves.is-pop b { animation: pop .28s ease; display: inline-block; }
@keyframes pop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.45); }
  100% { transform: scale(1); }
}

.game-actions { flex: 0 0 auto; display: flex; gap: 6px; }
.tool-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 7px 10px;
  min-width: 54px;
  border-radius: var(--r-sm);
  background: #f1edf9;
  border-bottom: 3px solid #ded6ee;
  font-size: .68rem;
  font-weight: 800;
  color: var(--ink);
  transition: transform .1s ease, background .12s ease;
}
.tool-glyph { font-size: 1.05rem; line-height: 1; }
.tool-label { line-height: 1.1; letter-spacing: .2px; }
.tool-btn:hover  { background: #e7e0f6; }
.tool-btn:active { transform: translateY(2px); border-bottom-width: 1px; }
.tool-btn:focus-visible { outline: 3px solid var(--hard); outline-offset: 2px; }

/* the canvas gets a definite box: absolutely filling its stage */
.board-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  margin: 10px 10px 6px;
}
#board {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* --------------------------- d-pad ------------------------- */
.dpad {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 8px;
  /* The fixed mute button sits bottom-left; the calc() keeps the ◀ arrow clear
     of it (44px button + 14px inset + breathing room) on narrow phones. */
  width: min(300px, 78vw, calc(100vw - 132px));
  margin: 0 auto;
  padding: 6px 0 max(12px, env(safe-area-inset-bottom));
}
.dbtn {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 5 / 4;
  min-height: 48px;
  border-radius: var(--r-md);
  background: #fff;
  color: #5a4d7a;
  font-size: 1.35rem;
  line-height: 1;
  border-bottom: 4px solid #ded6ee;
  box-shadow: 0 4px 12px rgba(44,35,64,.12);
  transition: transform .08s ease, background .1s ease;
}
.dbtn:hover  { background: #f6f2ff; }
.dbtn:active, .dbtn.is-held {
  transform: translateY(3px);
  border-bottom-width: 1px;
  background: #ece4ff;
  color: var(--hard-deep);
}
.dbtn:focus-visible { outline: 3px solid var(--hard); outline-offset: 2px; }
.dbtn--u { grid-column: 2; grid-row: 1; }
.dbtn--l { grid-column: 1; grid-row: 2; }
.dbtn--d { grid-column: 2; grid-row: 2; }
.dbtn--r { grid-column: 3; grid-row: 2; }

/* ============================================================
   WIN OVERLAY
   ============================================================ */
.overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(44, 35, 64, .55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fadeIn .18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.overlay-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  max-height: 100%;
  overflow-y: auto;
  text-align: center;
  padding: 26px 22px 22px;
  border-radius: var(--r-lg);
  background: #fff;
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
  animation: popIn .32s cubic-bezier(.2, 1.4, .5, 1);
}
@keyframes popIn {
  from { transform: scale(.7) translateY(20px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.confetti { position: absolute; top: 0; left: 0; right: 0; height: 0; pointer-events: none; }
.confetti i {
  position: absolute;
  top: 6px;
  width: 9px; height: 14px;
  border-radius: 3px;
  opacity: .9;
  animation: fall 2.2s linear infinite;
}
.confetti .c1 { left: 8%;  background: #ff4f81; animation-delay: 0s;   }
.confetti .c2 { left: 24%; background: #ffb020; animation-delay: .35s; }
.confetti .c3 { left: 43%; background: #3ecf6d; animation-delay: .7s;  }
.confetti .c4 { left: 61%; background: #38b6ff; animation-delay: .15s; }
.confetti .c5 { left: 78%; background: #a05cff; animation-delay: .55s; }
.confetti .c6 { left: 91%; background: #ff6bd6; animation-delay: .9s;  }
@keyframes fall {
  0%   { transform: translateY(-20px) rotate(0deg); opacity: 0; }
  15%  { opacity: .95; }
  100% { transform: translateY(230px) rotate(420deg); opacity: 0; }
}

.win-emoji { font-size: 3.2rem; line-height: 1; animation: brushWag 1.6s ease-in-out infinite; }
.win-title {
  margin-top: 6px;
  font-size: clamp(1.5rem, 6.5vw, 2rem);
  font-weight: 800;
  color: #6a5cff;
  -webkit-text-stroke: 0;
}
.win-star {
  font-size: 3rem;
  line-height: 1.1;
  margin-top: 4px;
  animation: popIn .5s .12s backwards cubic-bezier(.2, 1.6, .5, 1);
  filter: drop-shadow(0 4px 8px rgba(255, 201, 60, .6));
}
.win-stats {
  margin-top: 8px;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--ink);
}
.win-note {
  margin-top: 6px;
  font-size: .9rem;
  font-weight: 700;
  color: var(--ink-soft);
  min-height: 1.1em;
}

.win-buttons { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.big-btn {
  padding: 15px 18px;
  border-radius: var(--r-md);
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
  border-bottom: 5px solid rgba(0,0,0,.22);
  box-shadow: var(--shadow-soft);
  transition: transform .1s ease, filter .12s ease;
}
.big-btn:hover  { filter: brightness(1.06); }
.big-btn:active { transform: translateY(3px); border-bottom-width: 2px; }
.big-btn:focus-visible { outline: 4px solid var(--gold); outline-offset: 3px; }
.big-btn--next   { background: #3ecf6d; }
.big-btn--replay { background: #ff9f1c; }
.big-btn--levels { background: #7a6cff; }

/* ============================================================
   responsive tweaks
   ============================================================ */
@media (max-width: 400px) {
  .level-grid { gap: 5px; }
  .lv { border-radius: 9px; }
  .icon-label { display: none; }
  .icon-btn { padding: 10px 12px; }
  .tool-btn { min-width: 46px; padding: 6px 8px; }
}

@media (max-height: 620px) {
  .dbtn { min-height: 42px; aspect-ratio: 2 / 1; }
  .dpad { width: min(280px, 74vw, calc(100vw - 132px)); gap: 6px; }   /* same mute-button clearance */
  .win-emoji { font-size: 2.4rem; }
  .win-star { font-size: 2.2rem; }
  .overlay-card { padding: 18px 18px 16px; }
  .big-btn { padding: 12px 16px; font-size: 1rem; }
}

/* landscape phones: put the d-pad beside the board */
@media (orientation: landscape) and (max-height: 560px) {
  .screen--game { flex-direction: column; }
  .dpad { width: min(360px, 60vw); padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .dbtn { min-height: 38px; aspect-ratio: 3 / 1; font-size: 1.1rem; }
  .board-stage { margin: 6px 8px 2px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* ---------- sound on/off button (bottom-left; other corners are busy) ---------- */
.mute-btn {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 550;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0;
  background: rgba(255, 255, 255, 0.65);
  box-shadow: 0 3px 8px rgba(44, 35, 64, .2);
  backdrop-filter: blur(2px);
}
.mute-btn:hover { background: rgba(255, 255, 255, 0.9); }

/* ---------- leaderboard widget (home + level select; hidden while playing) ----------
   Top offset clears the level-select top bar so the pill never sits on the title. */
#paint-lb {
  position: fixed;
  top: 68px;
  right: 12px;
  z-index: 20;
  text-align: right;
}
#paint-lb-toggle {
  background: #ffffff;
  border-bottom: 2px solid var(--card-edge);
  border-radius: 999px;
  color: var(--ink);
  font-family: var(--font);
  font-weight: 800;
  font-size: .9rem;
  padding: 8px 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
#paint-lb-panel {
  margin-top: 8px;
  width: 280px;
  max-height: 70vh;
  overflow: auto;
  text-align: left;
}

/* ============================================================
   EMBEDDED IN THE paint.html SHELL
   ============================================================ */
/* Embedded in the paint.html shell: its floating HOME/BACK sticker (top-left)
   replaces the bars' own back buttons, so hide them and pad the bars clear. */
.pt-embedded #btn-levels-back,
.pt-embedded #btn-game-back { display: none; }
.pt-embedded .bar { padding-left: 128px; }
@media (max-width: 480px) {
  .pt-embedded .bar { padding-left: 104px; }
}

/* The game bar carries the most (label + moves/par + undo + restart) and the
   sticker's padding eats the space the hidden ◀ used to have. On phone widths
   tighten the type a notch so "Moves: n / Par: n" never spills under the tools. */
@media (max-width: 400px) {
  .pt-embedded .bar--game { gap: 6px; }
  .pt-embedded .game-label { font-size: .8rem; }
  .pt-embedded .game-stats { font-size: .68rem; }
}
