/* =========================================================================
   Bilo Arcade — shell styles
   Dark "arcade at night" ground, Bilo purple + spark yellow, bright cartridges.
   Single theme on purpose: the games set their own screen colours.
   ========================================================================= */

:root {
  --ground: #1B1538;
  --ground-2: #241D48;
  --panel: #2C2558;
  --panel-2: #3A3170;
  --line: #4A4185;
  --ink: #F4F1FF;
  --ink-2: #B7B0DA;
  --brand: #7C63FF;
  --brand-deep: #5B3FE8;
  --spark: #FFAE18;
  --spark-ink: #2B1D00;
  --success: #2ED38A;
  --danger: #FF5C7A;
  --radius: 16px;
  --font-ui: "Nunito", "Segoe UI", system-ui, sans-serif;
  --font-display: "Fredoka", "Nunito", sans-serif;
  --font-pixel: "Press Start 2P", ui-monospace, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--spark); outline-offset: 2px; }
[hidden] { display: none !important; }

#app { min-height: 100%; display: flex; flex-direction: column; }
.view { flex: 1; display: flex; flex-direction: column; }

/* ------------------------------------------------------------ menu ---- */
.view-menu {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: calc(14px + var(--safe-top)) 18px calc(20px + var(--safe-bottom));
  gap: 18px;
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.logo { display: flex; align-items: center; gap: 10px; }
.logo img { border-radius: 9px; }
.wordmark { font-family: var(--font-display); font-weight: 600; font-size: 1.35rem; letter-spacing: .01em; }
.wordmark b { font-weight: 700; color: var(--spark); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.iconbtn {
  min-width: 44px; height: 44px; padding: 0 12px;
  border-radius: 12px; background: var(--panel);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1rem;
}
.iconbtn:active { transform: translateY(1px); background: var(--panel-2); }
.chip {
  height: 44px; padding: 0 14px 0 10px; border-radius: 999px;
  background: var(--panel); display: inline-flex; align-items: center; gap: 8px;
  font-weight: 800; max-width: 46vw;
}
.chip .emoji { font-size: 1.25rem; }
.chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.hero { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.tagline { margin: 0; color: var(--ink-2); font-weight: 600; }
.stars-total { margin: 0; font-family: var(--font-display); font-weight: 600; color: var(--spark); font-variant-numeric: tabular-nums; }

/* cartridges grid */
.cartridges {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
}
.cart {
  --c: var(--brand);
  position: relative;
  display: flex; flex-direction: column; gap: 10px;
  text-align: left;
  background: var(--c);
  border-radius: 14px 14px 8px 8px;
  padding: 18px 12px 14px;
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.28), 0 10px 24px rgba(0,0,0,.35);
  transition: transform .12s ease;
  min-height: 210px;
}
.cart::before {
  content: ""; position: absolute; left: 16px; right: 16px; top: 0; height: 9px;
  background: rgba(0,0,0,.3); border-radius: 0 0 5px 5px;
}
.cart::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 14px;
  border-radius: 0 0 8px 8px;
  background: repeating-linear-gradient(90deg, rgba(0,0,0,.2) 0 4px, transparent 4px 10px);
}
.cart:hover { transform: translateY(-3px); }
.cart:active { transform: translateY(1px); }
.cart-label {
  background: #FAF8FF; color: #1B1538; border-radius: 8px;
  padding: 12px 10px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  text-align: center;
}
.cart-label .emoji { font-size: 2rem; line-height: 1; }
.cart-label .title { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; line-height: 1.15; }
.cart.pixel .cart-label { background: #9BBC0F; color: #0F380F; }
.cart.pixel .cart-label .title { font-family: var(--font-pixel); font-size: .62rem; line-height: 1.6; text-transform: uppercase; }
.cart-short { margin: 0; font-size: .82rem; line-height: 1.35; color: rgba(255,255,255,.92); font-weight: 600; min-height: 2.7em; }
.cart-meta { display: flex; justify-content: space-between; align-items: center; font-size: .8rem; font-weight: 800; color: rgba(255,255,255,.9); }
.cart-meta .stars { letter-spacing: .05em; color: var(--spark); font-size: .95rem; }
.cart-meta .stars .off { color: rgba(255,255,255,.35); }
.cart.soon { opacity: .55; cursor: default; }
.cart.soon:hover { transform: none; }
.cart .ribbon {
  position: absolute; top: 14px; right: -6px; background: var(--spark); color: var(--spark-ink);
  font-size: .68rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  padding: 3px 10px; border-radius: 6px 0 0 6px; box-shadow: 0 2px 6px rgba(0,0,0,.3);
}

.foot { margin-top: auto; color: var(--ink-2); font-size: .8rem; text-align: center; font-weight: 600; }

/* ------------------------------------------------------------ game ---- */
.view-game { flex: 0 0 auto; height: 100dvh; max-height: 100dvh; overflow: hidden; padding: var(--safe-top) 12px var(--safe-bottom); background: var(--ground); }
.hud {
  display: grid; grid-template-columns: 44px 1fr auto 44px; align-items: center; gap: 10px;
  padding: 8px 0;
}
.hud-title { font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-score { font-family: var(--font-pixel); font-size: .8rem; color: var(--spark); font-variant-numeric: tabular-nums; white-space: nowrap; }
.stage {
  flex: 1; min-height: 0; position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 6px 0;
}
.stage canvas { border-radius: 8px; box-shadow: 0 0 0 5px #2C2558, 0 0 0 7px #4A4185, 0 14px 30px rgba(0,0,0,.45); image-rendering: pixelated; }

.controls { display: flex; justify-content: center; align-items: center; padding: 8px 0 12px; gap: 12px; min-height: 12px; }
.controls:empty { padding: 0; }
.ctl-hint { color: var(--ink-2); font-size: .8rem; font-weight: 700; }
.dpad { display: grid; grid-template-columns: repeat(3, 54px); grid-template-rows: repeat(3, 54px); gap: 4px; }
.dpad button {
  background: var(--panel); border-radius: 12px; font-size: 1.4rem; font-weight: 800;
  display: flex; align-items: center; justify-content: center; touch-action: none;
}
.dpad button:active { background: var(--brand); }
.dpad .blank { background: transparent; }
.turn2 { display: flex; justify-content: space-between; width: 100%; max-width: 640px; }
.turn2 .side { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.turn2 .side .who { font-size: .75rem; font-weight: 800; color: var(--ink-2); }
.turn2 .pair { display: flex; gap: 8px; }
.turn2 button {
  width: 72px; height: 64px; border-radius: 14px; background: var(--panel);
  font-size: 1.7rem; font-weight: 800; touch-action: none;
}
.turn2 button:active { background: var(--brand); }
.turn2 .p2 button:active { background: var(--success); color: #063; }

/* --------------------------------------------------------- overlay ---- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 6, 30, .72); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.overlay-card {
  width: 100%; max-width: 380px; background: var(--ground-2);
  border: 1px solid var(--line); border-radius: 22px; padding: 24px 22px;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
  display: flex; flex-direction: column; gap: 14px;
  max-height: calc(100dvh - 40px); overflow-y: auto;
}
.ov-title { font-family: var(--font-display); font-weight: 700; font-size: 1.5rem; margin: 0; line-height: 1.2; text-wrap: balance; }
.ov-text { margin: 0; color: var(--ink-2); font-weight: 600; }
.ov-big { font-family: var(--font-pixel); font-size: 1.6rem; color: var(--spark); margin: 4px 0; text-align: center; }
.ov-stars { font-size: 2.2rem; text-align: center; letter-spacing: .1em; margin: 0; }
.ov-stars .off { opacity: .25; }
.ov-row { display: flex; justify-content: space-between; gap: 12px; font-weight: 700; }
.ov-row span:last-child { font-variant-numeric: tabular-nums; }
.ov-badge { align-self: center; background: var(--success); color: #063; font-weight: 800; padding: 4px 12px; border-radius: 999px; font-size: .85rem; }
.ov-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.btn {
  min-height: 52px; border-radius: 14px; padding: 8px 18px;
  font-weight: 800; font-size: 1.05rem; background: var(--panel);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; line-height: 1.25;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.25);
}
.btn:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 rgba(0,0,0,.25); }
.btn.primary { background: var(--spark); color: var(--spark-ink); }
.btn.quiet { background: transparent; box-shadow: none; color: var(--ink-2); }
.btn .sub { font-size: .8rem; font-weight: 700; opacity: .75; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 800; font-size: .9rem; color: var(--ink-2); }
.field input {
  font: inherit; font-weight: 700; font-size: 1.1rem; color: var(--ink);
  background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px;
}
.emoji-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.emoji-grid button { height: 56px; border-radius: 12px; background: var(--panel); font-size: 1.8rem; }
.emoji-grid button.on { background: var(--brand); box-shadow: 0 0 0 3px var(--spark); }

.plist { display: flex; flex-direction: column; gap: 8px; }
.plist button {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--panel); border-radius: 12px; font-weight: 800; text-align: left;
}
.plist button.on { outline: 3px solid var(--spark); }
.plist .emoji { font-size: 1.5rem; }
.plist .pstars { margin-left: auto; color: var(--spark); font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Wide, short windows (desktop, phone held sideways): controls beside the screen */
@media (orientation: landscape) and (min-width: 640px) {
  .view-game {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto 1fr;
    grid-template-areas: "hud hud" "stage controls";
  }
  .hud { grid-area: hud; }
  .stage { grid-area: stage; }
  .controls { grid-area: controls; flex-direction: column; justify-content: center; padding: 8px 18px 8px 0; }
  .controls:empty { padding: 0; }
  .ctl-hint { max-width: 180px; text-align: center; }
  .turn2 { flex-direction: column; width: auto; gap: 24px; }
}
