:root {
  --bg:         #0a1220;
  --surface:    #111c2e;
  --surface-2:  #1b2a40;
  --border:     rgba(40,57,80,0.8);
  --text:       #eef3f8;
  --muted:      #8fa0bb;
  --accent:     #4ade80;
  --accent-dim: rgba(74,222,128,0.12);
  --accent-txt: #0a1220;
  --gold:       #e0b84a;
  --silver:     #b9c3d1;
  --danger:     #e6685f;
  --radius:     12px;
  --radius-sm:  8px;
  --shadow:     0 8px 32px rgba(0,0,0,0.5);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(74,222,128,.1), transparent),
    var(--bg);
  min-height: 100vh;
}

.app { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem 2rem;
  margin-bottom: 2rem;
  background: linear-gradient(135deg, #0c1626, #0e1b2d);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.header-brand { display: flex; align-items: center; gap: 1rem; }

.header-actions { display: flex; align-items: center; gap: .6rem; }

.badge {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: .25rem .6rem;
  border-radius: 999px;
}

.badge-admin  { background: rgba(224,184,74,.15); color: var(--gold);   border: 1px solid rgba(224,184,74,.4); }
.badge-public { background: rgba(74,222,128,.1);  color: var(--accent); border: 1px solid rgba(74,222,128,.3); }

.header-icon {
  width: 3rem; height: 3rem;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  background: var(--accent);
  border-radius: 50%;
  flex-shrink: 0;
}

.header h1 { font-size: clamp(1.3rem, 3vw, 1.8rem); font-weight: 800; letter-spacing: .01em; }
.header-sub { color: var(--muted); font-size: .82rem; margin-top: .2rem; }

/* ── Main layout ── */
.main { display: flex; flex-direction: column; gap: 1.5rem; }

/* ── Panel ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.panel-consolation { border-color: rgba(185,195,209,.2); }

.panel-header { margin-bottom: 1.25rem; }
.panel-header h2 { font-size: 1.05rem; font-weight: 700; }
.panel-hint { color: var(--muted); font-size: .82rem; margin-top: .25rem; }

/* ── Bracket ── */
.bracket-scroll { overflow-x: auto; padding-bottom: .5rem; }

.bracket {
  display: flex;
  gap: 2rem;
  align-items: stretch;
  min-width: max-content;
  padding: .5rem 0;
}

.bracket-round {
  display: flex;
  flex-direction: column;
  min-width: 210px;
}

.round-title {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: .75rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}

.round-matches {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  gap: .75rem;
}

/* ── Match card ── */
.match-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: default;
  transition: border-color .15s, box-shadow .15s, transform .1s;
  user-select: none;
}

.match-card.is-playable {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px rgba(224,184,74,.25);
  cursor: pointer;
}

.match-card.is-playable:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(224,184,74,.2);
}

.match-card.is-done {
  border-color: rgba(74,222,128,.35);
  cursor: pointer;
}

.match-card.is-done:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(74,222,128,.15);
}

/* ── Match slot ── */
.match-slot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: 9px 12px;
  min-height: 40px;
  border-bottom: 1px solid var(--border);
  cursor: text;
  transition: background .1s;
}

.match-slot:last-of-type { border-bottom: none; }

.match-slot.is-empty .slot-name { color: var(--muted); font-style: italic; font-size: .85rem; }

.match-slot.is-winner {
  background: var(--accent-dim);
  font-weight: 700;
}

.match-slot.slot-bye {
  opacity: .5;
  cursor: default;
}

.slot-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .88rem;
}

.slot-scores {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.slot-score {
  font-size: 1.05rem;
  font-weight: 700;
  min-width: 16px;
  text-align: right;
  color: var(--accent);
}

.slot-tb-score {
  font-size: .78rem;
  color: var(--gold);
  font-weight: 600;
}

.match-action {
  padding: 5px 8px;
  border-top: 1px solid var(--border);
}

.btn-match-result,
.btn-match-edit {
  width: 100%;
  padding: .35rem .5rem;
  font: inherit;
  font-size: .76rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
  text-align: center;
}

.btn-match-result {
  color: var(--gold);
  background: rgba(224,184,74,.08);
  border: 1px solid rgba(224,184,74,.3);
}
.btn-match-result:hover { background: rgba(224,184,74,.2); }

.btn-match-edit {
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
}
.btn-match-edit:hover { color: var(--text); background: var(--surface-2); }

.match-tb {
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--muted);
  text-align: center;
  padding: 2px 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

/* ── Name modal input ── */
.name-input {
  width: 100%;
  padding: .65rem .85rem;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
.name-input::placeholder {
  color: var(--muted);
  -webkit-text-fill-color: var(--muted);
  opacity: 1;
}
.name-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ── Champion ── */
.champion {
  margin-top: 1.25rem;
  padding: 1rem 1.25rem;
  text-align: center;
  background: linear-gradient(135deg, rgba(224,184,74,.12), rgba(74,222,128,.08));
  border: 1px solid rgba(224,184,74,.3);
  border-radius: var(--radius);
}

.champion-silver {
  background: linear-gradient(135deg, rgba(185,195,209,.1), rgba(74,222,128,.06));
  border-color: rgba(185,195,209,.3);
}

.champion-label {
  display: block;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--gold);
  margin-bottom: .35rem;
}

.champion-silver .champion-label { color: var(--silver); }

.champion-name {
  font-size: 1.6rem;
  font-weight: 800;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .6rem 1.1rem;
  font: inherit;
  font-weight: 600;
  font-size: .88rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.97); }

.btn-primary { background: var(--accent); color: var(--accent-txt); }
.btn-primary:hover { background: #6ee7a0; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }

.btn-sm { padding: .4rem .85rem; font-size: .82rem; }

/* ── Modal ── */
.modal {
  padding: 0;
  border: none;
  background: transparent;
  max-width: 480px;
  width: calc(100% - 2rem);
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.modal::backdrop {
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-round {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gold);
  margin-bottom: .25rem;
}

.modal-title { font-size: 1.05rem; font-weight: 700; color: var(--text); }

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: .1rem .3rem;
  flex-shrink: 0;
}
.modal-close:hover { color: var(--text); }

.score-section { padding: 1.25rem 1.5rem; }

.score-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: .75rem 1rem;
  align-items: end;
  margin-bottom: 1rem;
}

.score-player { display: flex; flex-direction: column; gap: .4rem; }

.score-pname {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-sep {
  text-align: center;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 600;
  padding-bottom: .65rem;
}

.set-input {
  width: 100%;
  padding: .6rem .4rem;
  font: inherit;
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
  -moz-appearance: textfield;
}
.set-input::placeholder {
  color: var(--muted);
  -webkit-text-fill-color: var(--muted);
  opacity: 1;
}
.set-input::-webkit-outer-spin-button,
.set-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.set-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.tb-section {
  margin-bottom: 1rem;
  padding: .85rem 1rem;
  background: var(--surface-2);
  border: 1px dashed var(--gold);
  border-radius: var(--radius-sm);
}

.tb-title {
  font-size: .78rem;
  font-weight: 700;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: .65rem;
}

.set-input-sm { font-size: 1.1rem; }

.tb-hint {
  font-size: .72rem;
  color: var(--muted);
  margin-top: .5rem;
}

.score-hint { font-size: .78rem; color: var(--muted); margin-bottom: .5rem; }

.score-error {
  font-size: .85rem;
  color: #fff;
  background: rgba(230,104,95,.18);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: .6rem .85rem;
  margin-top: .5rem;
}

/* ── Tournament list ── */
.tournament-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  margin-top: .5rem;
}

.tournament-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .85rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  flex-wrap: wrap;
}

.t-info {
  flex: 1;
  min-width: 0;
}

.t-name {
  display: block;
  font-weight: 700;
  font-size: .95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.t-date {
  font-size: .75rem;
  color: var(--muted);
}

.t-progress {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
}

.t-progress-bar {
  width: 80px;
  height: 5px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.t-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .3s;
}

.t-progress-label {
  font-size: .72rem;
  color: var(--muted);
  white-space: nowrap;
}

.t-actions {
  display: flex;
  gap: .4rem;
  flex-shrink: 0;
}

.btn-danger { color: var(--danger) !important; border-color: rgba(230,104,95,.3) !important; }
.btn-danger:hover { background: rgba(230,104,95,.1) !important; }

.t-item-default {
  border-color: rgba(224,184,74,.35);
  background: linear-gradient(135deg, var(--surface-2) 0%, rgba(224,184,74,.06) 100%);
}

.t-default-badge {
  display: inline-block;
  margin-left: .4rem;
  padding: .05rem .4rem;
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  background: rgba(224,184,74,.18);
  color: var(--gold);
  border: 1px solid rgba(224,184,74,.4);
  border-radius: 4px;
  vertical-align: middle;
}

.btn-default-active {
  color: var(--gold) !important;
  border-color: rgba(224,184,74,.5) !important;
  background: rgba(224,184,74,.12) !important;
}
.btn-default-active:hover { background: rgba(224,184,74,.2) !important; }

.empty-state {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  font-size: .9rem;
}

/* ── Login page ── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.login-header { text-align: center; margin-bottom: 1.75rem; }
.login-title  { font-size: 1.3rem; font-weight: 800; color: var(--text); margin-bottom: .3rem; }
.login-sub    { font-size: .82rem; color: var(--muted); }

.login-form { display: flex; flex-direction: column; gap: 1rem; }

.login-field { display: flex; flex-direction: column; gap: .4rem; }
.login-field label {
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
}

.login-error {
  font-size: .85rem;
  color: #fff;
  background: rgba(230,104,95,.18);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: .6rem .85rem;
}

.login-footer { margin-top: 1.25rem; text-align: center; }
.login-public-link { font-size: .82rem; color: var(--muted); text-decoration: none; }
.login-public-link:hover { color: var(--text); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

/* ── Touch baseline ── */
button, a, [data-match-action], .match-slot {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ══════════════════════════════════════
   MOBILE  (≤ 640 px)
══════════════════════════════════════ */
@media (max-width: 640px) {

  /* App wrapper */
  .app { padding: .75rem; }

  /* ── Header ── */
  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: .75rem;
    padding: 1rem 1.1rem;
    margin-bottom: 1.25rem;
    border-radius: var(--radius-sm);
  }
  .header-brand { gap: .65rem; }
  .header-icon  { width: 2.4rem; height: 2.4rem; font-size: 1.2rem; }
  .header h1    { font-size: 1.15rem; }
  .header-sub   { font-size: .75rem; }
  .header-actions { width: 100%; flex-wrap: wrap; gap: .4rem; }
  .header-actions .btn { font-size: .78rem; padding: .35rem .7rem; }
  .badge { font-size: .6rem; }

  /* ── Panel ── */
  .panel {
    padding: .9rem;
    border-radius: var(--radius-sm);
  }
  .panel-header { margin-bottom: .9rem; }
  .panel-header h2 { font-size: .95rem; }

  /* ── Bracket scroll with snap ── */
  .bracket-scroll {
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding-bottom: .75rem;
    /* subtle scroll shadow hint */
    background:
      linear-gradient(to right, var(--surface) 0%, transparent 5%),
      linear-gradient(to left,  var(--surface) 0%, transparent 5%)
      right center / 100% 100% no-repeat;
  }

  .bracket { gap: .75rem; padding: .25rem .1rem; }

  .bracket-round {
    min-width: 155px;
    scroll-snap-align: start;
  }

  .round-title { font-size: .65rem; margin-bottom: .6rem; }

  .round-matches { gap: .55rem; }

  /* ── Match cards ── */
  .match-slot {
    padding: 8px 10px;
    min-height: 38px;
  }

  .slot-name { font-size: .82rem; }

  .match-action { padding: 4px 6px; }

  .btn-match-result,
  .btn-match-edit { font-size: .72rem; padding: .3rem .4rem; }

  /* ── Champion ── */
  .champion { padding: .85rem 1rem; }
  .champion-name { font-size: 1.3rem; }

  /* ── Modal → bottom sheet ── */
  .modal {
    width: 100%;
    max-width: 100%;
    /* override desktop centering */
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    padding: 0;
  }

  .modal-content {
    border-radius: var(--radius) var(--radius) 0 0;
    /* safe area for iPhone home indicator */
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  /* drag handle hint */
  .modal-content::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 999px;
    margin: .75rem auto -.25rem;
  }

  .modal-header { padding: .9rem 1.1rem; }
  .modal-title  { font-size: .95rem; }

  .score-section { padding: .9rem 1.1rem; }

  /* ── Score inputs ── */
  .set-input {
    font-size: 2rem;
    padding: .9rem .4rem;
  }

  .score-sep { font-size: 1rem; padding-bottom: .9rem; }

  .set-input-sm { font-size: 1.5rem; }

  .modal-footer {
    padding: .75rem 1.1rem;
    padding-bottom: max(.75rem, env(safe-area-inset-bottom));
    gap: .5rem;
  }

  /* stack footer buttons on very small screens */
  @media (max-width: 380px) {
    .modal-footer { flex-direction: column-reverse; }
    .modal-footer .btn { width: 100%; }
  }

  /* ── Name input ── */
  .name-input { font-size: 1.05rem; padding: .75rem .85rem; }

  /* ── Login ── */
  .login-card { padding: 1.5rem 1.1rem; border-radius: var(--radius-sm); }
  .login-title { font-size: 1.15rem; }
}

