/* Mahjong Monthly: calm, high-contrast, mobile-first. */

:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --ink: #17201c;
  --ink-2: #4a5550;
  --ink-3: #6b746f;
  --line: #e3ddd0;
  --line-strong: #cfc7b7;

  --jade: #0e5a47;
  --jade-hover: #0b4a3a;
  --on-jade: #ffffff;
  --jade-soft: #e1eee7;
  --jade-ink: #0b4a3a;

  --amber: #855600;
  --amber-soft: #f6ead2;
  --red: #9b372b;
  --red-soft: #f5e2de;
  --gold: #7a5b0c;
  --gold-soft: #f3e6bf;
  --wa: #137a43;

  --shadow: 0 1px 2px rgba(23, 32, 28, 0.04), 0 6px 24px rgba(23, 32, 28, 0.06);
  --radius: 16px;
  --radius-sm: 12px;
  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513;
    --surface: #1a1f1c;
    --surface-2: #202622;
    --ink: #eef2ef;
    --ink-2: #b4bdb8;
    --ink-3: #8f9993;
    --line: #2d3531;
    --line-strong: #3d4742;

    --jade: #57c29d;
    --jade-hover: #6dd0ad;
    --on-jade: #08140f;
    --jade-soft: #193229;
    --jade-ink: #8fdcc0;

    --amber: #e3b25a;
    --amber-soft: #33291a;
    --red: #ec8f82;
    --red-soft: #3a2421;
    --gold: #e8c766;
    --gold-soft: #352d16;
    --wa: #3fbf78;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 600; }
h1 { font-family: var(--serif); font-size: 1.625rem; letter-spacing: -0.01em; }
h2 { font-family: var(--serif); font-size: 1.25rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--jade); }
button, input, select, textarea { font: inherit; color: inherit; }
svg { flex: none; }

:focus-visible { outline: 3px solid var(--jade); outline-offset: 2px; }

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) calc(72px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.wrap.wide { max-width: 1120px; }

.stack > * + * { margin-top: 16px; }
.stack-lg > * + * { margin-top: 28px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.wrap-row { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--ink-2); }
.small { font-size: 0.875rem; }
.mt-12 { margin-top: 12px; }
.mt-14 { margin-top: 14px; }
.mt-16 { margin-top: 16px; }
.mb-12 { margin-bottom: 12px; }
.hint-tight { margin: -4px 0 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- header ---------- */

.brand {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 0.875rem; font-weight: 600; letter-spacing: 0.02em;
  color: var(--ink-2); text-decoration: none;
}
.brand img { display: block; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }

.page-head { margin: 16px 0 20px; }
.page-head h1 { overflow-wrap: anywhere; }
.page-head .lead { margin-top: 6px; }
.lead { font-size: 1rem; color: var(--ink-2); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 0.8125rem; font-weight: 600;
  background: var(--jade-soft); color: var(--jade-ink);
}

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card-quiet { background: var(--surface-2); box-shadow: none; }
.card h2 + p, .card h3 + p { margin-top: 6px; }

.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 28px 0 12px; }
.section-head h2 { font-size: 1.1875rem; }
.section-head .count { color: var(--ink-3); font-size: 0.875rem; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  font-size: 1rem; font-weight: 600; line-height: 1.2;
  text-decoration: none; cursor: pointer;
  transition: background-color .15s, border-color .15s, transform .08s;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: .55; cursor: default; transform: none; }
.btn-block { display: flex; width: 100%; }
.btn-primary { background: var(--jade); color: var(--on-jade); }
.btn-primary:hover { background: var(--jade-hover); }
.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn-secondary:hover { border-color: var(--ink-3); }
.btn-wa { background: var(--wa); color: #fff; }
.btn-ghost { background: transparent; color: var(--jade); padding: 0 12px; }
.btn-ghost:hover { background: var(--jade-soft); }
.btn-danger { background: transparent; color: var(--red); border-color: transparent; }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { min-height: 40px; padding: 0 12px; font-size: 0.9375rem; border-radius: 10px; }

.link-btn {
  background: none; border: 0; padding: 10px 4px; margin: -10px -4px;
  color: var(--jade); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}

.btn-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- forms ---------- */

.field { display: block; }
.field + .field { margin-top: 14px; }
.label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.9375rem; }
.hint { color: var(--ink-3); font-size: 0.875rem; margin-top: 6px; }

.input, .select, .textarea {
  display: block; width: 100%;
  min-height: 48px; padding: 11px 14px;
  background: var(--surface); color: var(--ink);
  border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm);
  font-size: 1rem; /* 16px: keeps iOS Safari from zooming in */
  -webkit-appearance: none; appearance: none;
}
.textarea { min-height: 84px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--jade); box-shadow: 0 0 0 3px var(--jade-soft); }
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236b746f' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 16px center; padding-right: 48px;
}
input[type="date"].input, input[type="time"].input { min-width: 0; text-align: left; }
input[type="date"]::-webkit-date-and-time-value, input[type="time"]::-webkit-date-and-time-value { text-align: left; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-grid .field + .field { margin-top: 0; }
.field-grid + .field { margin-top: 14px; }
.inline-add { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.form-actions .btn { flex: 1; }
.error-text { color: var(--red); font-weight: 600; font-size: 0.875rem; margin-top: 10px; }

/* ---------- chips (player list) ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 40px; padding: 0 0 0 14px;
  background: var(--surface-2); border: 1.5px solid var(--line); border-radius: 999px;
  font-weight: 600; font-size: 0.9375rem; max-width: 100%;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button {
  display: inline-grid; place-items: center; width: 44px; height: 44px; margin: -2px 0;
  border: 0; border-radius: 999px; background: transparent; color: var(--ink-3); cursor: pointer;
}
.chip button:hover { background: var(--red-soft); color: var(--red); }
.chip-static { padding: 0 16px; }

.names { display: flex; flex-wrap: wrap; gap: 6px; }
.name {
  padding: 2px 10px; border-radius: 999px; font-size: 0.875rem; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink);
}
.name.yes { background: var(--jade-soft); border-color: transparent; color: var(--jade-ink); }
.name.maybe { background: var(--amber-soft); border-color: transparent; color: var(--amber); }
.name.no { color: var(--ink-3); }

/* ---------- segmented tabs ---------- */

.callout + .tabs { margin-top: 20px; }
.tabs + .section-head { margin-top: 4px; }
.tabs {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  padding: 4px; margin: 0 0 20px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px;
}
.tab {
  min-height: 40px; border: 0; border-radius: 10px; background: transparent;
  font-weight: 600; font-size: 0.9375rem; color: var(--ink-2); cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 0 0 1px var(--line); }

/* ---------- session cards ---------- */

.sessions { display: grid; gap: 12px; }

.session { padding: 16px; scroll-margin-top: 16px; }
.session.flash { animation: flash 1.4s ease-out; }
@keyframes flash { 0%, 30% { box-shadow: 0 0 0 4px var(--jade); } 100% { box-shadow: var(--shadow); } }
.session-top { display: flex; gap: 14px; align-items: flex-start; }

.datebox {
  flex: none; width: 54px; padding: 6px 0 7px; text-align: center;
  border-radius: 12px; background: var(--jade-soft); color: var(--jade-ink);
}
.datebox .dow { display: block; font-size: 0.6875rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.datebox .day { display: block; font-family: var(--serif); font-size: 1.5rem; line-height: 1.05; font-weight: 600; }
.datebox .mon { display: block; font-size: 0.6875rem; font-weight: 600; }
.datebox.proposed { background: transparent; border: 2px dashed var(--line-strong); color: var(--ink-2); }

.session-info { flex: 1; min-width: 0; }
.session-title { font-weight: 700; font-size: 1rem; }
.meta { display: flex; align-items: flex-start; gap: 6px; color: var(--ink-2); margin-top: 2px; font-size: 0.9375rem; overflow-wrap: anywhere; }
.meta svg { margin-top: 3px; color: var(--ink-3); }
.session-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 0.8125rem; font-weight: 700; white-space: nowrap;
}
.badge-ready { background: var(--jade); color: var(--on-jade); }
.badge-two { background: var(--gold-soft); color: var(--gold); box-shadow: inset 0 0 0 1.5px currentColor; }
.badge-proposed { background: var(--surface-2); color: var(--ink-2); border: 1.5px dashed var(--line-strong); }
.badge-count { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }

/* Yes / Maybe / No */
.answers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.answer {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 52px; padding: 4px;
  border-radius: 12px; border: 1.5px solid var(--line-strong);
  background: var(--surface); color: var(--ink);
  font-weight: 700; font-size: 0.9375rem; cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s, transform .08s;
  touch-action: manipulation;
}
.answer:active { transform: scale(0.97); }
.answer svg { color: var(--ink-3); }
.answer[aria-pressed="true"] svg { color: currentColor; }
.answer.yes[aria-pressed="true"] { background: var(--jade); border-color: var(--jade); color: var(--on-jade); }
.answer.maybe[aria-pressed="true"] { background: var(--amber); border-color: var(--amber); color: var(--surface); }
.answer.no[aria-pressed="true"] { background: var(--red); border-color: var(--red); color: var(--surface); }

.session-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.details { margin-top: 12px; padding-top: 14px; border-top: 1px solid var(--line); }

.session-actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.cal-links { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.cal-links.single { grid-template-columns: 1fr; }
.cal-links .btn { padding: 0 6px; gap: 6px; background: var(--jade-soft); }
.cal-links .btn:hover { background: var(--line); }

/* Overview groups */
.who { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); display: grid; gap: 10px; }
.who-row { display: grid; gap: 5px; }
.waiting { font-size: 0.875rem; color: var(--ink-3); overflow-wrap: anywhere; }
.waiting strong { color: var(--ink-2); font-weight: 700; }
.who-label { font-size: 0.8125rem; font-weight: 700; color: var(--ink-2); }
.notes { margin-top: 12px; display: grid; gap: 6px; }
.note-line {
  padding: 8px 12px; border-radius: 10px; background: var(--surface-2);
  font-size: 0.9375rem; overflow-wrap: anywhere;
}
.note-line strong { font-weight: 700; }

/* ---------- calendar ---------- */

.calendar { padding: 14px 12px 12px; }
.calendars { display: grid; gap: 12px; align-content: start; }
.cal-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 6px 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.cal-dow { text-align: center; font-size: 0.75rem; font-weight: 700; color: var(--ink-3); padding-bottom: 6px; letter-spacing: .04em; }
.cal-day {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  aspect-ratio: 1 / 1; min-height: 38px; max-height: 48px;
  border-radius: 10px; border: 0; background: transparent;
  font-size: 0.9375rem; font-weight: 500; color: var(--ink); padding: 0;
}
.cal-day.blank { visibility: hidden; }
.cal-day.today { box-shadow: inset 0 0 0 1.5px var(--line-strong); }
button.cal-day { cursor: pointer; font-weight: 700; }
.cal-day.has { background: var(--jade-soft); color: var(--jade-ink); }
.cal-day.ready { background: var(--jade); color: var(--on-jade); }
.cal-day.proposed { background: transparent; box-shadow: inset 0 0 0 2px var(--line-strong); border-radius: 12px; }
.cal-day .dots { position: absolute; bottom: 5px; display: flex; gap: 3px; }
.cal-day .dots i { width: 5px; height: 5px; border-radius: 99px; background: currentColor; opacity: .8; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; padding: 0 6px; font-size: 0.8125rem; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }
.legend .l-ready { background: var(--jade); }
.legend .l-has { background: var(--jade-soft); box-shadow: inset 0 0 0 1px var(--line); }
.legend .l-prop { box-shadow: inset 0 0 0 2px var(--line-strong); }

.overview-grid { display: grid; gap: 20px; }

/* ---------- share ---------- */

.share-url {
  display: block; padding: 10px 12px; margin: 10px 0 12px;
  border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line);
  font-size: 0.8125rem; color: var(--ink-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.share-actions { display: grid; grid-template-columns: 1fr; gap: 10px; }
.callout { border-color: transparent; background: var(--jade-soft); box-shadow: none; }
.callout h2 { color: var(--jade-ink); }
.callout .steps { margin: 12px 0 0; padding: 0; list-style: none; display: grid; gap: 8px; font-size: 0.9375rem; }
.callout .steps li { display: flex; gap: 12px; align-items: flex-start; }
.callout .steps b {
  flex: none; display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 99px;
  background: var(--jade); color: var(--on-jade); font-size: 0.8125rem;
}

/* ---------- player picker ---------- */

.name-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.name-btn {
  min-height: 52px; padding: 8px 12px;
  border-radius: 12px; border: 1.5px solid var(--line-strong);
  background: var(--surface); color: var(--ink);
  font-size: 1rem; font-weight: 700; cursor: pointer;
  overflow-wrap: anywhere; line-height: 1.25;
  box-shadow: var(--shadow);
}
.name-btn:hover { border-color: var(--jade); }
.name-btn:active { transform: scale(0.98); }

.me-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: -6px 0 16px; color: var(--ink-2); font-size: 0.9375rem;
}
.me-bar strong { color: var(--ink); }

.progress { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; color: var(--ink-2); font-size: 0.875rem; }
.progress-bar {
  flex: 1; height: 6px; border: 0; border-radius: 99px; overflow: hidden;
  background: var(--line); color: var(--jade);
  -webkit-appearance: none; appearance: none;
}
.progress-bar::-webkit-progress-bar { background: var(--line); border-radius: 99px; }
.progress-bar::-webkit-progress-value { background: var(--jade); border-radius: 99px; transition: width .3s; }
.progress-bar::-moz-progress-bar { background: var(--jade); border-radius: 99px; }

/* ---------- empty / loading ---------- */

.empty {
  text-align: center; padding: 28px 18px;
  border: 2px dashed var(--line-strong); border-radius: var(--radius);
  color: var(--ink-2);
}
.empty .empty-icon {
  display: inline-grid; place-items: center; width: 48px; height: 48px; margin-bottom: 10px;
  border-radius: 99px; background: var(--jade-soft); color: var(--jade-ink);
}
.empty h3 { color: var(--ink); font-size: 1.0625rem; margin-bottom: 4px; }
.empty p { font-size: 0.9375rem; }
.empty .btn { margin-top: 16px; }

.empty-page { padding-top: 12vh; }
.empty-page h1 { margin: 24px 0 12px; }
.empty-page .btn { margin-top: 28px; }

.loading { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 50vh; color: var(--ink-2); }
.spinner { width: 22px; height: 22px; border-radius: 99px; border: 3px solid var(--line); border-top-color: var(--jade); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 50;
  display: flex; align-items: center; gap: 10px;
  max-width: calc(100vw - 32px); padding: 12px 18px;
  border-radius: 12px; background: var(--ink); color: var(--bg);
  font-weight: 600; font-size: 0.9375rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
  opacity: 0; pointer-events: none; transform: translate(-50%, 16px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red); color: #fff; }
.toast svg { color: var(--jade-soft); }

.recent-list { display: grid; gap: 10px; }
.recent {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px; padding: 10px 14px;
  border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--line);
  text-decoration: none; color: var(--ink); font-weight: 600;
}
.recent span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent small { color: var(--ink-3); font-weight: 500; white-space: nowrap; }

.footer-note { margin-top: 32px; text-align: center; color: var(--ink-3); font-size: 0.875rem; }
.footer-note a { display: inline-block; padding: 12px 8px; }
.danger-zone { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); display: flex; justify-content: center; }

/* ---------- larger screens ---------- */

@media (min-width: 560px) {
  .share-actions { grid-template-columns: 1fr 1fr; }
  .name-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 900px) {
  .wrap { padding-top: 32px; }
  h1 { font-size: 2rem; }
  .card { padding: 20px; }
  .session { padding: 20px; }
  .overview-grid { grid-template-columns: 360px 1fr; align-items: start; gap: 24px; }
  .overview-grid > .calendars { position: sticky; top: 24px; }
  .who-row { grid-template-columns: 96px 1fr; align-items: baseline; gap: 10px; }
}

@media (max-width: 360px) {
  h1 { font-size: 1.5rem; }
  .datebox { width: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
