@font-face {
  font-family: "Fredoka";
  src: url("../fonts/fredoka-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fredoka";
  src: url("../fonts/fredoka-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #151228;
  --ink2: #241c44;
  --card: rgba(255, 255, 255, 0.07);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f5f0ff;
  --dim: #b9b0d6;
  --amber: #ffb65c;
  --mint: #7be0c8;
  --coral: #ff7d6e;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  font-family: "Fredoka", "Trebuchet MS", "Segoe UI", sans-serif;
  font-weight: 500;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

#app {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(120% 70% at 85% -10%, rgba(255, 182, 92, 0.16), transparent 60%),
    radial-gradient(90% 60% at 0% 100%, rgba(123, 224, 200, 0.13), transparent 60%),
    linear-gradient(180deg, var(--ink) 0%, var(--ink2) 100%);
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: var(--safe-t) var(--safe-r) 0 var(--safe-l);
}
.screen[hidden], .modal[hidden], .toast[hidden], .loading[hidden] { display: none; }

/* ---------- loading ---------- */
.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 24px;
}
.loading .mark { width: 84px; height: 84px; }
.loading h1 { margin: 6px 0 0; font-size: 30px; font-weight: 700; letter-spacing: 0.3px; }
.loading p { margin: 0; color: var(--dim); font-size: 16px; }
.loadbar {
  width: min(240px, 60vw);
  height: 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
  margin-top: 8px;
}
.loadbar i {
  display: block;
  height: 100%;
  width: 4%;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--mint), var(--amber));
  transition: width 0.15s linear;
}

/* ---------- top bars ---------- */
.top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  min-height: 56px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 20px; margin-right: auto; white-space: nowrap; }
.brand svg { width: 30px; height: 30px; flex: 0 0 auto; }

.level {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 14px;
  white-space: nowrap;
}
.lvnum b { color: var(--amber); font-weight: 700; }
.lvbar { width: 56px; height: 6px; border-radius: 6px; background: rgba(255, 255, 255, 0.14); overflow: hidden; }
.lvbar i { display: block; height: 100%; width: 0; border-radius: 6px; background: linear-gradient(90deg, var(--mint), var(--amber)); }
.lvpts { color: var(--dim); font-variant-numeric: tabular-nums; }

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--mint); outline-offset: 2px; }

.icon {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
}
.icon svg { width: 22px; height: 22px; }
.icon:active, .pill:active, .chip:active { transform: scale(0.94); }
.icon.fav svg path { fill: transparent; }
.icon.fav[aria-pressed="true"] { color: var(--amber); }
.icon.fav[aria-pressed="true"] svg path { fill: var(--amber); }
.icon[hidden] { display: none; }

.pill {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 7px;
  height: 42px;
  padding: 0 14px 0 12px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  font-weight: 700;
  font-size: 15px;
}
.pill svg { width: 18px; height: 18px; color: var(--amber); }

.playtop h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 0 1 auto;
}
.status {
  flex: 1 100 0px;
  min-width: 0;
  text-align: right;
  font-size: 14px;
  color: var(--mint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.status:empty { visibility: hidden; }

/* ---------- chips ---------- */
.chips {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 2px 14px 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 15px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--dim);
  font-size: 15px;
  white-space: nowrap;
}
.chip svg { width: 16px; height: 16px; }
.chip[aria-pressed="true"] { background: var(--amber); border-color: var(--amber); color: #2a1c05; font-weight: 700; }
.chip.surprise { color: var(--mint); border-color: rgba(123, 224, 200, 0.45); }

/* ---------- grid ---------- */
.grid {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 12px;
  align-content: start;
  padding: 4px 14px calc(22px + var(--safe-b));
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}
.card { position: relative; }
.card[hidden] { display: none; }
.cardmain {
  display: block;
  width: 100%;
  text-align: left;
  border-radius: 22px;
  padding: 7px 7px 10px;
  background: var(--card);
  border: 1px solid var(--line);
  transition: transform 0.12s ease, background 0.12s ease;
}
.cardmain:hover { background: rgba(255, 255, 255, 0.11); }
.cardmain:active { transform: scale(0.96); }
.cardmain canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 17px;
  background: #1c1736;
}
.cardname {
  display: block;
  padding: 8px 6px 0;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cardcat { display: block; padding: 1px 6px 0; font-size: 12.5px; color: var(--dim); }
.cardfav {
  position: absolute;
  top: 13px;
  right: 13px;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(21, 18, 40, 0.62);
  color: #fff;
}
.cardfav svg { width: 18px; height: 18px; }
.cardfav svg path { fill: transparent; }
.cardfav[aria-pressed="true"] { color: var(--amber); }
.cardfav[aria-pressed="true"] svg path { fill: var(--amber); }
.empty { grid-column: 1 / -1; text-align: center; color: var(--dim); padding: 40px 16px; font-size: 16px; }
.empty[hidden] { display: none; }

/* ---------- play ---------- */
.stagewrap { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; }
#stage { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hint {
  position: absolute;
  left: 50%;
  bottom: calc(16px + var(--safe-b));
  transform: translateX(-50%);
  max-width: 90%;
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(21, 18, 40, 0.74);
  border: 1px solid var(--line);
  font-size: 15px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}
.hint.show { opacity: 1; }

/* ---------- settings ---------- */
.modal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(10, 8, 22, 0.66);
}
.sheet {
  width: min(360px, 100%);
  max-height: 100%;
  overflow-y: auto;
  border-radius: 24px;
  padding: 20px;
  background: #2a2150;
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.sheet h3 { margin: 0 0 10px; font-size: 22px; font-weight: 700; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  border-bottom: 1px solid var(--line);
  font-size: 17px;
}
.switch {
  appearance: none;
  -webkit-appearance: none;
  width: 52px;
  height: 30px;
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.2);
  position: relative;
  cursor: pointer;
  margin: 0;
  flex: 0 0 auto;
  transition: background 0.15s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}
.switch:checked { background: var(--mint); }
.switch:checked::after { transform: translateX(22px); }
.ghost {
  height: 38px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 125, 110, 0.6);
  color: var(--coral);
  font-size: 15px;
}
.fine { color: var(--dim); font-size: 14px; line-height: 1.4; margin: 12px 0 14px; }
.primary {
  width: 100%;
  height: 48px;
  border-radius: 16px;
  background: var(--amber);
  color: #2a1c05;
  font-weight: 700;
  font-size: 17px;
}

/* ---------- toast ---------- */
.toast {
  position: absolute;
  left: 50%;
  top: calc(66px + var(--safe-t));
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--mint);
  color: #0d2b25;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* ---------- small and extreme viewports ---------- */
@media (max-width: 520px) {
  .pill span { display: none; }
  .pill { padding: 0 12px; }
  .playtop { gap: 8px; }
}
@media (max-width: 380px) {
  .brand span { font-size: 17px; }
  .lvbar { display: none; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .top { padding: 8px 10px; gap: 8px; }
  .chips { padding-left: 10px; padding-right: 10px; }
  .grid { padding-left: 10px; padding-right: 10px; }
}
@media (max-width: 250px) {
  .level { display: none; }
  .pill span { display: none; }
  .pill { padding: 0 12px; }
}
@media (max-height: 300px) {
  .top { min-height: 44px; padding-top: 4px; padding-bottom: 4px; }
  .icon, .pill { height: 36px; }
  .icon { width: 36px; }
  .chips { padding-bottom: 6px; }
  .chip { height: 32px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
  .cardcat { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .cardmain, .hint, .loadbar i, .switch, .switch::after { transition: none; }
}
