*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }

/* ══ RESET & ROOT ══════════════════════════════════════════════ */
:root {
  --bg:    #0d0d0f; --bg2: #141417; --bg3: #1c1c21; --bg4: #242429;
  --border: #2e2e36;
  --gold: #c9a84c; --gold-l: #e8c97a; --gold-d: #7a6128;
  --cream: #f0ead6; --text: #c8c4b8; --text-d: #6e6b62;
  --red: #c05454; --red-d: #3d1e1e;
  --green: #5a9e6f; --green-d: #1e3328;
  --blue: #4a7fa5; --blue-d: #1a3040;
  --amber: #d4813a; --amber-d: #3a2010;
  --r: 10px;
  --nav-h: 68px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

/* ══ FONT SIZE SCALES ════════════════════════════════════════ */
html                { font-size: 14px; }
html.fs-large       { font-size: 16px; }
html.fs-xlarge      { font-size: 18px; }

html.fs-large  .content-scroll,
html.fs-large  .modal-box,
html.fs-large  .login-wrap,
html.fs-large  #s-confirm > div { font-size: 16px; }

html.fs-xlarge .content-scroll,
html.fs-xlarge .modal-box,
html.fs-xlarge .login-wrap,
html.fs-xlarge #s-confirm > div { font-size: 18px; }

/* ══ LIGHT THEME ════════════════════════════════════════════ */
body.light {
  --bg:    #f5f3ee; --bg2: #ffffff; --bg3: #eceae4; --bg4: #e0ddd5;
  --border: #d4d0c8;
  --gold: #a07828; --gold-l: #c9a84c; --gold-d: #7a5c1a;
  --cream: #1a1814; --text: #3d3a32; --text-d: #8a8578;
  --red: #b03030; --red-d: rgba(176,48,48,.12);
  --green: #3d7a52; --green-d: rgba(61,122,82,.12);
  --blue: #2d6088; --blue-d: rgba(45,96,136,.12);
  --amber: #b06820; --amber-d: rgba(176,104,32,.12);
}
body.light .app-header    { background: #ffffff; box-shadow: 0 1px 0 var(--border); }
body.light .bottom-nav    { background: #ffffff; }
body.light .modal-box     { background: #ffffff; }
body.light .login-card    { background: #ffffff; }
body.light #s-login       { background: radial-gradient(ellipse 80% 40% at 50% 0%, rgba(160,120,40,.08) 0%, transparent 60%), var(--bg); }

/* Theme / font toggle buttons */
.theme-toggle {
  background: none; border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 12px;
  cursor: pointer; font-size: 13px; line-height: 1;
  color: var(--text-d); transition: all .15s;
  display: flex; align-items: center; gap: 4px;
  min-height: 36px;
}
.theme-toggle:hover { border-color: var(--gold-d); color: var(--gold); }

body {
  background: var(--bg); color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  overscroll-behavior: none;
}
.serif { font-family: 'Playfair Display', serif; }
.mono  { font-family: 'DM Mono', monospace; }
input, textarea, select, button { font-family: inherit; }

/* ══ SCREENS ════════════════════════════════════════════════ */
.screen { display: none; position: fixed; inset: 0; overflow: hidden; }
.screen.active { display: flex; flex-direction: column; }
/* Login and create screens need their own scroll — override hidden */
#s-login, #s-create { overflow-y: auto; }

/* ══ LOGIN SCREEN ═══════════════════════════════════════════ */
#s-login {
  background: radial-gradient(ellipse 80% 40% at 50% 0%, rgba(201,168,76,.08) 0%, transparent 60%), var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: calc(var(--safe-top) + 40px) 20px calc(var(--safe-bottom) + 40px);
}
.login-wrap { width: 100%; max-width: 380px; margin: 0 auto; }
.login-logo {
  font-family: 'Playfair Display', serif;
  font-size: clamp(42px, 12vw, 64px);
  font-weight: 900; font-style: italic;
  color: var(--cream); letter-spacing: -.02em;
  line-height: 1; text-align: center; margin-bottom: 6px;
}
.login-logo span { color: var(--gold); }
.login-tagline {
  font-family: 'DM Mono', monospace; font-size: 10px;
  letter-spacing: .2em; text-transform: uppercase;
  color: var(--text-d); text-align: center; margin-bottom: 28px;
}
.login-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--r); padding: 22px 20px; margin-bottom: 14px;
}
.login-card-title {
  font-family: 'Playfair Display', serif; font-size: 18px;
  color: var(--cream); margin-bottom: 16px;
}
/* Form fields — larger targets */
.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--text-d); margin-bottom: 7px;
}
.field input, .field select {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; color: var(--cream); padding: 13px 14px;
  font-size: 16px; transition: border-color .15s;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--gold-d); }
.field input::placeholder { color: var(--text-d); }
.field select option { background: var(--bg3); }
.login-hint {
  background: rgba(201,168,76,.06); border: 1px solid rgba(201,168,76,.2);
  border-radius: var(--r); padding: 12px 14px; margin-bottom: 14px;
  font-size: 12px; color: var(--text-d); line-height: 1.7;
}
.login-hint strong { color: var(--gold); display: block; margin-bottom: 4px; font-size: 10px; text-transform: uppercase; letter-spacing: .1em; }
.login-hint code { font-family: 'DM Mono', monospace; font-size: 12px; color: var(--cream); background: var(--bg4); padding: 1px 5px; border-radius: 3px; }
.btn-login {
  width: 100%; padding: 15px; background: var(--gold); color: #0d0d0f;
  border: none; border-radius: 8px; font-size: 15px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; cursor: pointer;
  transition: background .15s, transform .1s; margin-bottom: 8px;
  /* Active press feel */
}
.btn-login:hover  { background: var(--gold-l); }
.btn-login:active { transform: scale(.97); }
.btn-login:disabled { opacity: .5; cursor: default; transform: none; }
.login-err { color: var(--red); font-size: 12px; min-height: 18px; margin: 4px 0 8px; }
.login-demo-note { font-size: 11px; color: var(--text-d); text-align: center; margin-top: 8px; }

/* ══ APP SHELL ══════════════════════════════════════════════ */
#s-app { background: var(--bg); }
.app-header {
  background: var(--bg2); border-bottom: 1px solid var(--border);
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  display: flex; align-items: center; gap: 10px; flex-shrink: 0; z-index: 200;
  position: relative;
}
.app-logo { font-family: 'Playfair Display', serif; font-size: 20px; font-style: italic; font-weight: 700; color: var(--cream); }
.app-logo span { color: var(--gold); }
.app-show { font-size: 11px; color: var(--text-d); flex: 1; text-align: center; }
.app-user { display: flex; align-items: center; gap: 6px; }
.app-user-name { font-size: 12px; color: var(--text-d); }
.btn-logout {
  padding: 7px 12px; background: none; border: 1px solid var(--border);
  border-radius: 6px; color: var(--text-d); font-size: 12px; cursor: pointer;
  min-height: 36px;
}
.btn-logout:hover { color: var(--gold); border-color: var(--gold-d); }

/* ══ CONTENT SCROLL ═════════════════════════════════════════ */
.content-scroll {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(var(--nav-h) + var(--safe-bottom) + 20px);
}
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 2px; }

/* ══ BOTTOM NAV ═════════════════════════════════════════════ */
.bottom-nav {
  position: absolute; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg2); border-top: 1px solid var(--border);
  display: flex; z-index: 50;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; cursor: pointer;
  background: none; border: none; padding: 8px 2px;
  color: var(--text-d); transition: color .15s;
  /* Enforce minimum touch target */
  min-height: 44px;
  /* Active press feedback on touch */
  -webkit-tap-highlight-color: transparent;
}
.nav-btn.active { color: var(--gold); }
.nav-btn:active { opacity: .7; }
.nav-badge {
  position: absolute;
  top: 4px;
  right: 6px;
  background: var(--gold);
  color: #0d0d0f;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  pointer-events: none;
}
.nav-icon { font-size: 22px; line-height: 1; }
.nav-icon-more { font-size: 18px; line-height: 1; letter-spacing: .05em; }
.nav-label { font-size: 9px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; }

/* ══ DESKTOP LAYOUT (≥ 768px) ════════════════════════════════ */
.hidden-past { display: none; }

@media (min-width: 768px) {
  .app-header { padding: 14px 32px; }
  .content-scroll { padding-left: 32px; padding-right: 32px; }
  #panels { max-width: 720px; margin: 0 auto; }
  .modal-box { max-width: 560px; width: 90%; border-radius: 12px; }
  .login-wrap { padding-top: 60px; padding-bottom: 60px; }
  /* On desktop modal centers rather than slides from bottom */
  .modal-ov { align-items: center; }
}

/* ══ PANELS ═════════════════════════════════════════════════ */
.panel { display: none; animation: fadeUp .2s ease; }
.panel.active { display: block; }
@keyframes fadeUp { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }

/* ══ SECTION HEADER ═════════════════════════════════════════ */
.sh { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sh-title { font-family: 'Playfair Display', serif; font-size: 22px; font-weight: 700; color: var(--cream); }
.sh-sub { font-size: 11px; color: var(--text-d); margin-top: 2px; }

/* ══ CARDS ══════════════════════════════════════════════════ */
.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--r); padding: 14px 16px; margin-bottom: 10px;
  /* Subtle press feedback */
  transition: opacity .1s;
}
.card:active { opacity: .85; }
.card-title { font-weight: 600; color: var(--cream); margin-bottom: 4px; font-size: 15px; }
.card-meta  { font-size: 12px; color: var(--text-d); display: flex; gap: 10px; flex-wrap: wrap; }
.card-body  { font-size: 13px; color: var(--text); margin-top: 10px; line-height: 1.65; }
.card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.card-accent-l { border-left: 3px solid; }

/* ══ TAGS ═══════════════════════════════════════════════════ */
.tag {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 20px; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; border: 1px solid;
}
.tg  { background: rgba(201,168,76,.12); color:var(--gold);  border-color: rgba(201,168,76,.25); }
.tr  { background: rgba(192,84,84,.12);  color:var(--red);   border-color: rgba(192,84,84,.25); }
.tgn { background: rgba(90,158,111,.12); color:var(--green); border-color: rgba(90,158,111,.25); }
.tb  { background: rgba(74,127,165,.12); color:var(--blue);  border-color: rgba(74,127,165,.25); }
.ta  { background: rgba(212,129,58,.12); color:var(--amber); border-color: rgba(212,129,58,.25); }

/* ══ BUTTONS ════════════════════════════════════════════════ */
.btn {
  padding: 10px 18px; border-radius: 8px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: none; transition: all .15s;
  text-transform: uppercase; letter-spacing: .04em; line-height: 1;
  /* Minimum touch target */
  min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn:active { transform: scale(.97); }
.btn-p  { background: var(--gold); color: #0d0d0f; }
.btn-p:hover { background: var(--gold-l); }
.btn-s  { background: var(--bg4); color: var(--text); border: 1px solid var(--border); }
.btn-s:hover { border-color: var(--gold-d); color: var(--gold); }
/* Small variant — relaxed enough for thumb use */
.btn-sm { padding: 8px 14px; font-size: 12px; min-height: 36px; }

/* ══ FORMS ══════════════════════════════════════════════════ */
.fg { margin-bottom: 16px; }
.fl { display: block; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: var(--text-d); margin-bottom: 7px; }
.fi, .fta, .fsel {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; color: var(--cream); padding: 13px 14px; font-size: 16px;
  /* 16px minimum prevents iOS Safari auto-zoom on focus */
}
.fi:focus, .fta:focus, .fsel:focus { outline: none; border-color: var(--gold-d); }
.fta { resize: vertical; min-height: 80px; }
.fsel { -webkit-appearance: none; }
.fsel option { background: var(--bg3); }
/* grid2 collapses on very narrow screens */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 360px) {
  .grid2 { grid-template-columns: 1fr; }
}

/* ══ STATS ══════════════════════════════════════════════════ */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 16px; }
.stat  { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r); padding: 14px 12px; text-align: center; }
.stat-n { font-size: 28px; font-weight: 700; color: var(--cream); line-height: 1; margin-bottom: 4px; }
.stat-l { font-size: 11px; color: var(--text-d); text-transform: uppercase; letter-spacing: .06em; }

/* ══ SECTION LABEL ══════════════════════════════════════════ */
.slabel { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--text-d); margin: 16px 0 8px; }
.slabel:first-child { margin-top: 0; }

/* ══ MILESTONES ═════════════════════════════════════════════ */
.ms-timeline { display: flex; flex-direction: column; gap: 0; }
.ms-strip    { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.ms-strip::-webkit-scrollbar { display: none; }
.ms-chip     { flex-shrink: 0; background: var(--bg2); border: 1px solid var(--border); border-radius: 20px; padding: 6px 14px; font-size: 11px; white-space: nowrap; cursor: pointer; }

/* ══ SIGN-IN HERO ═══════════════════════════════════════════ */
.signin-hero  { text-align: center; padding: 24px 16px; }
.signin-clock { font-size: 44px; color: var(--cream); letter-spacing: -.02em; line-height: 1; }
.signin-date  { font-size: 13px; color: var(--text-d); margin: 6px 0 12px; }
.signin-show  { font-size: 20px; color: var(--cream); margin-bottom: 4px; }
.signin-loc   { font-size: 12px; color: var(--text-d); margin-bottom: 20px; }
.btn-signin   {
  background: var(--gold); color: #0d0d0f; border: none; border-radius: 10px;
  padding: 16px 40px; font-size: 16px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; cursor: pointer;
  transition: background .15s, transform .1s;
  min-height: 52px; /* extra large — this is the primary action */
}
.btn-signin:hover  { background: var(--gold-l); }
.btn-signin:active { transform: scale(.97); }
.btn-signin:disabled { opacity: .6; cursor: default; transform: none; }

/* ══ MODAL ══════════════════════════════════════════════════ */
.modal-ov { display:none; position:fixed; inset:0; background:rgba(0,0,0,.75); z-index:200; align-items:flex-end; padding:0; }
.modal-ov.open { display:flex; }
.modal-box {
  background:var(--bg2); border-top:1px solid var(--border);
  border-radius:16px 16px 0 0; padding:20px 20px 0;
  width:100%; max-height:92vh;
  display: flex; flex-direction: column;
  animation: slideUp .25s ease;
}
/* Scrollable content area inside modal */
.modal-scroll {
  flex: 1; overflow-y: auto; padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}
/* Sticky action buttons always visible at bottom */
.modal-actions {
  display:flex; gap:8px; padding: 14px 0 calc(var(--safe-bottom) + 14px);
  flex-shrink: 0; border-top: 1px solid var(--border); margin-top: 8px;
  background: var(--bg2); /* matches modal background */
}
@keyframes slideUp { from { transform:translateY(100%); } to { transform:translateY(0); } }
.modal-title { font-family:'Playfair Display',serif; font-size:20px; color:var(--cream); margin-bottom:16px; flex-shrink: 0; }
.modal-handle { width:40px; height:4px; background:var(--border); border-radius:2px; margin:0 auto 16px; flex-shrink:0; cursor:grab; }

/* ══ TOAST ══════════════════════════════════════════════════ */
#toasts { position:fixed; bottom:calc(var(--nav-h) + var(--safe-bottom) + 10px); left:16px; right:16px; z-index:300; display:flex; flex-direction:column; gap:6px; pointer-events:none; }
.toast {
  background:var(--bg3); border:1px solid var(--border); border-radius:8px;
  padding:13px 16px; font-size:14px; color:var(--cream);
  animation: toastIn .2s ease, toastOut .3s ease 2.7s forwards;
  border-left:3px solid var(--gold);
}
.toast.ok  { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
@keyframes toastIn  { from{opacity:0;transform:translateY(8px);}to{opacity:1;transform:translateY(0);} }
@keyframes toastOut { from{opacity:1;}to{opacity:0;} }

/* ══ NOTE CAST PILLS ════════════════════════════════════════ */
.note-cast-opt {
  display: inline-flex; align-items: center;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 12px;
  margin: 3px; cursor: pointer; font-size: 13px;
  color: var(--text-d); user-select: none;
  -webkit-user-select: none;
  min-height: 36px;
  transition: all .15s;
}
.note-cast-selected {
  background: rgba(201,168,76,.2) !important;
  border-color: var(--gold) !important;
  color: var(--gold) !important;
}

/* ══ INSTALL BANNER ═════════════════════════════════════════ */
#install-banner {
  display:none; background:rgba(201,168,76,.1); border:1px solid rgba(201,168,76,.3);
  border-radius:var(--r); padding:12px 14px; margin-bottom:12px;
  align-items:center; gap:10px;
}
#install-banner.show { display:flex; }
.install-text { flex:1; font-size:12px; line-height:1.5; }
.install-text strong { color:var(--gold); }

/* ══ LINE NOTES ═════════════════════════════════════════════ */
.ln-type-btn {
  padding: 8px 14px; border-radius: 20px; font-size: 12px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg3); color: var(--text-d);
  transition: all .15s; white-space: nowrap; min-height: 36px;
}
.ln-type-btn.active { border-color: var(--gold); color: var(--gold); background: rgba(201,168,76,.1); }

/* ══ MISC ═══════════════════════════════════════════════════ */
.report-pre {
  background:var(--bg3); border:1px solid var(--border); border-radius:var(--r);
  padding:16px; font-family:'DM Mono',monospace; font-size:11px;
  line-height:1.9; white-space:pre-wrap; color:var(--text);
}

/* ══ PRE-REHEARSAL ALERT ════════════════════════════════════ */
@keyframes pulse {
  0%   { border-color: rgba(192,84,84,.4); }
  50%  { border-color: rgba(192,84,84,.9); }
  100% { border-color: rgba(192,84,84,.4); }
}

/* ══ LOGIN SCREEN CREATE FORM ═══════════════════════════════ */
#s-create { background: var(--bg); }  /* scroll handled by inner flex:1 div */
