:root {
  --md-primary: #1a237e;
  --md-primary-container: #c5cae9;
  --md-on-primary: #ffffff;
  --md-secondary: #3949ab;
  --md-surface: #f7f8fc;
  --md-surface-card: #ffffff;
  --md-on-surface: #1c1b1f;
  --md-on-surface-variant: #49454f;
  --md-outline: #cac4d0;
  --md-outline-variant: #e7e0ec;
  --md-error: #b3261e;
  --md-success: #1b5e20;
  --md-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(26, 35, 126, 0.08);
  --md-shadow-lg: 0 4px 8px rgba(0, 0, 0, 0.06), 0 12px 32px rgba(26, 35, 126, 0.12);
  --radius: 16px;
  --radius-sm: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Noto Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --spring: cubic-bezier(0.34, 1.2, 0.64, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--md-surface);
  color: var(--md-on-surface);
  min-height: 100%;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(ellipse 120% 80% at 0% -20%, rgba(57, 73, 171, 0.12), transparent 55%),
    radial-gradient(ellipse 90% 60% at 100% 0%, rgba(26, 35, 126, 0.08), transparent 50%);
  background-attachment: fixed;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 520px;
  margin: 0 auto;
  padding-bottom: calc(24px + var(--safe-bottom));
}

/* —— Header —— */
.top-bar {
  padding: 20px 20px 8px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(180deg, var(--md-surface) 60%, transparent);
}

.top-bar-inner {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(145deg, #283593, #1a237e 60%, #0d1642);
  box-shadow: 0 4px 12px rgba(26, 35, 126, 0.35);
  position: relative;
  flex-shrink: 0;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-bottom-width: 0;
  border-left-width: 0;
  transform: rotate(45deg) translate(-1px, 1px);
}

.brand-sub {
  font-size: 12px;
  font-weight: 500;
  color: var(--md-secondary);
  letter-spacing: 0.06em;
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.main {
  flex: 1;
  padding: 8px 16px 0;
}

/* —— Views —— */
.view {
  display: none;
  animation: fadeUp 0.35s var(--ease) both;
}

.view.active {
  display: block;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.card {
  background: var(--md-surface-card);
  border-radius: var(--radius);
  padding: 22px 18px 20px;
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.elevate {
  box-shadow: var(--md-shadow);
}

.card-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.card-title.center {
  text-align: center;
}

.card-hint {
  font-size: 13px;
  color: var(--md-on-surface-variant);
  margin-bottom: 18px;
}

.card-hint.center {
  text-align: center;
  margin-bottom: 0;
}

/* —— Member grid —— */
.member-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.role-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--md-on-surface-variant);
  margin: 12px 0 4px 4px;
}

.role-label:first-child {
  margin-top: 0;
}

.member-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 14px;
  border: 1.5px solid var(--md-outline-variant);
  border-radius: var(--radius-sm);
  background: #fafbff;
  color: var(--md-on-surface);
  font-family: inherit;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease),
    transform 0.2s var(--spring), box-shadow 0.2s var(--ease);
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}

.member-btn:hover {
  border-color: var(--md-primary-container);
  background: #f0f2ff;
}

.member-btn:active {
  transform: scale(0.98);
}

.member-btn.done {
  opacity: 0.55;
}

.member-btn .avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--md-primary);
  background: var(--md-primary-container);
  flex-shrink: 0;
}

.member-btn .meta {
  flex: 1;
  min-width: 0;
}

.member-btn .name {
  font-weight: 600;
}

.member-btn .tag {
  font-size: 12px;
  color: var(--md-on-surface-variant);
  margin-top: 1px;
}

.member-btn .status {
  font-size: 12px;
  font-weight: 600;
  color: var(--md-success);
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(27, 94, 32, 0.08);
}

/* —— Vote form —— */
.vote-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--md-outline-variant);
}

.who-label {
  font-size: 11px;
  color: var(--md-on-surface-variant);
}

.who-name {
  font-size: 16px;
  font-weight: 600;
}

.candidate-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 22px;
}

.candidate-row {
  padding: 14px;
  border-radius: var(--radius-sm);
  background: #f8f9fd;
  border: 1px solid var(--md-outline-variant);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.candidate-row.filled {
  border-color: rgba(57, 73, 171, 0.35);
  background: #f3f5ff;
}

.candidate-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.score-value {
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  font-weight: 700;
  color: var(--md-secondary);
  min-width: 2.2em;
  text-align: right;
}

.score-value.empty {
  color: var(--md-outline);
  font-weight: 500;
}

.score-pills {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
}

.score-pill {
  appearance: none;
  border: none;
  border-radius: 8px;
  height: 36px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--md-on-surface-variant);
  background: #fff;
  border: 1px solid var(--md-outline-variant);
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease),
    border-color 0.15s var(--ease), transform 0.15s var(--spring);
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}

.score-pill:hover {
  border-color: var(--md-secondary);
  color: var(--md-secondary);
}

.score-pill:active {
  transform: scale(0.92);
}

.score-pill.selected {
  background: var(--md-primary);
  border-color: var(--md-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(26, 35, 126, 0.35);
}

/* —— Buttons —— */
.btn-primary {
  display: block;
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 14px 24px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  color: var(--md-on-primary);
  background: linear-gradient(135deg, #3949ab, #1a237e);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(26, 35, 126, 0.35);
  transition: transform 0.2s var(--spring), opacity 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:hover {
  box-shadow: 0 6px 18px rgba(26, 35, 126, 0.42);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-outline {
  border: 1.5px solid var(--md-outline);
  border-radius: 999px;
  padding: 12px 20px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--md-primary);
  background: transparent;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-outline:active {
  background: rgba(26, 35, 126, 0.06);
}

.btn-text {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--md-secondary);
  cursor: pointer;
  padding: 8px 4px;
  -webkit-tap-highlight-color: transparent;
}

.btn-outline.sm,
.btn-text.sm {
  padding: 8px 14px;
  font-size: 13px;
}

/* —— Done —— */
.done-card {
  text-align: center;
  padding: 40px 24px;
}

.done-icon {
  color: var(--md-success);
  margin-bottom: 12px;
  animation: pop 0.5s var(--spring) both;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* —— Toast —— */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #2d2a32;
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s var(--ease);
  z-index: 100;
  max-width: calc(100% - 40px);
  box-shadow: var(--md-shadow-lg);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* —— Modal —— */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: end center;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 27, 31, 0.4);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-sheet {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: 20px;
  padding: 24px 20px 18px;
  animation: sheetUp 0.3s var(--spring);
}

@keyframes sheetUp {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.modal-sheet h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

.modal-body {
  font-size: 14px;
  color: var(--md-on-surface-variant);
  margin-bottom: 20px;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.modal-actions .btn-primary {
  padding: 12px;
}

/* —— Fields —— */
.field {
  display: block;
  margin-bottom: 16px;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--md-on-surface-variant);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--md-outline-variant);
  font-family: inherit;
  font-size: 16px;
  background: #fafbff;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus {
  border-color: var(--md-secondary);
}

.form-error {
  color: var(--md-error);
  font-size: 13px;
  margin-top: 10px;
  text-align: center;
}

/* Desktop breathing room */
@media (min-width: 600px) {
  .top-bar {
    padding-top: 28px;
  }

  .main {
    padding-top: 12px;
  }

  .card {
    padding: 28px 26px 24px;
  }

  .score-pill {
    height: 40px;
    font-size: 13px;
  }
}
