:root {
  --bg: #f5f4fb;
  --fg: #16141f;
  --muted: #6b6680;
  --faint: #5c5770;
  --surface: #ffffff;
  --surface-2: #eeedf6;
  --line: #e2e0ee;
  --primary: #6030fc;
  --primary-fg: #ffffff;
  --ok: #2a6240;
  --ok-soft: #e4f1e8;
  --warn: #8a5a12;
  --warn-soft: #f8edd9;
  --danger: #8d3b32;
  --danger-soft: #f8e6e3;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0e0c14;
  --fg: #f0f0f0;
  --muted: #b4b0c4;
  --faint: #a8a3b8;
  --surface: #16141f;
  --surface-2: #221f2e;
  --line: #322e42;
  --primary: #7b56ff;
  --primary-fg: #ffffff;
  --ok: #8fceab;
  --ok-soft: #1a2c22;
  --warn: #e4b56a;
  --warn-soft: #2c2416;
  --danger: #f0a297;
  --danger-soft: #2c1c1a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html {
  touch-action: manipulation;
  background: var(--bg);
  color: var(--fg);
  overflow-x: hidden;
  max-width: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  max-width: 100%;
  overflow-x: hidden;
  font-family: system-ui, "Segoe UI", sans-serif;
  line-height: 1.5;
  background: var(--bg);
  color: var(--fg);
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.tab-link:focus,
.tab-link:focus-visible,
.nav-tab:focus,
.nav-tab:focus-visible,
.brand:focus,
.brand:focus-visible {
  outline: none;
}

h1, h2, h3, p { margin: 0; }

.display {
  font-family: system-ui, "Segoe UI", sans-serif;
  font-weight: 650;
  letter-spacing: -0.03em;
}

#app { min-height: 100dvh; max-width: 100%; overflow-x: hidden; }

.top {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 64px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 0 1 auto;
  border: 0;
  background: transparent;
  padding: 0;
}

.logo {
  display: block;
  height: 40px;
  width: auto;
  max-width: min(140px, calc(100vw - 196px));
  object-fit: contain;
  object-position: left center;
}

.desk-nav { display: none; gap: 4px; margin-left: 12px; }
.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.auth-btn {
  height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 14px;
  font-weight: 600;
}
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.sun, .moon { font-size: 18px; line-height: 1; }
:root[data-theme="dark"] .sun { display: none; }
:root:not([data-theme="dark"]) .moon { display: none; }

main {
  width: min(1120px, 100%);
  max-width: 100%;
  margin: 0 auto;
  padding: 24px 16px 112px;
  overflow-x: hidden;
}

html[data-screen="checkout"] main { padding-bottom: 0; }
html[data-screen="checkout"] .tabbar { display: none; }

[data-panel] { display: none; }
html:not([data-screen]) [data-panel="catalog"],
html[data-screen="profile"] [data-panel="profile"],
html[data-screen="catalog"] [data-panel="catalog"],
html[data-screen="checkout"] [data-panel="checkout"] { display: block; }

.nav-tab, .tab-link { color: var(--muted); background: transparent; }
html:not([data-screen]) .nav-tab[data-go="catalog"],
html[data-screen="profile"] .nav-tab[data-go="profile"],
html[data-screen="catalog"] .nav-tab[data-go="catalog"] {
  background: var(--fg);
  color: var(--bg);
}
html:not([data-screen]) .tab-link[data-go="catalog"],
html[data-screen="profile"] .tab-link[data-go="profile"],
html[data-screen="catalog"] .tab-link[data-go="catalog"] {
  color: var(--fg);
}

.nav-tab {
  height: 44px;
  border: 0;
  border-radius: 12px;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 600;
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
html[data-logged-in] .tabbar {
  grid-template-columns: 1fr 1fr;
}

.tab-link {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  border: 0;
  padding-top: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  font-size: 12px;
  font-weight: 600;
}

.tab-link svg { width: 22px; height: 22px; }
.tab-link::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 32px;
  height: 3px;
  border-radius: 999px;
  background: transparent;
  transform: translateX(-50%);
}
html:not([data-screen]) .tab-link[data-go="catalog"]::before,
html[data-screen="profile"] .tab-link[data-go="profile"]::before,
html[data-screen="catalog"] .tab-link[data-go="catalog"]::before {
  background: var(--primary);
}

.layout {
  display: grid;
  gap: 24px;
  min-width: 0;
  max-width: 100%;
}
#panel-profile,
#panel-profile section {
  min-width: 0;
  max-width: 100%;
}
.card, .rental, .game, .summary, .pay-card, .banner {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 16px;
}
.profile-card { padding: 16px; }
.who { display: flex; gap: 12px; align-items: center; min-width: 0; }
.who > div:last-child { min-width: 0; }
.profile-card h1 { overflow-wrap: anywhere; }
.avatar {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--fg);
  color: var(--bg);
  font-family: system-ui, "Segoe UI", sans-serif;
  font-size: 18px;
}
.kicker {
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 600;
}
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 14px; }
.tiny { font-size: 12px; }
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.stats > div { min-width: 0; }
.stats dd {
  overflow-wrap: anywhere;
  text-align: right;
}
.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  min-width: 0;
  flex-wrap: wrap;
}
.section-head > div { min-width: 0; flex: 1; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 0;
  background: var(--primary);
  color: var(--primary-fg);
  font-size: 14px;
  font-weight: 600;
}
.btn.ghost {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--line);
}
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.login-error { color: var(--danger); margin-top: 12px; }
.login-ok { color: var(--ok); margin-top: 12px; }
#login-form .btn,
#register-form .btn { margin-top: 16px; }
.auth-switch {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  cursor: pointer;
}
.auth-switch:hover { color: var(--fg); }
.banner {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
  padding: 16px;
  background: var(--warn-soft);
}
.catalog-head {
  max-width: 560px;
  margin-bottom: 24px;
}
.catalog-head .tools { margin-top: 16px; margin-bottom: 0; }
.tools { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.search {
  width: 100%;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 0 12px;
}
.filters {
  display: flex;
  gap: 8px;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}
.chip {
  height: 44px;
  flex: none;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 0 16px;
  font-size: 14px;
  font-weight: 600;
}
.chip[aria-selected="true"] {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
.list { display: flex; flex-direction: column; gap: 12px; }
.rental { padding: 16px; min-width: 0; overflow: hidden; }
.rental.head { display: flex; justify-content: space-between; gap: 12px; }
.row { display: flex; justify-content: space-between; gap: 12px; align-items: center; min-width: 0; }
.rental-title { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.rental-title > div { min-width: 0; }
.rental-title h3 { overflow-wrap: anywhere; word-break: break-word; }
.game-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  overflow: hidden;
  flex: none;
  background: var(--surface-2);
}
.game-icon-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}
.pill {
  display: inline-flex;
  align-items: center;
  flex: none;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--ok-soft);
  color: var(--ok);
}
.pill.expiring { background: var(--warn-soft); color: var(--warn); }
.pill.expired { background: var(--surface-2); color: var(--muted); }
.bar {
  height: 6px;
  margin-top: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--primary);
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions .btn { flex: 1 1 auto; }
.empty {
  padding: 28px 16px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 16px;
}
.games {
  display: grid;
  gap: 16px;
}
.game { overflow: hidden; }
.poster {
  position: relative;
  height: 168px;
  background: #121018;
  overflow: hidden;
}
.poster-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}
.poster span { position: absolute; display: block; }
.poster-harbor { background: linear-gradient(180deg, #1a1840, #0c0a18); }
.poster-harbor span:nth-child(1) { left: 18%; right: 18%; bottom: 18%; height: 46%; border: 2px solid rgba(240,240,240,.45); border-radius: 40% 40% 8px 8px; }
.poster-harbor span:nth-child(2) { width: 10px; height: 10px; border-radius: 50%; background: #6030fc; left: calc(50% - 5px); top: 28%; }
.poster-ash { background: linear-gradient(160deg, #2a1848, #100e18); }
.poster-ash span { left: -10%; right: -10%; height: 18%; background: rgba(96,48,252,.8); transform: rotate(-8deg); }
.poster-ash span:nth-child(1) { top: 38%; }
.poster-ash span:nth-child(2) { top: 62%; background: rgba(240,240,240,.25); }
.poster-crown { background: linear-gradient(180deg, #241848, #100e18); }
.poster-crown span:nth-child(1) { left: 28%; right: 28%; top: 22%; bottom: 28%; border: 2px solid rgba(240,240,240,.55); border-radius: 8px 8px 0 0; }
.poster-crown span:nth-child(2) { left: 20%; right: 20%; bottom: 22%; height: 8px; background: #6030fc; }
.poster-tide { background: linear-gradient(180deg, #181840, #0a0a16); }
.poster-tide span { left: -5%; right: -5%; height: 22%; border-radius: 50%; border: 2px solid rgba(240,240,240,.35); }
.poster-tide span:nth-child(1) { bottom: 8%; }
.poster-tide span:nth-child(2) { bottom: 22%; }
.poster-orbit { background: radial-gradient(circle at 50% 60%, #2a1848, #100e16 70%); }
.poster-orbit span:nth-child(1) { inset: 22%; border: 2px solid rgba(240,240,240,.45); border-radius: 50%; }
.poster-orbit span:nth-child(2) { width: 12px; height: 12px; border-radius: 50%; background: #6030fc; left: calc(50% - 6px); top: calc(50% - 6px); }
.poster-parish { background: linear-gradient(180deg, #221e38, #101016); }
.poster-parish span:nth-child(1) { left: 34%; right: 34%; top: 16%; bottom: 18%; background: rgba(240,240,240,.12); }
.poster-parish span:nth-child(2) { width: 18%; left: 41%; top: 28%; bottom: 42%; background: #6030fc; }
.game-body { padding: 16px; display: grid; gap: 12px; }
.game-copy { display: grid; gap: 4px; }
.game-title {
  font-size: 20px;
  line-height: 1.25;
  height: 2.5em;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: break-word;
}
.price-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.checkout {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 88px);
  max-width: 560px;
  margin: 0 auto;
}
.checkout-scroll { min-height: 0; flex: 1; overflow: auto; padding-bottom: 16px; }
.back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin-bottom: 8px;
  border: 0;
  background: transparent;
  color: var(--fg);
  font-size: 15px;
  font-weight: 600;
}
.back-icon {
  width: 22px;
  height: 22px;
  flex: none;
}
.back:hover { color: var(--primary); }
.game-mini { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; }
.thumb {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  overflow: hidden;
  flex: none;
  background: var(--surface-2);
}
.thumb .game-icon {
  width: 64px;
  height: 64px;
  border-radius: 14px;
}
.thumb .poster { height: 64px; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.step {
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 14px;
  font-weight: 600;
}
.step[aria-current="step"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.step:disabled { opacity: 0.6; }
.plans { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.plan {
  text-align: left;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.plan[aria-pressed="true"] { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.plan strong { display: block; margin: 6px 0 0; font-family: system-ui, "Segoe UI", sans-serif; font-size: 28px; font-weight: 650; }
.summary, .pay-card { padding: 16px; }
.summary dl { margin: 16px 0 0; }
.summary .line, .pay-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  font-size: 14px;
}
.total-line {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.total-line strong { font-family: system-ui, "Segoe UI", sans-serif; font-size: 32px; }
.dock {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 -16px;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.dock .sum { font-family: system-ui, "Segoe UI", sans-serif; font-size: 22px; }
.pay-head { display: flex; gap: 12px; align-items: center; }
.paypal {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  padding: 7px;
  flex: none;
}
.paypal img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.switch {
  width: 44px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  position: relative;
}
.switch i {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface);
}
.switch[aria-checked="true"] { background: var(--primary); border-color: var(--primary); }
.switch[aria-checked="true"] i { left: 20px; }
.payer {
  margin-top: 16px;
  padding: 12px;
  border-radius: 12px;
  background: var(--bg);
  font-size: 14px;
}
.wait, .result { text-align: center; padding: 48px 16px; }
.wait h2, .result h2 { margin-top: 12px; font-size: 28px; }
.amount { font-family: system-ui, "Segoe UI", sans-serif; font-size: 40px; }
.spin {
  width: 32px;
  height: 32px;
  margin: 0 auto;
  border: 3px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }

.scrim {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--fg) 42%, transparent);
}
.dialog {
  position: fixed;
  z-index: 51;
  left: 16px;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: calc(100% - 32px);
  max-width: 440px;
  max-height: calc(100dvh - 32px);
  overflow-x: hidden;
  overflow-y: auto;
  margin: 0 auto;
  padding: 20px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.dialog-head { display: flex; justify-content: space-between; gap: 12px; min-width: 0; }
.dialog-head > div { min-width: 0; flex: 1; }
.dialog-head .small { overflow-wrap: anywhere; word-break: break-word; }
.cred-step {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  min-width: 0;
}
.cred-step:first-of-type { margin-top: 12px; padding-top: 0; border-top: 0; }
.cred-step-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.field { margin-top: 14px; min-width: 0; }
.field label { display: block; font-size: 12px; color: var(--faint); margin-bottom: 4px; }
.field-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
}
.field input {
  width: 100%;
  height: 36px;
  line-height: 36px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 0 10px;
  font-size: 16px;
  appearance: none;
  -webkit-appearance: none;
}
.field-row input {
  flex: 1 1 auto;
  min-width: 0;
  width: 0;
}
.field-row .btn {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 10px;
  font-size: 13px;
}
#cred-dialog .field input {
  height: 32px;
  min-height: 32px;
  max-height: 32px;
  line-height: 32px;
  padding: 0 10px;
}
#cred-dialog .field-row .btn {
  min-height: 32px;
  height: 32px;
  padding: 0 10px;
}
#cred-dialog .nintendo-get {
  width: 100%;
  margin-top: 8px;
  min-height: 36px;
  height: auto;
}
.flash {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 96px;
  z-index: 45;
  max-width: 360px;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--fg);
  color: var(--bg);
  font-size: 14px;
}
[hidden] { display: none !important; }

@media (min-width: 768px) {
  .logo { height: 44px; max-width: 148px; }
  .desk-nav { display: flex; }
  .tabbar { display: none; }
  main { padding-bottom: 48px; }
  .layout { grid-template-columns: 272px 1fr; align-items: start; }
  .profile-card { position: sticky; top: 80px; }
  .banner { flex-direction: row; align-items: center; justify-content: space-between; }
  .tools { flex-direction: row; align-items: center; }
  .games { grid-template-columns: 1fr 1fr; }
  .stack { flex-direction: row; justify-content: center; }
}

@media (min-width: 1100px) {
  .games { grid-template-columns: 1fr 1fr 1fr; }
}

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