@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&display=swap');

* { box-sizing: border-box; }

/* Suppress double-tap-to-zoom and the tap delay on every element. */
* { touch-action: manipulation; }

html, body {
  margin: 0;
  padding: 0;
  background: #212121;
  color: #fafafa;
  font-family: "JetBrains Mono", monospace;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------- header ---------- */
.topbar {
  padding-bottom: 1rem;
  border-bottom: 1px solid #2e2e2e;
}

.topbar h1 {
  font-size: 1.1rem;
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.05em;
  word-break: break-word;
}

.subtitle {
  margin: 0.3rem 0 0;
  font-size: 0.8rem;
  color: #888;
}

main {
  flex: 0 1 auto;
  padding: 1rem 0 0.25rem;
}

/* ---------- form fields ---------- */
.field { margin-bottom: 1.25rem; }

.field > label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #888;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

input[type="text"],
input[type="date"] {
  width: 100%;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  color: #fafafa;
  font-family: inherit;
  font-size: 1rem;               /* >=16px keeps iOS from zooming on focus */
  padding: 0.7rem 0.8rem;
  border-radius: 6px;
  min-width: 0;
}

input:focus { outline: none; border-color: #6aa84f; }

/* date input dark-mode tweaks */
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  color-scheme: dark;
}
input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.7);
  cursor: pointer;
}

.hint {
  margin: 0.5rem 0 0;
  font-size: 0.75rem;
  color: #777;
  line-height: 1.4;
}

.empty {
  font-size: 0.85rem;
  color: #888;
  margin: 0.5rem 0;
  line-height: 1.5;
}

.add-row {
  display: flex;
  gap: 0.5rem;
}
.add-row input { flex: 1; }

/* ---------- chosen-night chips ---------- */
.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  padding: 0.45rem 0.35rem 0.45rem 0.6rem;
}

.chip-dow { font-size: 0.7rem; color: #888; }
.chip-day { font-size: 0.95rem; font-weight: 700; }
.chip-mon { font-size: 0.7rem; color: #aaa; }

.chip-x {
  background: none;
  border: none;
  color: #888;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.2rem;
  min-width: 1.6rem;
  min-height: 1.6rem;
}
.chip-x:active { color: #e57373; }

/* ---------- calendar (create picker + results heat-map) ---------- */
.cal {
  background: #262626;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 0.6rem;
  user-select: none;
}

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.15rem 0.25rem 0.55rem;
}
.cal-head.static { justify-content: center; }

.cal-title {
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.cal-nav {
  background: #2f2f2f;
  border: 1px solid #3a3a3a;
  color: #fafafa;
  border-radius: 8px;
  width: 2.4rem;
  height: 2.4rem;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cal-nav:active { background: #383838; }

.cal-dow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.3rem;
  margin-bottom: 0.3rem;
}
.cal-dow span {
  text-align: center;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #777;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.3rem;
}

.cal-cell {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

/* create-picker day (interactive button) */
button.cal-cell {
  background: #2c2c2c;
  border-color: #383838;
  color: #ddd;
  font-family: inherit;
  cursor: pointer;
}
button.cal-cell:active { background: #343434; }
button.cal-cell.wknd { color: #fafafa; background: #313131; }
button.cal-cell.sel {
  background: #6aa84f;
  border-color: #6aa84f;
  color: #0c1a06;
  font-weight: 700;
}
.cal-cell.blank { border: none; background: none; }

.cal-summary { margin-top: 0.9rem; }
.cal-summary-count {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #888;
  margin-bottom: 0.5rem;
}

/* results heat-map calendar */
/* space out the stacked month calendars on the vote screen */
.votecal {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.rescal {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.cal-result .cal-cell {
  position: relative;
}
.cal-cell.off {
  color: #4a4a4a;
  background: #232323;
}
.cal-cell.cand {
  background: #2b2b2b;
  border-color: #3a3a3a;
  color: #fafafa;
}
.cal-cell.cand .cal-day { font-size: 0.9rem; font-weight: 700; }
.cal-cell.cand .cal-tag {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(50% + 0.65rem);
  text-align: center;
  font-size: 0.65rem;
  color: #cfe8c4;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.cal-cell.cand .cal-tag .t-yes { color: #cfe8c4; font-weight: 700; }
.cal-cell.cand .cal-tag .t-maybe { color: #e6c34e; font-size: 0.55rem; }
.cal-cell.cand.best {
  border-color: #8bcf6f;
  box-shadow: 0 0 0 1px #8bcf6f inset;
}

/* vote calendar: tappable candidate day that cycles yes/maybe/no */
button.cal-cell.vc {
  background: #2b2b2b;
  border-color: #3a3a3a;
  color: #fafafa;
  font-family: inherit;
  cursor: pointer;
  position: relative;
}
button.cal-cell.vc:active { transform: scale(0.96); }
button.cal-cell.vc .cal-day { font-size: 0.9rem; font-weight: 700; }
button.cal-cell.vc .vc-mark {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(50% + 0.65rem);
  text-align: center;
  font-size: 0.75rem;
  line-height: 1;
  font-weight: 700;
}
button.cal-cell.vc.v-no {
  background: #2a2a2a;
  border-color: #3a3a3a;
}
button.cal-cell.vc.v-no .vc-mark { color: #666; }
button.cal-cell.vc.v-yes {
  background: #6aa84f;
  border-color: #6aa84f;
  color: #0c1a06;
}
button.cal-cell.vc.v-yes .vc-mark { color: #0c1a06; }
button.cal-cell.vc.v-maybe {
  background: #d4af37;
  border-color: #d4af37;
  color: #201700;
}
button.cal-cell.vc.v-maybe .vc-mark { color: #201700; }

.vote-legend { flex-wrap: wrap; margin: 0.75rem 0 0; }
.vote-legend .dim { color: #666; }

/* "Select all / Clear all" quick-action — full width at the top of the vote screen */
.btn.bulk-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  width: 100%;
  margin: 0 0 1rem;
  padding: 0.7rem 0.95rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 8px;
  background: rgba(106, 168, 79, 0.14);
  border: 1px solid rgba(106, 168, 79, 0.55);
  color: #a6e08a;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn.bulk-btn::before {
  content: "✓";
  font-weight: 700;
  font-size: 0.9em;
  line-height: 1;
}
.btn.bulk-btn:active {
  background: rgba(106, 168, 79, 0.24);
}
/* When everything is already Yes, the button clears — show a neutral look. */
.btn.bulk-btn.is-clear {
  background: #2a2a2a;
  border-color: #3a3a3a;
  color: #aaa;
}
.btn.bulk-btn.is-clear::before {
  content: "×";
  font-size: 1.05em;
}

/* name field sits at the bottom of the vote screen, above the buttons */
.name-field { margin-top: 1.25rem; margin-bottom: 0; }

@media (max-width: 380px) {
  .cal-cell { font-size: 0.8rem; }
  .cal-cell.cand .cal-tag { font-size: 0.58rem; }
  .cal-cell.cand .cal-tag .t-maybe { font-size: 0.5rem; }
  .cal-grid, .cal-dow { gap: 0.2rem; }
}

/* ---------- vote rows ---------- */
.vote-rows {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.vote-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  text-align: left;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-left-width: 4px;
  border-radius: 8px;
  padding: 0.85rem 0.9rem;
  color: #fafafa;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  min-height: 3.25rem;           /* comfortable touch target */
}
.vote-row:active { background: #303030; }

.vote-label { font-size: 0.95rem; }

.vote-badge {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
  min-width: 4.2rem;
  text-align: center;
}

.vote-row.v-no    { border-left-color: #3a3a3a; }
.vote-row.v-no    .vote-badge { background: #333; color: #888; }
.vote-row.v-yes   { border-left-color: #6aa84f; background: #263123; }
.vote-row.v-yes   .vote-badge { background: #6aa84f; color: #0c1a06; }
.vote-row.v-maybe { border-left-color: #d4af37; background: #302c1e; }
.vote-row.v-maybe .vote-badge { background: #d4af37; color: #201700; }

/* ---------- winner banner ---------- */
.winner {
  background: #263123;
  border: 1px solid #385234;
  border-radius: 10px;
  padding: 0.9rem 1rem;
  margin-bottom: 1.25rem;
  text-align: center;
}
.winner-tag {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #8bcf6f;
  margin-bottom: 0.3rem;
}
.winner-date {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fafafa;
  word-break: break-word;
}

/* "Saved — now share" reminder on the results screen */
.save-notice {
  background: #2a2620;
  border: 1px solid #4a3f22;
  border-radius: 10px;
  padding: 0.9rem 1rem;
  margin-bottom: 1.25rem;
  text-align: center;
}
.save-notice-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #f0d98a;
  margin-bottom: 0.25rem;
}
.save-notice-sub {
  font-size: 0.78rem;
  color: #b9b096;
  line-height: 1.4;
  margin-bottom: 0.75rem;
}
.save-notice .btn { width: 100%; }

/* "Continue your last poll?" banner on the create screen */
.restore {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #26302b;
  border: 1px solid #37503f;
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 1.25rem;
}
.restore-info { flex: 1; min-width: 0; }
.restore-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: #fafafa;
  word-break: break-word;
}
.restore-sub {
  font-size: 0.74rem;
  color: #9bbfa3;
  margin-top: 0.15rem;
}
.restore .btn { flex: 0 0 auto; }

/* "Combine links from others" box on the results screen */
.merge {
  margin: 0.5rem 0 0;
  border: 1px solid #333;
  border-radius: 10px;
  overflow: hidden;
}
.merge-toggle {
  width: 100%;
  background: #262626;
  border: none;
  color: #cfcfcf;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: left;
  padding: 0.8rem 0.9rem;
  cursor: pointer;
}
.merge-toggle:active { background: #2c2c2c; }
.merge-toggle.open { color: #fafafa; border-bottom: 1px solid #333; }
.merge-body {
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
/* the [hidden] attribute must win over display:flex above */
.merge-body[hidden] { display: none; }
.merge-hint {
  margin: 0;
  font-size: 0.76rem;
  color: #999;
  line-height: 1.45;
}
.merge-input {
  width: 100%;
  background: #1c1c1c;
  border: 1px solid #3a3a3a;
  color: #fafafa;
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.6rem 0.7rem;
  border-radius: 6px;
  resize: vertical;
  min-height: 3rem;
}
.merge-input:focus { outline: none; border-color: #6aa84f; }
.merge-body .btn.small { align-self: flex-start; }
.merge-status {
  font-size: 0.78rem;
  line-height: 1.4;
}
.merge-status:empty { display: none; }
.merge-status.ok { color: #8bcf6f; }
.merge-status.warn { color: #e0b64a; }

/* ---------- results grid ---------- */
.grid-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
}

.grid {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-variant-numeric: tabular-nums;
}

.grid th, .grid td {
  padding: 0.55rem 0.4rem;
  text-align: center;
  border-bottom: 1px solid #3a3a3a;
  border-right: 1px solid #3a3a3a;
  white-space: nowrap;
}
.grid tr:last-child th,
.grid tr:last-child td { border-bottom: none; }

/* Two sticky left columns — the date and the count — stay visible while the
   voter columns scroll. The date is pinned to the edge; the count sits right
   after it at a fixed offset (so we give the date a fixed width to match). */
.grid th.corner,
.grid th.date {
  position: sticky;
  left: 0;
  z-index: 2;
  width: 4.5rem;
  min-width: 4.5rem;
  background: #242424;
  text-align: left;
  border-right: 1px solid #454545;
}
.grid th.sum-h,
.grid td.sum {
  position: sticky;
  left: 4.5rem;
  z-index: 2;
  background: #242424;
  border-right: 1px solid #454545;
}
.grid thead th.corner,
.grid thead th.sum-h { z-index: 3; }

.grid thead th {
  position: sticky;
  top: 0;
  background: #242424;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #aaa;
  font-weight: 600;
  /* Sticky + border-collapse:separate drops the inherited bottom border, so
     draw the header's bottom separator as an inset shadow (always paints). */
  box-shadow: inset 0 -1px 0 #3a3a3a;
}

.grid th.name {
  max-width: 5.5rem;
}
.grid th.name span {
  display: inline-block;
  max-width: 5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}
/* the ✓ column header: match the brighter, bolder ✓ used in the cells/legend
   (the generic header style makes it small, dim and thin, which looks off) */
.grid th.sum-h {
  color: #8bcf6f;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
}

.grid th.corner {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #aaa;
  text-align: center;
}

.grid th.date {
  padding: 0.5rem 0.6rem;
  font-weight: 400;
}
.grid .d-dow { display: block; font-size: 0.68rem; color: #888; }
.grid .d-day { display: block; font-size: 0.9rem; font-weight: 700; }

.grid td.cell {
  font-size: 1rem;
  font-weight: 700;
  min-width: 2.4rem;
}
.grid td.c-yes   { color: #8bcf6f; background: rgba(106,168,79,0.10); }
.grid td.c-maybe { color: #e6c34e; background: rgba(212,175,55,0.10); }
.grid td.c-no    { color: #555; }

.grid tr.best th.date { background: #26311f; }
.grid tr.best td.sum { background: #26311f; }
.grid tr.best td { background: rgba(106,168,79,0.07); }
.grid tr.best td.c-yes { background: rgba(106,168,79,0.16); }

/* count cell: yes total with a maybe "(~n)" beside it, laid out inline so the
   "(~n)" can never get pushed out of (or clipped by) the cell.
   Bottom-aligned so the number lines up with the bold date beside it
   (same 0.5rem bottom padding as .grid th.date), centered in the column. */
.grid td.sum {
  font-size: 0.85rem;
  width: 2.4rem;
  min-width: 2.4rem;
  text-align: center;
  vertical-align: bottom;
  padding: 0.5rem 0.3rem;
}
.grid td.sum .s-yes,
.grid td.sum .s-maybe {
  display: inline;
}
.grid .s-yes   { color: #8bcf6f; font-weight: 700; font-size: 0.9rem; }
.grid .s-maybe {
  color: #e6c34e;
  font-size: 0.68rem;
}

/* legend under the grid */
.legend {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 0.9rem;
  font-size: 0.75rem;
  color: #888;
}
.legend .lg { display: inline-flex; align-items: center; gap: 0.3rem; }
.legend b { font-style: normal; }
.legend .c-yes { color: #8bcf6f; }
.legend .c-maybe { color: #e6c34e; }
.legend .c-no { color: #666; }

/* ---------- buttons ---------- */
.actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.5rem;
}

/* subtle "start a new poll" text link at the very bottom of results */
.new-poll-link {
  background: none;
  border: none;
  color: #666;
  font-family: inherit;
  font-size: 0.78rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0.75rem 0.5rem 0.25rem;
  align-self: center;
}
.new-poll-link:active { color: #999; }

.btn {
  width: 100%;
  background: #2a2a2a;
  color: #fafafa;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  padding: 0.9rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
}
.btn:active { background: #333; }

.btn.primary {
  background: #6aa84f;
  color: #0c1a06;
  border: none;
  font-weight: 700;
}
.btn.primary:active { background: #5c9744; }

.btn.ghost {
  background: none;
  border: 1px solid #333;
  color: #999;
}

.btn.small {
  width: auto;
  padding: 0.7rem 1rem;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.7; cursor: default; }

/* little shake to flag a required field */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.shake { animation: shake 0.35s; }

/* ---------- narrow phones ---------- */
@media (max-width: 380px) {
  .vote-badge { min-width: 3.6rem; font-size: 0.68rem; }
  .vote-label { font-size: 0.88rem; }
  .btn { font-size: 0.9rem; }
}
