* { box-sizing: border-box; }

:root, :root[data-theme="dark"] {
  --bg: radial-gradient(1200px 700px at 70% -10%, #2a2f45 0%, #14161f 60%) fixed;
  --panel: #232736;
  --panel-hover: #2d3350;
  --line: #343a52;
  --text: #eef0f6;
  --muted: #9aa0b8;
  --accent: #1fd36b;
  --accent-text: #04180c;
  --bar: rgba(10, 12, 20, .55);
  --stage: #1a1e2c;
}

:root[data-theme="light"] {
  --bg: #f2f4f5;
  --panel: #ffffff;
  --panel-hover: #e6e9ee;
  --line: #d6dae1;
  --text: #1b1d24;
  --muted: #6b7280;
  --accent: #00b05a;
  --accent-text: #ffffff;
  --bar: rgba(255, 255, 255, .85);
  --stage: #dde3ee;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3 { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .6; }
.muted { color: var(--muted); }
.center { text-align: center; }
.spacer { flex: 1; }

#app { min-height: 100vh; }

/* ----- Slotit / aloitus ----- */

.center-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
}
.center-screen.narrow { width: min(420px, 92vw); margin: 0 auto; }
.center-screen input { width: 100%; }
.title { font-size: 2.2rem; }

.slot-row { display: flex; gap: 20px; flex-wrap: wrap; justify-content: center; }
.slot-card {
  width: 200px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--text);
}
.slot-card.empty {
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 28px 10px;
  border-style: dashed;
}
.slot-card:hover { background: var(--panel-hover); }
.slot-main {
  background: none;
  border: 0;
  padding: 22px 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.slot-plus {
  width: 96px; height: 96px; border-radius: 50%;
  display: grid; place-items: center; font-size: 2.4rem;
  background: var(--stage); color: var(--muted);
}
.slot-name { font-weight: 700; font-size: 1.1rem; }
.slot-sub { color: var(--muted); font-size: .85rem; }
.slot-del {
  background: none; border: 0; border-top: 1px solid var(--line);
  padding: 8px; color: var(--muted);
}
.slot-del:hover { background: #6b2630; color: #fff; }

.floating { position: fixed; top: 14px; right: 14px; }

/* ----- Painikkeet ----- */

.btn, input {
  padding: 12px 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
}
.btn:hover:not(:disabled) { background: var(--panel-hover); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 700; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.small { padding: 7px 12px; width: 100%; border-radius: 9px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel); font-size: 1.1rem;
}
.icon-btn:hover { background: var(--panel-hover); }

#back {
  position: fixed; top: 12px; left: 12px; z-index: 10;
  padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel);
}

/* ----- Yläpalkki ----- */

.shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 28px;
  background: var(--bar);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.logo {
  width: 38px; height: 38px; border-radius: 9px;
  display: grid; place-items: center; font-weight: 800;
  background: var(--text); color: var(--panel);
}
.tabs { display: flex; align-items: center; gap: 6px; }
.tab {
  background: none; border: 0; padding: 8px 14px; border-radius: 10px;
  color: var(--muted); font-weight: 600;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); }
.pill {
  margin-left: 6px; padding: 7px 16px; border-radius: 999px;
  border: 1px solid var(--accent); background: transparent; color: var(--accent); font-weight: 700;
}
.pill:hover, .pill.active { background: var(--accent); color: var(--accent-text); }
.me {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 14px 4px 4px;
}
.me:hover { background: var(--panel-hover); }

.content { padding: 24px 28px 60px; max-width: 1200px; margin: 0 auto; }

/* ----- Avatarit ----- */

.headshot { display: block; border-radius: 50%; background: var(--stage); object-fit: cover; }
.headshot.tiny { width: 32px; height: 32px; }
.headshot.big { width: 110px; height: 110px; }
.headshot.circle { width: 84px; height: 84px; border: 2px solid var(--line); }
.headshot.circle.big { width: 96px; height: 96px; }

.hello { display: flex; align-items: center; gap: 18px; margin-bottom: 20px; }
.hello-small { color: var(--muted); }
.hello-name { font-size: 1.8rem; font-weight: 800; }

.label { font-size: .72rem; letter-spacing: .1em; color: var(--muted); margin-bottom: 10px; }

.friends { display: flex; gap: 18px; flex-wrap: wrap; }
.friend { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: .85rem; }
.circle.ghost {
  width: 84px; height: 84px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.8rem;
  border: 2px dashed var(--line); color: var(--muted);
}

/* ----- Pelikortit ----- */

.row-section { margin-bottom: 28px; }
.row-section h2 { margin-bottom: 12px; }
.cards {
  display: flex; gap: 14px; overflow-x: auto; padding-bottom: 6px;
  scrollbar-width: none; -ms-overflow-style: none;
  cursor: grab; user-select: none;
}
.cards::-webkit-scrollbar { display: none; }
.card {
  flex: 0 0 auto; width: 200px; text-align: left; padding: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  color: var(--text);
}
.card .thumb {
  height: 116px; display: grid; place-items: center; font-size: 2.4rem; font-weight: 800;
  background: linear-gradient(135deg, #3b4266, #242842); color: rgba(255, 255, 255, .5);
}
.card.placeholder .thumb { background: var(--stage); }
.card-title { padding: 10px 12px; font-weight: 600; }
.card.placeholder { opacity: .55; }
.card.game:hover { outline: 2px solid var(--accent); }

/* ----- Shop / Customize ----- */

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.chip {
  padding: 7px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel);
}
.chip.active { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 700; }

.item-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.item {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px; display: flex; flex-direction: column; gap: 6px; color: var(--text); text-align: left;
}
.item.pick:hover { background: var(--panel-hover); }
.item.pick.on { outline: 3px solid var(--accent); }
.swatch {
  height: 84px; border-radius: 10px; display: grid; place-items: center; font-size: 2rem;
}
.swatch.none { background: var(--stage); color: var(--muted); }
.item-name { font-weight: 600; font-size: .92rem; }
.item-price { font-size: .75rem; color: var(--accent); font-weight: 700; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: var(--accent-text);
  padding: 12px 20px; border-radius: 12px; font-weight: 700;
}
.toast[hidden] { display: none; }

.customize { display: grid; grid-template-columns: minmax(280px, 420px) 1fr; gap: 28px; align-items: start; }
.stage {
  height: min(66vh, 560px); border-radius: 18px; overflow: hidden;
  background: radial-gradient(circle at 50% 30%, var(--panel-hover), var(--stage));
  border: 1px solid var(--line);
}
.stage-wrap { position: sticky; top: 80px; }
.side { display: flex; flex-direction: column; gap: 6px; }
.item-grid.compact { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); margin-bottom: 14px; }
.item.pick .swatch { height: 64px; }

@media (max-width: 760px) {
  .customize { grid-template-columns: 1fr; }
  .stage-wrap { position: static; }
  .topbar { padding: 8px 12px; flex-wrap: wrap; }
  .content { padding: 16px 14px 60px; }
  .me span { display: none; }
}

#game-root { position: fixed; inset: 0; }

/* ----- Ikkunat ----- */

.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, .55); backdrop-filter: blur(3px);
}
.modal {
  width: min(440px, 92vw); max-height: 90vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 24px; display: flex; flex-direction: column; gap: 14px;
}
.modal h2 { text-align: center; }
.setting { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.setting .chips { margin: 0; }
.vol { display: flex; align-items: center; gap: 12px; }
.vol input { flex: 1; padding: 0; accent-color: var(--accent); }
.players { display: flex; flex-direction: column; gap: 8px; max-height: 40vh; overflow: auto; }
.player { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 12px; background: var(--stage); }
.pause-actions { display: flex; gap: 10px; margin-top: 6px; }
.pause-actions .btn { flex: 1; padding: 12px 8px; }
.btn.danger:hover { background: #6b2630; color: #fff; }
.btn.on { background: #f2c230; color: #3a2a00; border-color: transparent; font-weight: 700; }

/* ----- Kaverit (verkko) ----- */
.friends-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.friends-head .label { margin: 0; }
.net-status { font-size: .85rem; color: var(--muted); }
.net-status.online { color: #4cd97b; }
.net-status.nosrv { color: #e0a040; }
.btn.small { padding: 5px 12px; font-size: .8rem; }
.net-setup { display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
.net-row { display: flex; gap: 8px; }
.net-row input { flex: 1; }
.fcard { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: .85rem; min-width: 110px; }
.fcard .fbtns { display: flex; gap: 6px; margin-top: 4px; }
.fcard.request .headshot { border-color: #f2c230; }
.avwrap { position: relative; }
.avwrap.on::after { content: ""; position: absolute; right: 4px; bottom: 6px; width: 16px; height: 16px; border-radius: 50%; background: #4cd97b; border: 3px solid var(--bg, #111); }
.net-toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); z-index: 99; }
.friends-head .btn.small, .fcard .fbtns .btn.small { width: auto; }
