:root {
  color-scheme: light;
  --bg: #b9c6ff;
  --panel: rgba(255, 249, 238, 0.96);
  --line: rgba(90, 30, 60, 0.14);
  --text: #3a1d38;
  --muted: #7d6684;
  --gold: #f4b93a;
  --on-gold: #241505;
  --red: #e0393e;
  --sans: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

canvas#game { position: fixed; inset: 0; display: block; }

button { font: inherit; color: inherit; cursor: pointer; }

.hud {
  color: #fff7ea;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  padding: max(8px, env(safe-area-inset-top)) 10px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 5;
}
.hud[hidden] { display: none; }
.icon {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(10, 6, 22, 0.55);
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 700;
}
.icon:active { transform: scale(0.94); }
.hud-mid { flex: 1; min-width: 0; display: grid; gap: 5px; justify-items: center; }
.hud-mid { max-width: 360px; margin: 0 auto; padding: 6px 14px 8px; border-radius: 16px; background: rgba(40, 18, 60, 0.62); }
.hud-level { margin: 0; font-weight: 800; font-size: 15px; letter-spacing: 0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.bar { width: min(240px, 100%); height: 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, #f07c2e, var(--gold)); transition: width 0.25s ease; }

.hint-line {
  position: fixed;
  left: 50%;
  top: 62px;
  transform: translateX(-50%);
  margin: 0;
  max-width: min(92vw, 520px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 7px 14px;
  border-radius: 12px;
  background: rgba(40, 18, 60, 0.82);
  color: #fff7ea;
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 14px;
  line-height: 1.35;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
  z-index: 4;
}
.hint-line.show { opacity: 1; }

#ui { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 10; padding: 16px; }
#ui > * { pointer-events: auto; }

.panel {
  width: min(420px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 26px 22px 22px;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 24px 70px rgba(70, 30, 90, 0.35), 0 0 0 4px rgba(198, 47, 61, 0.9), 0 0 0 7px #f5be3c;
  text-align: center;
  animation: rise 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(0.96); } to { opacity: 1; transform: none; } }
.panel.wide { width: min(620px, 100%); }

.logo {
  margin: 0;
  font-size: clamp(64px, 18vw, 104px);
  line-height: 0.95;
  font-weight: 900;
  letter-spacing: -0.03em;
  background: linear-gradient(180deg, #f5be3c, #e8792e 55%, #c62f3d);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 rgba(120, 30, 40, 0.35));
}
.logo-sub { margin: -2px 0 0; font-size: 22px; font-weight: 900; letter-spacing: 0.12em; text-transform: uppercase; color: #c62f3d; }
.ornament-line { width: 160px; height: 18px; margin: 6px auto 10px; display: block; }
.tag { margin: 0 0 20px; color: var(--muted); font-size: 15px; line-height: 1.45; }
h2 { margin: 4px 0 6px; font-size: 30px; font-weight: 900; }
.sub { margin: 0 0 18px; color: var(--muted); font-size: 15px; }

.btn {
  width: 100%;
  min-height: 52px;
  margin-top: 10px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(90, 30, 60, 0.06);
  font-weight: 800;
  font-size: 17px;
}
.btn.primary { background: linear-gradient(180deg, #ffd05e, var(--gold)); color: var(--on-gold); border-color: transparent; box-shadow: 0 8px 24px rgba(244, 185, 58, 0.3); }
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: 3px solid #c62f3d; outline-offset: 2px; }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }

.chips { display: flex; gap: 8px; justify-content: center; margin-top: 16px; }
.chip { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: none; font-weight: 700; font-size: 13px; color: var(--muted); }
.chip[aria-pressed="true"] { background: rgba(90, 30, 60, 0.1); color: var(--text); }

.clean { margin: -4px 0 10px; color: #c0661a; font-weight: 800; font-size: 15px; }
.stars { display: flex; justify-content: center; gap: 6px; margin: 2px 0 8px; font-size: 46px; line-height: 1; }
.stars span { color: rgba(90, 30, 60, 0.14); transform: scale(0.2); opacity: 0; animation: starpop 0.42s cubic-bezier(0.3, 1.6, 0.5, 1) forwards; }
.stars span.on { color: #ffd23f; text-shadow: 0 0 18px rgba(255, 200, 60, 0.6), 0 3px 0 #c07a10; }
.stars span:nth-child(2) { transform: translateY(-8px) scale(0.2); font-size: 1.15em; }
@keyframes starpop { to { opacity: 1; transform: none; } }
.stars span:nth-child(2) { animation-name: starpop2; }
@keyframes starpop2 { to { opacity: 1; transform: translateY(-8px); } }
.stars.small { position: absolute; right: 3px; bottom: 1px; gap: 0; margin: 0; font-size: 10px; }
.stars.small span { animation: none; opacity: 1; transform: none; text-shadow: 0 1px 2px #000; }
.stars.small span.on { text-shadow: 0 1px 2px #000; }
.stars.small span:nth-child(2) { transform: none; font-size: 1em; }
.stars-total { margin: 10px 0 0; color: #c0661a; font-weight: 800; font-size: 15px; }
.almost { margin: 0 0 6px; color: #c0661a; font-weight: 900; font-size: 20px; }

.carpet-progress { margin: 6px auto 4px; width: 100%; }
.panel .bar { background: rgba(90, 30, 60, 0.12); margin: 0 auto; }
.carpet-progress p { margin: 0 0 6px; font-size: 14px; color: var(--muted); }

.preview { display: block; margin: 4px auto 12px; border-radius: 10px; image-rendering: pixelated; background: #fff3dc; padding: 8px; box-shadow: 0 0 0 4px #c62f3d, 0 0 0 6px #f5be3c, 0 12px 26px rgba(70, 30, 90, 0.3); }

.carpet {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 6px;
  padding: 12px;
  border-radius: 18px;
  background:
    repeating-linear-gradient(45deg, rgba(224, 57, 62, 0.25) 0 6px, rgba(244, 185, 58, 0.25) 6px 12px) border-box;
  border: 6px solid transparent;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.3);
  margin: 10px 0 4px;
}
.tile {
  aspect-ratio: 1;
  border-radius: 10px;
  border: none;
  padding: 0;
  background: rgba(90, 30, 60, 0.12);
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
}
.tile canvas { width: 100%; height: 100%; image-rendering: pixelated; }
.tile.locked { color: rgba(90, 30, 60, 0.3); font-weight: 800; font-size: 18px; cursor: default; }
.tile.next { outline: 3px solid #c62f3d; color: #c62f3d; background: #fff3dc; }
.tile .num { position: absolute; left: 4px; bottom: 2px; font-size: 10px; font-weight: 800; color: rgba(255, 255, 255, 0.75); text-shadow: 0 1px 2px #000; }

.foot { margin: 16px 0 0; font-size: 12px; color: var(--muted); }
.foot a { color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .panel { animation: none; }
}

.panel { backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }

/* short screens (a phone on its side, a small game frame): everything must fit without scrolling */
@media (max-height: 560px) {
  .panel { padding: 16px 18px 14px; }
  .logo { font-size: 52px; }
  .ornament-line { margin: 2px auto 4px; height: 12px; }
  .tag { margin-bottom: 10px; font-size: 13px; }
  h2 { font-size: 24px; }
  .sub { margin-bottom: 10px; font-size: 13px; }
  .btn { min-height: 42px; margin-top: 7px; font-size: 15px; }
  .chips { margin-top: 10px; }
  .foot { margin-top: 8px; }
  .preview { max-height: 110px; width: auto; }
}
