:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-alt: #fafbfc;
  --border: #e3e6ea;
  --border-strong: #cfd4dc;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-dark: #4338ca;
  --accent-soft: #eef2ff;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --radius: 14px;
  --radius-sm: 10px;
  --control-h: 42px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 8px 24px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.container { max-width: 920px; margin: 0 auto; padding: 0 20px; }
.container.narrow { max-width: 460px; }

/* ------------------------------------------------------------------ header */
header.site {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
header.site .container {
  display: flex; align-items: center; gap: 16px;
  min-height: 60px; padding-top: 10px; padding-bottom: 10px;
  flex-wrap: wrap;
}
.brand {
  display: inline-flex; align-items: center; gap: 9px;
  font-weight: 700; font-size: 18px; line-height: 1;
  text-decoration: none; color: var(--text);
}
.brand .dot {
  width: 24px; height: 24px; border-radius: 7px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px;
}
.brand small { color: var(--muted); font-weight: 500; font-size: 13px; }

.nav { margin-left: auto; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.navlink {
  display: inline-flex; align-items: center;
  min-height: 34px; padding: 0 2px;
  font-size: 14px; font-weight: 600; color: var(--text); text-decoration: none;
}
.navlink:hover { color: var(--accent); }
.navcta {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff;
  min-height: 34px; padding: 0 14px; border-radius: 9px;
}
.navcta:hover { background: var(--accent-dark); color: #fff; }
.navuser {
  display: inline-flex; align-items: center; min-height: 34px;
  font-size: 14px; color: var(--muted);
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.navbtn {
  min-height: 34px; padding: 0 13px;
  font-size: 13.5px; font-weight: 600; border-radius: 9px;
}

/* ------------------------------------------------------------------- basic */
main { padding: 36px 0 64px; }

h1 { font-size: 28px; line-height: 1.25; margin: 0 0 8px; letter-spacing: -0.02em; }
h2 { font-size: 20px; line-height: 1.3; margin: 0 0 8px; letter-spacing: -0.01em; }
h1 .badge { margin-left: 8px; }
.subtitle { color: var(--muted); margin: 0 0 26px; font-size: 16px; }

p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.hidden { display: none !important; }
.text-center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mt { margin-top: 24px; }
.mb { margin-bottom: 16px; }

/* ------------------------------------------------------------------ forms */
.field { margin-bottom: 20px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 7px; }
.field .hint { color: var(--muted); font-size: 13px; margin-top: 6px; }

input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="time"], textarea, select {
  font: inherit;
  font-size: 15px;
  line-height: 20px;
  min-height: var(--control-h);
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  width: 100%;
}
textarea { resize: vertical; min-height: 78px; line-height: 1.5; padding: 9px 12px; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row .grow { flex: 1 1 200px; min-width: 0; }

.fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
  margin: 0 0 20px;
}
.fieldset legend {
  padding: 0 6px; margin-left: -2px;
  font-weight: 700; font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
}

/* ---------------------------------------------------------------- buttons */
button,
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 7px;
  font: inherit; font-weight: 600; font-size: 15px; line-height: 1.2;
  min-height: var(--control-h);
  padding: 0 16px;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s, transform .05s;
}
button:hover, .btn:hover { border-color: var(--border-strong); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: not-allowed; transform: none; }

button.primary, .btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
button.primary:hover, .btn.primary:hover {
  background: var(--accent-dark); border-color: var(--accent-dark); color: #fff;
}
button.ghost, .btn.ghost { background: transparent; }
button.danger, .btn.danger { color: var(--red); border-color: #fecaca; background: var(--red-soft); }
button.danger:hover, .btn.danger:hover { border-color: #fca5a5; }

button.sm, .btn.sm { min-height: 34px; padding: 0 13px; font-size: 13.5px; border-radius: 9px; }
button.xs, .btn.xs { min-height: 28px; padding: 0 10px; font-size: 12px; border-radius: 7px; }
button.block, .btn.block { width: 100%; }

/* ------------------------------------------------------------------ chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); padding: 5px 8px 5px 12px;
  font-size: 14px; line-height: 1.4;
}
.chip .x {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; padding: 0;
  min-height: 0; border: none; border-radius: 50%;
  background: transparent; color: var(--muted);
  font-size: 16px; font-weight: 700; line-height: 1;
  cursor: pointer;
}
.chip .x:hover { background: var(--red-soft); color: var(--red); }

.preset {
  min-height: 34px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); font-size: 13.5px;
}
.preset.active {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent-dark);
}

/* ------------------------------------------------------- link / copy boxes */
.links { display: grid; gap: 14px; margin: 18px 0; }
.linkbox {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; background: var(--surface-alt);
}
.linkbox .lbl { flex: 1 1 auto; min-width: 0; }
.linkbox .lbl .k {
  font-size: 11px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 2px;
}
.linkbox .lbl .v { font-size: 14px; overflow-wrap: anywhere; }
.linkbox.sensitive { border-color: #fde68a; background: #fffbeb; }
.copybtn { flex-shrink: 0; }

/* ------------------------------------------------------------------- vote */
.tzbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 16px;
}
.tzbar select { width: auto; flex: 1 1 240px; min-width: 180px; }
.tzbar .tzlabel { font-size: 14px; color: var(--muted); flex-shrink: 0; }

.legend { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.legend b { color: var(--text); }

.table-scroll {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  -webkit-overflow-scrolling: touch;
}

table.matrix { border-collapse: collapse; width: 100%; min-width: 520px; }
table.matrix th, table.matrix td { padding: 0; }
table.matrix thead th {
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  text-align: center; vertical-align: middle;
  font-size: 13px; font-weight: 700; color: var(--muted);
  white-space: nowrap;
}
table.matrix thead th.corner {
  text-align: left; color: var(--text); font-size: 13px;
}
table.matrix thead th .dow {
  display: block; font-size: 12px; font-weight: 500; color: var(--muted);
}
table.matrix .timecell {
  text-align: right; vertical-align: middle;
  padding: 10px 14px 10px 12px;
  border-right: 1px solid var(--border);
  background: var(--surface-alt);
  font-weight: 700; font-size: 14px; white-space: nowrap;
}
td.cell {
  padding: 0;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
table.matrix td.cell:last-child { border-right: none; }
table.matrix tbody tr:last-child td.cell { border-bottom: none; }
td.cell.selected { background: var(--green-soft); }
td.cell:hover { background: var(--accent-soft); }
td.cell.selected:hover { background: #c9f0d5; }

.slot {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; width: 100%; min-height: 62px; padding: 8px 10px;
  border: none; border-radius: 0; background: transparent;
  font-weight: 400; text-align: center; white-space: normal;
}
.slot:hover, .slot:active { transform: none; }
.slot .origin-time { font-weight: 600; font-size: 14px; color: var(--text); }
.slot .local-time { font-size: 12px; color: var(--muted); }
td.cell.selected .slot .origin-time,
td.cell.selected .slot .local-time { color: var(--green); }

.namebar {
  display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-top: 18px;
}
.namebar .field { margin: 0; flex: 1 1 240px; min-width: 0; }
.namebar button, .namebar .btn { flex: 0 0 auto; }

/* ------------------------------------------------------------------ alerts */
.alert { border-radius: var(--radius-sm); padding: 12px 16px; font-size: 14px; margin: 16px 0; }
.alert.success { background: var(--green-soft); color: #14532d; }
.alert.error { background: var(--red-soft); color: #7f1d1d; }
.alert.info { background: var(--accent-soft); color: var(--accent-dark); }

.closed-banner {
  background: #fef3c7; color: #78350f; border: 1px solid #fde68a;
  border-radius: var(--radius-sm); padding: 16px 18px; margin-bottom: 18px; font-size: 15px;
}

.badge {
  display: inline-block; vertical-align: middle;
  font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 6px; white-space: nowrap;
}
.badge.open { background: var(--green-soft); color: #14532d; }
.badge.closed { background: #f1f5f9; color: #475569; }

/* ----------------------------------------------------------------- results */
.bestlist { display: grid; gap: 10px; margin: 16px 0 28px; }
.bestitem {
  display: flex; align-items: center; gap: 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 13px 16px; background: var(--surface);
}
.bestitem .medal {
  flex-shrink: 0; width: 28px; text-align: center;
  font-size: 17px; line-height: 1.2;
}
.bestitem .when { flex: 1 1 auto; min-width: 0; }
.bestitem .when .dt { font-weight: 700; }
.bestitem .when .sub { color: var(--muted); font-size: 13px; }
.bestitem .count {
  flex-shrink: 0;
  background: var(--accent-soft); color: var(--accent-dark);
  font-weight: 700; font-size: 14px; white-space: nowrap;
  border-radius: 999px; padding: 4px 12px;
}
.bestitem.top { border-color: var(--accent); background: linear-gradient(180deg, #f5f6ff, #fff); }

table.results { width: 100%; min-width: 460px; border-collapse: collapse; font-size: 14px; }
table.results th, table.results td {
  padding: 12px 16px; text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--border);
}
table.results th {
  color: var(--muted); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
  background: var(--surface-alt);
}
table.results tbody tr:last-child td { border-bottom: none; }
table.results .num { text-align: center; font-weight: 700; width: 110px; }
table.results .yes { color: var(--green); }
table.results .none { color: var(--muted); }
table.results .who { color: var(--muted); }

.inline-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ------------------------------------------------------------------- hero */
.hero { padding: 24px 0 0; max-width: 680px; }
.hero h1 { font-size: 34px; line-height: 1.15; margin-bottom: 12px; }
.hero .subtitle { font-size: 17px; margin-bottom: 24px; }
.hero-points { display: grid; gap: 12px; margin-top: 36px; }
.hero-point {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px;
}
.hero-point strong { font-size: 15px; }
.hero-point span { color: var(--muted); font-size: 14px; }

/* -------------------------------------------------------------- dashboard */
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 24px;
}
.page-head h1 { margin-bottom: 0; }
.page-head .subtitle { margin: 4px 0 0; font-size: 14px; }
.page-head .btn { flex-shrink: 0; }

.empty-state { text-align: center; padding: 40px 28px; }
.empty-state h2 { margin-bottom: 6px; }
.empty-state .muted { max-width: 420px; margin: 0 auto; }
.empty-mark { font-size: 26px; line-height: 1; margin-bottom: 10px; }

.poll-list { display: grid; gap: 14px; }
.poll-card {
  display: flex; gap: 20px; justify-content: space-between; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px;
}
.poll-card-main { flex: 1 1 360px; min-width: 0; }
.poll-card-title {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 4px;
}
.poll-card-title a {
  font-size: 17px; font-weight: 700; color: var(--text); text-decoration: none;
  overflow-wrap: anywhere;
}
.poll-card-title a:hover { color: var(--accent); }
.poll-card-meta { color: var(--muted); font-size: 13px; }

.poll-links { display: grid; gap: 8px; margin-top: 14px; }
.poll-link {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 8px 6px 12px;
  font-size: 12.5px;
}
.poll-link .k {
  flex-shrink: 0; font-size: 10px; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase; color: var(--muted);
}
.poll-link .v { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; color: var(--text); }

.poll-card-actions {
  display: flex; gap: 8px; align-items: flex-start;
  flex-wrap: wrap; align-content: flex-start;
}

/* ----------------------------------------------------------------- footer */
footer.site { color: var(--muted); font-size: 13px; text-align: center; padding: 8px 0 40px; }

/* --------------------------------------------------------------- responsive */
@media (max-width: 640px) {
  main { padding: 24px 0 48px; }
  .card { padding: 20px; }
  .fieldset { padding: 14px 14px 16px; }

  /* entry rows: the picker goes full width, action buttons share a row */
  .fieldset .row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .fieldset .row .grow { grid-column: 1 / -1; }
  .fieldset .row > button { width: 100%; }
  #add-time { grid-column: 1 / -1; }

  /* chips + presets sit on an even grid instead of ragged flex widths */
  #date-chips,
  #time-chips {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: stretch;
  }
  #time-presets {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  #date-chips .chip,
  #time-chips .chip {
    width: 100%;
    min-width: 0;
    justify-content: space-between;
    font-size: 13px;
  }
  #date-chips .chip > span:first-child { min-width: 0; text-align: left; }
  #time-presets .preset { width: 100%; font-size: 13px; }
  .chips > .muted { grid-column: 1 / -1; }

  .brand small { display: none; }
  header.site .container { gap: 10px; }
  .nav { gap: 12px; }
  .hero h1 { font-size: 27px; }
  .hero { padding-top: 8px; }
  .namebar { padding: 16px; }
  .namebar button, .namebar .btn { width: 100%; }
  .poll-card { padding: 16px; gap: 14px; }
  .poll-card-actions { width: 100%; }
  .poll-card-actions > * { flex: 1 1 auto; }
  .bestitem { flex-wrap: wrap; gap: 10px; }
  .tzbar { padding: 12px; }
  .tzbar select { flex: 1 1 100%; }
}
