/* Layout: one column on a phone — names, number of teams, the big button, then the team cards; two panes on wide screens */
:root {
  --bg: #17110e;
  --surface: #241a15;
  --surface-2: #2f231c;
  --line: #4a3a30;
  --accent: #ff6b2c;
  --accent-text: #ff8a55;
  --accent-deep: #b8461c;
  --on-accent: #17110e;
  --focus: #ffbd4a;
  --text: #f7ede1;
  --muted: #b5a191;
  --bust: #c0392b;
  --on-bust: #ffffff;
  --danger-text: #ff9a8f;
  --glow: rgba(255, 107, 44, .16);
  --scrim: rgba(8, 5, 4, .6);
  --shadow: rgba(0, 0, 0, .5);
  --toast-bg: #f3e7cf;
  --toast-ink: #2b1d14;
  --avatar-bg: #ffd54f;
  --avatar-ink: #17110e;
  --team-ink: #17110e;
  --team-1: #ff8a4c;
  --team-2: #61b6ff;
  --team-3: #93dc7d;
  --team-4: #ffd54f;
  --team-5: #c99cff;
  --team-6: #ff8aac;
  --team-7: #4fd1c5;
  --team-8: #ff7a6b;
  --team-9: #c6e36b;
  --team-10: #e0b88a;
  --display: 'Bagel Fat One', 'Arial Black', system-ui, sans-serif;
  --body: 'Rethink Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; min-height: 100vh;
  background: radial-gradient(130% 55% at 50% 105%, var(--glow), transparent 62%), var(--bg);
  color: var(--text); font-family: var(--body); font-size: 16px; line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2, h3, h4, p { margin: 0; }
#app {
  max-width: 560px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 0 96px;
  display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr);
}
.controls { display: grid; gap: 14px; min-width: 0; }
.eyebrow, .label { font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }

/* ---------- buttons and controls ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer; width: 100%; min-height: 52px; padding: 0 18px; border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 800; font-size: 17px;
}
.btn:active { transform: translateY(2px); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn svg { flex: none; width: 18px; height: 18px; }
.btn.primary { background: var(--accent); color: var(--on-accent); box-shadow: 0 3px 0 var(--accent-deep); }
.btn.ghost { background: var(--surface); color: var(--text); border: 1.5px solid var(--line); }
.btn.bust { background: var(--bust); color: var(--on-bust); }
.btn.text { background: transparent; color: var(--muted); min-height: 44px; }
.btn.big { min-height: 58px; font-family: var(--display); font-weight: 400; font-size: 21px; }
.btn.small { width: auto; min-height: 44px; padding: 0 14px; font-size: 15px; border-radius: 12px; }
.icon-btn { appearance: none; flex: none; width: 46px; height: 46px; border-radius: 14px; cursor: pointer; border: 1.5px solid var(--line); background: var(--surface); color: var(--text); display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:disabled { opacity: .35; cursor: default; }
.segmented { display: inline-flex; flex: none; gap: 2px; padding: 3px; border-radius: 12px; background: var(--bg); }
.segmented button { appearance: none; border: 0; cursor: pointer; min-height: 40px; padding: 0 12px; border-radius: 9px; background: none; color: var(--muted); font-weight: 700; font-size: 15px; }
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--on-accent); }
.stepper { display: flex; align-items: center; gap: 4px; padding: 4px; border-radius: 14px; background: var(--bg); }
.stepper button { appearance: none; width: 44px; height: 44px; border: 0; border-radius: 10px; background: var(--surface-2); color: var(--text); font-size: 24px; font-weight: 700; cursor: pointer; }
.stepper button:disabled { opacity: .3; cursor: default; }
.stepper output { width: 36px; text-align: center; font-family: var(--display); font-size: 24px; }

/* ---------- avatars ---------- */
.avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--avatar-bg); color: var(--avatar-ink); font-weight: 800; }
.avatar.pic { padding: 0; overflow: hidden; background: none; }
.avatar.pic svg { display: block; width: 100%; height: 100%; }

/* ---------- top ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-block: 12px 0;
}
.top-actions { display: flex; gap: 8px; flex: none; }
.back-link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px; color: var(--muted); font-weight: 700; text-decoration: none; }
.hero { display: grid; gap: 6px; }
.hero h1 { font-family: var(--display); font-weight: 400; font-size: clamp(44px, 13vw, 60px); line-height: 1; }
.hero p { color: var(--muted); max-width: 36ch; }
.box { background: var(--surface); border-radius: 18px; padding: 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; min-width: 0; }
.box h2 { font-size: 17px; font-weight: 800; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pill { font-size: 13px; font-weight: 800; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text); }
.hint { color: var(--muted); font-weight: 600; }
.count-text { display: grid; gap: 2px; min-width: 0; }

/* ---------- names ---------- */
.add-row { display: flex; gap: 8px; }
.add-row input, .paste textarea, .copy-text {
  flex: 1; min-width: 0; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-size: 17px;
}
.add-row input { height: 52px; padding: 0 14px; font-weight: 600; }
.add-row input::placeholder, .paste textarea::placeholder { color: var(--muted); font-weight: 400; }
.add-btn { width: auto; flex: none; padding: 0 16px; font-size: 16px; }
.btn.paste-toggle { justify-self: start; width: auto; min-height: 44px; padding: 0 4px; margin-block: -6px; color: var(--accent-text); }
.paste { display: grid; gap: 8px; }
.paste textarea { width: 100%; padding: 12px 14px; resize: vertical; line-height: 1.4; }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%;
  min-height: 44px; padding: 3px 3px 3px 4px; border-radius: 999px; background: var(--surface-2);
}
.chip .avatar { width: 34px; height: 34px; font-size: 14px; }
.chip-name { font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-x { appearance: none; flex: none; border: 0; cursor: pointer; width: 38px; height: 38px; border-radius: 50%; background: none; color: var(--muted); display: grid; place-items: center; }
.chip-x svg { width: 15px; height: 15px; }
.chip-x:hover { background: var(--line); color: var(--text); }
.empty { color: var(--muted); }
.btn.danger-text { justify-self: start; width: auto; padding: 0 4px; margin-block: -6px; color: var(--danger-text); }

/* ---------- teams ---------- */
.results { display: grid; gap: 12px; min-width: 0; scroll-margin-top: 12px; }
.results-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; }
.results-head h2 { font-family: var(--display); font-weight: 400; font-size: 28px; line-height: 1.1; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.note { color: var(--text); background: var(--surface); border-radius: 12px; padding: 10px 12px; font-size: 14.5px; }
.note.subtle { background: none; padding: 0 2px; color: var(--muted); }
.note b { color: var(--text); }
.team-grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.team {
  --tc-ink: var(--team-ink);
  background: var(--surface); border-radius: 18px; overflow: hidden; min-width: 0;
  display: grid; align-content: start;
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--tc) 45%, transparent);
}
.team-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 6px 12px; flex-wrap: wrap;
  padding: 12px 16px; background: var(--tc); color: var(--tc-ink);
}
.team-head h3 { font-family: var(--display); font-weight: 400; font-size: 22px; line-height: 1.1; min-width: 0; overflow-wrap: anywhere; }
.team-size { font-weight: 800; font-size: 14px; }
.members { list-style: none; margin: 0; padding: 8px; display: grid; gap: 2px; }
.members .empty { padding: 8px; }
.member {
  appearance: none; border: 0; cursor: pointer; width: 100%; min-height: 48px; padding: 4px 8px; border-radius: 12px;
  background: none; display: flex; align-items: center; gap: 10px; text-align: left;
}
.member .avatar { width: 36px; height: 36px; font-size: 15px; }
.member-name { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member:hover { background: var(--surface-2); }
.member.on { background: var(--surface-2); box-shadow: inset 0 0 0 2px var(--focus); }
.move-here { width: auto; margin: 0 8px 10px; min-height: 44px; font-size: 15px; background: var(--tc); color: var(--tc-ink); }
.team-grid.dealt .team { animation: deal .36s cubic-bezier(.2, .9, .3, 1) both; animation-delay: calc(var(--i) * 45ms); }
@media (min-width: 640px) {
  #app { max-width: 760px; }
  .team-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1000px) {
  #app { max-width: 1180px; grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); column-gap: 24px; align-items: start; }
  #app > .topbar { grid-column: 1 / -1; }
  #app > .controls { grid-column: 1; }
  #app > .results { grid-column: 2; padding-top: 10px; }
  .team-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}

/* ---------- sheets, modal, toast ---------- */
.backdrop { position: fixed; inset: 0; z-index: 20; background: var(--scrim); animation: fade .2s ease; }
.sheet {
  position: fixed; z-index: 21; bottom: 0; left: 50%; translate: -50% 0; width: min(100%, 560px); max-height: 86%; overflow-y: auto;
  border-radius: 22px 22px 0 0; background: var(--surface); display: grid; gap: 14px;
  padding-top: 10px; padding-left: max(18px, env(safe-area-inset-left, 0px)); padding-right: max(18px, env(safe-area-inset-right, 0px));
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -10px 40px var(--shadow); animation: rise .25s cubic-bezier(.2, .9, .3, 1);
}
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); justify-self: center; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-head h3 { font-family: var(--display); font-weight: 400; font-size: 24px; }
.close-btn { appearance: none; border: 0; width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); color: var(--text); cursor: pointer; display: grid; place-items: center; }
.close-btn svg { width: 18px; height: 18px; }
.copy-text { width: 100%; padding: 12px 14px; font-size: 15px; resize: none; }
.menu-list { display: grid; gap: 6px; }
.menu-item {
  appearance: none; border: 0; cursor: pointer; width: 100%; min-height: 54px; padding: 0 14px; border-radius: 14px;
  background: var(--surface-2); color: var(--text); text-align: left; font-weight: 700; font-size: 16.5px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.menu-item.static { cursor: default; padding-block: 8px; }
.menu-item.danger { color: var(--danger-text); }
.switch { flex: none; width: 52px; height: 32px; border-radius: 999px; position: relative; background: var(--line); transition: background .2s ease; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: var(--text); transition: transform .2s ease; }
[aria-checked="true"] .switch { background: var(--accent); }
[aria-checked="true"] .switch::after { transform: translateX(20px); background: var(--on-accent); }
.modal-backdrop { position: fixed; inset: 0; z-index: 40; background: var(--scrim); animation: fade .2s ease; }
.modal {
  position: fixed; z-index: 41; left: 50%; top: 50%; translate: -50% -50%; width: min(calc(100% - 48px), 360px);
  padding: 20px; border-radius: 20px; background: var(--surface); box-shadow: 0 20px 60px var(--shadow);
  display: grid; gap: 10px; animation: pop .2s ease;
}
.modal h3 { font-family: var(--display); font-weight: 400; font-size: 24px; line-height: 1.1; }
.modal p { color: var(--muted); }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.modal-actions .btn { min-height: 48px; font-size: 16px; padding: 0 10px; }
.toast {
  position: fixed; z-index: 30; left: 50%; translate: -50% 0; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  width: min(calc(100% - 32px), 528px); display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 16px; background: var(--toast-bg); color: var(--toast-ink);
  box-shadow: 0 12px 30px var(--shadow); font-weight: 600; font-size: 15px;
}
.toast span { flex: 1; min-width: 0; }

@keyframes deal { from { opacity: 0; translate: 0 10px; scale: .97; } }
@keyframes rise { from { translate: -50% 30px; opacity: 0; } to { translate: -50% 0; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; scale: .95; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
