:root {
  --navy: #123b5d;
  --navy-2: #0b2941;
  --blue: #2878a8;
  --pool: #dff4fb;
  --teal: #1f8a86;
  --gold: #f4b942;
  --ink: #17232d;
  --muted: #687782;
  --line: #d8e1e7;
  --paper: #ffffff;
  --bg: #f3f7f9;
  --danger: #a93636;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 18px 14px;
  color: white;
  background: linear-gradient(135deg, var(--navy-2), var(--navy));
  box-shadow: 0 5px 22px rgba(8, 38, 58, .2);
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 22px; letter-spacing: -.02em; }
h2 { margin-bottom: 14px; font-size: 20px; }
h3 { margin-bottom: 4px; font-size: 16px; }
.eyebrow { font-size: 11px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; opacity: .72; }
.icon-btn {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 50%;
  color: white;
  background: rgba(255,255,255,.1);
  font-size: 25px;
}

main { max-width: 880px; margin: 0 auto; padding: 14px 14px 100px; }
.tabs {
  position: sticky;
  top: 82px;
  z-index: 15;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 14px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(10px);
}
.tab {
  min-height: 42px;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 750;
}
.tab.active { color: white; background: var(--navy); }

.panel, .meet-hero, .hand-card, .history-card {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 5px 18px rgba(20, 55, 75, .06);
}
.panel { padding: 18px; }
.access-panel { margin-top: 28px; }
.meet-hero {
  padding: 18px;
  color: white;
  border: 0;
  background: linear-gradient(135deg, #1b7095, #14506f);
}
.meet-hero select {
  width: 100%;
  margin-top: 12px;
  color: var(--ink);
  background: white;
}
.meet-meta { display: flex; gap: 10px; margin-top: 8px; font-size: 13px; opacity: .85; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }

.agenda-list { display: grid; gap: 10px; }
.agenda-row {
  display: grid;
  grid-template-columns: 66px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: 14px;
  background: white;
}
.agenda-row.revy { border-left-color: var(--teal); }
.planned-time { color: var(--navy); font-size: 16px; font-weight: 850; }
.event-meta { color: var(--muted); font-size: 12px; }
.event-desc { margin: 3px 0; font-weight: 780; }
.result-button {
  min-width: 68px;
  min-height: 44px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--navy);
  background: var(--pool);
  font-size: 12px;
  font-weight: 800;
}
.result-value { font-size: 15px; }
.source-badge { display: block; margin-top: 2px; color: var(--muted); font-size: 9px; text-transform: uppercase; }
.standard-badge {
  display: inline-block;
  margin: 3px 2px 0;
  padding: 2px 5px;
  border-radius: 999px;
  color: #17232d;
  font-size: 9px;
  font-weight: 900;
  line-height: 1.2;
  text-transform: uppercase;
}
.standard-badge.bronze { color: white; background: #a8642a; }
.standard-badge.silver { background: #d8dde2; }
.standard-badge.gold { background: #ffd84d; }
.delta { display: block; margin-top: 2px; font-size: 10px; }
.delta.drop, .drop-text { color: #14734d; }
.delta.add, .add-text { color: #a34c35; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

.hand-card { overflow: hidden; }
.hand-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  color: white;
  background: var(--navy);
}
.hand-card.revy .hand-card-header { background: var(--teal); }
.hand-grid {
  display: grid;
  grid-template-columns: .65fr .55fr 2.4fr .55fr .55fr .9fr .9fr;
  align-items: stretch;
}
.hand-cell {
  min-width: 0;
  padding: 10px 5px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: center;
  font-size: 12px;
}
.hand-cell:nth-child(7n) { border-right: 0; }
.hand-head {
  padding: 7px 4px;
  color: var(--muted);
  background: #f4f7f8;
  font-size: 10px;
  font-weight: 850;
}
.hand-desc { text-align: left; font-weight: 720; }
.hand-actual { color: var(--blue); font-weight: 850; }
.relay-note { display: block; margin-top: 2px; color: var(--muted); font-size: 9px; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 14px; padding: 4px; border-radius: 13px; background: #dfe8ed; }
.segmented button { min-height: 42px; border: 0; border-radius: 9px; background: transparent; font-weight: 800; }
.segmented button.active { color: white; background: var(--navy); }
.history-card { padding: 16px; }
.history-top { display: flex; justify-content: space-between; gap: 12px; }
.pb { color: var(--teal); text-align: right; font-weight: 850; }
.history-list { margin-top: 12px; border-top: 1px solid var(--line); }
.history-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.history-row > span { min-width: 0; }
.history-row > strong { flex: 0 0 auto; text-align: right; }
.history-row small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; font-weight: 600; }
.season-summary {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  margin-bottom: 8px;
}
.season-summary > div {
  padding: 10px 5px;
  border: 1px solid var(--line);
  border-radius: 12px;
  text-align: center;
  background: white;
}
.season-summary strong, .season-summary span { display: block; }
.season-summary strong { font-size: 20px; }
.season-summary span { color: var(--muted); font-size: 9px; text-transform: uppercase; }
.season-summary .gold { border-color: #e2bd21; background: #fff8d2; }
.season-summary .silver { border-color: #b7c0c8; background: #f0f3f5; }
.season-summary .bronze { border-color: #a8642a; background: #f8eadf; }
.place-summary {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 12px;
}
.place-summary strong { color: var(--navy); }
.provisional { color: #8b6700; }

label { display: block; margin-bottom: 13px; color: var(--muted); font-size: 12px; font-weight: 750; }
input, select {
  width: 100%;
  min-height: 46px;
  margin-top: 5px;
  padding: 10px 12px;
  border: 1px solid #bdcbd4;
  border-radius: 11px;
  color: var(--ink);
  background: white;
  font-size: 16px;
}
input:focus, select:focus { outline: 3px solid rgba(40,120,168,.16); border-color: var(--blue); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.primary {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  color: white;
  background: var(--navy);
  font-weight: 850;
}
.primary:disabled { opacity: .5; }
.status { margin: 12px 0; color: var(--muted); font-size: 13px; }
.parse-table { width: 100%; margin: 12px 0; border-collapse: collapse; font-size: 12px; }
.parse-table th, .parse-table td { padding: 7px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.official-grid { display: grid; grid-template-columns: 1.7fr 1fr .55fr .55fr; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.official-grid input, .official-grid select { min-height: 42px; margin: 0; }
.official-head { color: var(--muted); font-size: 10px; font-weight: 850; text-transform: uppercase; }
.source-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.source-row a { color: var(--blue); font-weight: 750; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  background: rgba(5, 22, 34, .55);
}
.modal {
  position: relative;
  width: min(100%, 520px);
  max-height: 92vh;
  overflow: auto;
  padding: 22px;
  border-radius: 20px;
  background: white;
}
.modal-close { position: absolute; top: 10px; right: 12px; z-index: 1; width: 40px; height: 40px; border: 0; background: transparent; font-size: 28px; }
.toast-container { position: fixed; left: 16px; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 80; display: grid; justify-items: center; gap: 8px; pointer-events: none; }
.toast { max-width: 520px; padding: 12px 16px; border-radius: 12px; color: white; background: var(--navy-2); box-shadow: 0 8px 25px rgba(0,0,0,.2); font-size: 13px; }
.toast.error { background: var(--danger); }

@media (max-width: 480px) {
  main { padding-left: 10px; padding-right: 10px; }
  .tabs { top: 80px; }
  .agenda-row { grid-template-columns: 58px 1fr 65px; gap: 8px; padding: 11px 9px; }
  .event-desc { font-size: 14px; }
  .hand-cell { padding: 9px 2px; font-size: 10px; }
  .hand-desc { font-size: 9px; }
  .two-col { grid-template-columns: 1fr; gap: 0; }
  .official-grid { grid-template-columns: 1.35fr .85fr .55fr .55fr; gap: 5px; }
  .season-summary { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
  .season-summary strong { font-size: 17px; }
}

@media print {
  body { background: white; }
  .topbar, .tabs, #todayTab, #historyTab, #importTab { display: none !important; }
  main { max-width: none; padding: 0; }
  #appView, #cardsTab { display: block !important; }
  .hand-card { break-inside: avoid; box-shadow: none; }
}
