:root {
  --bg:        #0d1117;
  --bg-raised: #161b22;
  --bg-hover:  #1c232d;
  --line:      #262d38;
  --line-soft: #1d242e;
  --text:      #e6edf3;
  --text-dim:  #8b949e;
  --text-faint:#56606b;

  /* signature accent: badge amber */
  --gold:      #e3a008;
  --gold-soft: rgba(227,160,8,0.12);

  /* event type colors */
  --shift:     #3b82f6;
  --court:     #a855f7;
  --overtime:  #ef4444;
  --off:       #2f6f4f;
  --training:  #14b8a6;
  --other:     #6b7785;

  --mono: 'JetBrains Mono', 'SF Mono', ui-monospace, 'Cascadia Code', Menlo, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  --radius: 10px;
}

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

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a { color: inherit; }

/* ---------- auth pages ---------- */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(227,160,8,0.07), transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 36px 32px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 28px;
}
.brand .shield {
  width: 34px; height: 34px;
  flex: none;
}
.brand h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.brand h1 span { color: var(--gold); }
.auth-card h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 4px;
}
.auth-card .sub {
  color: var(--text-dim);
  font-size: 13.5px;
  margin-bottom: 26px;
}
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 7px;
}
input[type=text], input[type=password], input[type=date], input[type=time],
select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  padding: 11px 13px;
  font-size: 14px;
  font-family: var(--sans);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}
textarea { resize: vertical; min-height: 64px; }

.btn {
  width: 100%;
  border: none;
  border-radius: var(--radius);
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--gold);
  color: #1a1205;
  transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}
.btn-ghost:hover { background: var(--bg-hover); filter: none; }

.auth-foot {
  margin-top: 22px;
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
}
.auth-foot a { color: var(--gold); text-decoration: none; font-weight: 500; }
.auth-foot a:hover { text-decoration: underline; }

.alert {
  border-radius: var(--radius);
  padding: 10px 13px;
  font-size: 13px;
  margin-bottom: 18px;
  border: 1px solid;
}
.alert-error { background: rgba(239,68,68,0.08); border-color: rgba(239,68,68,0.3); color: #fca5a5; }
.alert-ok    { background: rgba(47,111,79,0.12); border-color: rgba(47,111,79,0.4); color: #86efac; }

/* ---------- app shell ---------- */
.topbar {
  height: 60px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  background: var(--bg-raised);
  position: sticky; top: 0; z-index: 20;
}
.topbar .brand { margin: 0; }
.topbar .brand h1 { font-size: 14px; }
.user-chip {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  color: var(--text-dim);
}
.user-chip .who { font-family: var(--mono); color: var(--text); }
.user-chip a {
  text-decoration: none;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  border: 1px solid var(--line);
  padding: 6px 11px;
  border-radius: 8px;
  transition: all .15s;
}
.user-chip a:hover { color: var(--text); border-color: var(--text-faint); }

.shell { max-width: 1080px; margin: 0 auto; padding: 26px 22px 60px; }

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 14px;
}
.cal-title { display: flex; align-items: baseline; gap: 12px; }
.cal-title .month {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.cal-title .year {
  font-family: var(--mono);
  font-size: 15px;
  color: var(--gold);
}
.nav-group { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: all .15s;
}
.icon-btn:hover { background: var(--bg-hover); border-color: var(--text-faint); }
.today-btn {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0 14px;
  height: 38px;
  display: grid; place-items: center;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer; text-decoration: none;
  transition: all .15s;
}
.today-btn:hover { background: var(--bg-hover); border-color: var(--text-faint); }

/* ---------- legend ---------- */
.legend {
  display: flex; flex-wrap: wrap; gap: 16px;
  margin-bottom: 18px;
  font-size: 12px; color: var(--text-dim);
}
.legend .lg { display: flex; align-items: center; gap: 6px; }
.legend .dot { width: 9px; height: 9px; border-radius: 3px; }

/* ---------- calendar grid ---------- */
.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 6px;
}
.weekdays div {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  text-align: center;
  padding: 4px 0;
}
.grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 7px;
}
.cell {
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  min-height: 104px;
  padding: 8px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  display: flex; flex-direction: column;
  position: relative;
  overflow: hidden;
}
.cell:hover { border-color: var(--text-faint); background: var(--bg-hover); }
.cell.muted { opacity: 0.4; }
.cell.today {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px var(--gold-soft);
}
.cell .daynum {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.cell.today .daynum { color: var(--gold); font-weight: 700; }
.evt {
  font-size: 11px;
  border-radius: 5px;
  padding: 3px 6px;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 3px solid;
  background: var(--bg);
  line-height: 1.35;
}
.evt .et {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  opacity: 0.85;
}
.evt-shift    { border-color: var(--shift); }
.evt-court    { border-color: var(--court); }
.evt-overtime { border-color: var(--overtime); }
.evt-off      { border-color: var(--off); }
.evt-training { border-color: var(--training); }
.evt-other    { border-color: var(--other); }
.evt-more {
  font-size: 10px;
  color: var(--text-faint);
  padding: 1px 2px;
  line-height: 1.3;
}
.dot-shift{background:var(--shift)} .dot-court{background:var(--court)}
.dot-overtime{background:var(--overtime)} .dot-off{background:var(--off)}
.dot-training{background:var(--training)} .dot-other{background:var(--other)}

/* ---------- summary strip ---------- */
.summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}
.stat {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px;
}
.stat .n {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 700;
}
.stat .l {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(2px);
  display: none;
  place-items: center;
  z-index: 50;
  padding: 20px;
}
.modal-back.open { display: grid; }
.modal {
  width: 100%;
  max-width: 440px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h3 {
  font-size: 18px;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px;
}
.modal .modal-date {
  font-family: var(--mono);
  color: var(--gold);
  font-size: 13px;
  margin-bottom: 18px;
}
.modal .close {
  background: none; border: none; color: var(--text-dim);
  font-size: 22px; cursor: pointer; line-height: 1;
}
.modal .close:hover { color: var(--text); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.existing { margin-bottom: 18px; }
.existing-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg);
  border: 1px solid var(--line-soft);
  border-left: 3px solid var(--other);
  border-radius: 8px;
  padding: 9px 11px;
  margin-bottom: 7px;
  font-size: 13px;
}
.existing-item .ei-main { flex: 1; min-width: 0; }
.existing-item .ei-type {
  font-family: var(--mono); font-size: 9.5px;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-dim);
}
.existing-item .ei-time { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
.existing-item form { margin: 0; }
.del-btn {
  background: none; border: 1px solid var(--line);
  color: var(--text-dim); border-radius: 7px;
  width: 28px; height: 28px; cursor: pointer; flex: none;
  transition: all .15s;
}
.del-btn:hover { color: #fca5a5; border-color: rgba(239,68,68,0.4); }
.divider { height:1px; background: var(--line); margin: 18px 0; border: none; }
.section-label {
  font-family: var(--mono); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-faint); margin-bottom: 12px;
}

@media (max-width: 680px) {
  .summary { grid-template-columns: repeat(2, 1fr); }
  .cell { min-height: 78px; padding: 5px; }
  .cell .evt .et { display: none; }
  .cal-title .month { font-size: 21px; }
}

/* ===================================================
   MOBILE REFINEMENTS
   =================================================== */

/* prevent iOS auto-zoom: inputs need >=16px font on small screens */
@media (max-width: 768px) {
  input[type=text], input[type=password], input[type=date],
  input[type=time], select, textarea {
    font-size: 16px;
  }
}

@media (max-width: 560px) {
  /* tighter shell padding */
  .shell { padding: 16px 12px 48px; }

  /* topbar: keep brand + actions on one row, drop the long label */
  .topbar { padding: 0 14px; height: 56px; }
  .signed-in { display: none; }
  .user-chip { gap: 8px; }
  .user-chip a { padding: 8px 12px; font-size: 12px; }

  /* summary: 2x2 with a bit less padding */
  .summary { gap: 8px; margin-bottom: 18px; }
  .stat { padding: 11px 12px; }
  .stat .n { font-size: 21px; }
  .stat .l { font-size: 10px; }

  /* calendar header stacks cleanly */
  .cal-head { gap: 10px; margin-bottom: 14px; }
  .nav-group { width: 100%; }
  /* let "Today" stretch between the two arrows for a big tap target */
  .nav-group .today-btn { flex: 1; }
  .icon-btn, .today-btn { height: 44px; }
  .icon-btn { width: 44px; }

  /* legend wraps to a compact two-ish rows */
  .legend { gap: 10px 14px; margin-bottom: 14px; font-size: 11px; }

  /* calendar grid: smaller gaps, dots instead of text labels */
  .grid { gap: 4px; }
  .weekdays div { font-size: 10px; letter-spacing: 0.04em; }
  .cell { min-height: 64px; padding: 4px; border-radius: 8px; }
  .cell .daynum { font-size: 12px; margin-bottom: 3px; }

  /* on phones, collapse each event to a colored dot row to save space */
  .cell .evt {
    font-size: 0;            /* hide the text */
    padding: 0;
    height: 6px;
    border-radius: 3px;
    border-left: none;
    margin-bottom: 3px;
    background: var(--other);
  }
  .cell .evt .et { display: none; }
  .cell .evt-shift    { background: var(--shift); }
  .cell .evt-court    { background: var(--court); }
  .cell .evt-overtime { background: var(--overtime); }
  .cell .evt-off      { background: var(--off); }
  .cell .evt-training { background: var(--training); }
  .cell .evt-other    { background: var(--other); }
  /* the "+N more" line stays as small faint text */
  .cell .evt-more { font-size: 9px; }

  /* modal: slide up from bottom like a native sheet */
  .modal-back { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    border-radius: 18px 18px 0 0;
    max-height: 92vh;
    padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  }
  .modal h3 { font-size: 17px; }
  .modal .close { font-size: 28px; padding: 4px; margin: -4px; } /* bigger tap target */

  /* form controls get taller for fingers */
  input[type=text], input[type=password], input[type=date],
  input[type=time], select, textarea { padding: 13px 13px; }
  .btn { padding: 14px; font-size: 15px; }
  .seg { padding: 11px; }

  /* weekday picker buttons a touch taller */
  .dow span { height: 42px; font-size: 11px; }

  /* existing entries: bigger delete targets */
  .del-btn { width: 34px; height: 34px; }

  /* admin tables: let them scroll horizontally without breaking layout */
  .panel { border-radius: 8px; }
}

/* very small phones */
@media (max-width: 360px) {
  .cell { min-height: 58px; }
  .stat .n { font-size: 19px; }
  .user-chip a { padding: 7px 10px; }
}

/* respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- single / repeating toggle ---------- */
.add-toggle {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 18px;
}
.seg {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  padding: 8px;
  border-radius: 7px;
  cursor: pointer;
  transition: all .15s;
}
.seg.active { background: var(--bg-raised); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.3); }

/* ---------- weekday picker ---------- */
.dow-picker {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}
.dow {
  position: relative;
  display: block;
  cursor: pointer;
}
.dow input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.dow span {
  display: grid;
  place-items: center;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg);
  transition: all .12s;
  user-select: none;
}
.dow input:checked + span {
  background: var(--gold-soft);
  border-color: var(--gold);
  color: var(--gold);
  font-weight: 700;
}
.dow input:focus-visible + span { box-shadow: 0 0 0 3px var(--gold-soft); }

.xm-note {
  font-size: 12px;
  color: var(--gold);
  margin: -6px 0 14px;
  font-family: var(--mono);
}
@media (max-width: 680px) {
  .dow span { height: 34px; font-size: 10px; }
}