:root {
  --bg: #0f1020;
  --bg-2: #16182e;
  --card: rgba(255, 255, 255, 0.045);
  --card-border: rgba(255, 255, 255, 0.08);
  --text: #eef0ff;
  --muted: #9aa0c2;
  --accent: #7c5cff;
  --accent-2: #00d4ff;
  --danger: #ff5c7c;
  --win: #ffd166;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(124, 92, 255, 0.18), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(0, 212, 255, 0.12), transparent 55%),
    var(--bg);
  min-height: 100dvh;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

/* Topbar */
.topbar {
  padding: 20px 18px 8px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 26px; }
.brand h1 {
  font-size: 20px; font-weight: 800; letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--text), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}

/* Tabs */
.tabs {
  display: flex; gap: 6px; padding: 8px 14px 4px;
  position: sticky; top: 0; z-index: 5;
}
.tab {
  flex: 1; padding: 11px 8px; border: none; cursor: pointer;
  background: var(--card); color: var(--muted);
  border: 1px solid var(--card-border);
  border-radius: 14px; font-size: 14px; font-weight: 600;
  font-family: inherit; transition: all 0.18s ease;
}
.tab.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #5b8cff);
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(124, 92, 255, 0.4);
}

/* Content / panels */
.content { flex: 1; padding: 14px 14px 28px; }
.panel { display: none; animation: fade 0.25s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { font-size: 16px; font-weight: 700; }

.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }

/* Inputs */
.input {
  width: 100%; padding: 14px 14px; font-size: 16px; color: var(--text);
  background: rgba(0, 0, 0, 0.25); border: 1px solid var(--card-border);
  border-radius: 14px; font-family: inherit; outline: none; transition: border 0.15s;
}
.input::placeholder { color: #6b7099; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.2); }

.row { display: flex; gap: 8px; }
.row .input { flex: 1; }

/* Buttons */
.btn {
  border: none; cursor: pointer; font-family: inherit; font-weight: 600;
  border-radius: 14px; padding: 13px 16px; font-size: 15px; color: #fff;
  transition: transform 0.08s ease, opacity 0.15s, background 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #5b8cff); box-shadow: 0 6px 18px rgba(124, 92, 255, 0.35); }
.btn.ghost { background: transparent; border: 1px solid var(--card-border); color: var(--muted); }
.btn.danger { background: transparent; color: var(--danger); padding: 8px 10px; }
.btn.big { width: 100%; padding: 17px; font-size: 16px; font-weight: 700; }
.btn.small { padding: 8px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 10px 15px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: rgba(0, 0, 0, 0.25); border: 1px solid var(--card-border);
  color: var(--text); cursor: pointer; transition: all 0.15s; user-select: none;
}
.chip.selected { background: linear-gradient(135deg, var(--accent), #5b8cff); border-color: transparent; color: #fff; }
.chip.winner { background: linear-gradient(135deg, #ffb703, var(--win)); border-color: transparent; color: #3a2c00; }
.chip:active { transform: scale(0.95); }

/* Lists */
.list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--card-border); border-radius: 14px;
}
.list .name { font-weight: 600; }

/* History */
.history-tools {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 12px;
}
.search-wrap {
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px; min-width: 0;
  background: rgba(0, 0, 0, 0.25); border: 1px solid var(--card-border);
  border-radius: 14px;
}
.search-wrap input {
  width: 100%; min-width: 0; border: none; outline: none;
  background: transparent; color: var(--text); font: inherit; font-size: 14px; padding: 12px 0;
}
.search-wrap input::placeholder { color: #6b7099; }
.history-filter {
  border: 1px solid var(--card-border); outline: none; cursor: pointer;
  background: rgba(0, 0, 0, 0.25); color: var(--text); border-radius: 14px;
  padding: 0 10px; font: inherit; font-size: 13px; font-weight: 600;
}

.history { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.history-record {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--card-border); border-radius: 14px;
  transition: background 0.15s;
}
.history-record:active { background: rgba(0, 0, 0, 0.3); }
.history-group {
  margin: 8px 2px 0; padding: 0 2px;
  color: var(--muted); font-size: 12px; font-weight: 800;
  letter-spacing: 0.08em; text-transform: uppercase;
}

.hist-avatar {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; font-weight: 800; font-size: 17px;
  color: #3a2c00; background: linear-gradient(135deg, #ffb703, var(--win));
  box-shadow: 0 4px 12px rgba(255, 183, 3, 0.3);
}

.hist-body { flex: 1; min-width: 0; }
.hist-line {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.hist-sub { margin-top: 1px; }

.hist-game {
  font-weight: 700; font-size: 15px; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hist-count {
  flex: 0 0 auto; font-size: 11px; font-weight: 700; color: var(--accent-2);
  background: rgba(0, 212, 255, 0.12); padding: 2px 7px; border-radius: 999px;
}
.hist-winner {
  font-size: 13px; font-weight: 600; color: var(--win);
  display: inline-flex; align-items: center; gap: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.trophy { font-size: 12px; }
.hist-date { flex: 0 0 auto; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.hist-players {
  font-size: 12px; color: var(--muted); margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.hist-del {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 9px;
  border: none; cursor: pointer; font-size: 14px; line-height: 1;
  color: var(--muted); background: rgba(255, 255, 255, 0.05);
  transition: all 0.15s;
}
.hist-del:hover, .hist-del:active { color: #fff; background: var(--danger); }

/* Stats */
.stats { display: flex; gap: 12px; }
.stat { flex: 1; text-align: center; padding: 6px; }
.stat-num {
  display: block; font-size: 26px; font-weight: 800; line-height: 1.1;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.stat-label { font-size: 12px; color: var(--muted); }

/* Misc */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { text-align: center; padding: 14px 0; }
[hidden] { display: none !important; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: #fff; color: #15172b; font-weight: 600; font-size: 14px;
  padding: 12px 18px; border-radius: 999px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: all 0.28s ease; z-index: 50; max-width: 90%;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Confirm modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center; padding: 22px;
  background: rgba(6, 7, 18, 0.6); backdrop-filter: blur(4px);
  opacity: 0; transition: opacity 0.2s ease;
}
.modal-overlay.show { opacity: 1; }
.modal {
  width: 100%; max-width: 360px;
  background: var(--bg-2); border: 1px solid var(--card-border);
  border-radius: 20px; padding: 22px; box-shadow: var(--shadow);
  transform: scale(0.94) translateY(8px); transition: transform 0.22s ease;
}
.modal-overlay.show .modal { transform: none; }
.modal-title { font-size: 18px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 8px; }
.modal-msg { font-size: 14px; color: var(--muted); line-height: 1.5; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }
.btn.danger-solid {
  background: linear-gradient(135deg, #ff4d6d, var(--danger));
  box-shadow: 0 6px 18px rgba(255, 92, 124, 0.35); color: #fff;
}
