:root {
  color-scheme: dark;
  --bg: #1a1233;
  --panel: rgba(24, 16, 44, 0.9);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f6efe2;
  --muted: #b9add0;
  --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 {
  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-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(10, 6, 22, 0.78);
  border: 1px solid var(--line);
  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 80px rgba(0, 0, 0, 0.55);
  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, #ffe08a, var(--gold) 55%, #e0802e);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 18px rgba(244, 185, 58, 0.25));
}
.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(255, 255, 255, 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 #fff; 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(255, 255, 255, 0.12); color: var(--text); }

.clean { margin: -4px 0 10px; color: var(--gold); font-weight: 800; font-size: 15px; }
.almost { margin: 0 0 6px; color: var(--gold); font-weight: 900; font-size: 20px; }

.carpet-progress { margin: 6px auto 4px; width: 100%; }
.carpet-progress p { margin: 0 0 6px; font-size: 14px; color: var(--muted); }

.preview { display: block; margin: 4px auto 12px; border-radius: 14px; image-rendering: pixelated; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45); }

.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(10, 6, 22, 0.7);
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
}
.tile canvas { width: 100%; height: 100%; image-rendering: pixelated; }
.tile.locked { color: rgba(255, 255, 255, 0.25); font-weight: 800; font-size: 18px; cursor: default; }
.tile.next { outline: 2px solid var(--gold); color: var(--gold); }
.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; }
}
