:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --ink: #171715;
  --muted: #777772;
  --line: #deded9;
  --accent: #e94732;
  --accent-dark: #cf3926;
  --soft-accent: #fff0ec;
  --success: #277b57;
  --shadow: 0 18px 46px rgba(25, 25, 22, 0.14);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  overscroll-behavior-y: none;
}

button {
  color: inherit;
  font: inherit;
  letter-spacing: 0;
  -webkit-tap-highlight-color: transparent;
}

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

.app-shell {
  width: min(100%, 760px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: var(--safe-top) 16px calc(28px + var(--safe-bottom));
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 58px;
  background: rgba(247, 247, 245, 0.94);
  border-bottom: 1px solid rgba(222, 222, 217, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 700;
}

.brand-mark {
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  background: var(--ink);
  color: white;
  font-family: Georgia, serif;
  font-size: 15px;
  font-style: italic;
}

.rules-button,
.page-footer button {
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.intro {
  display: grid;
  gap: 18px;
  padding: 30px 0 24px;
  border-bottom: 1px solid var(--line);
}

.date {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: "Noto Serif TC", "Songti TC", PMingLiU, serif;
  font-size: 38px;
  font-weight: 700;
  line-height: 1.08;
}

.intro-copy {
  max-width: 320px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.75;
}

.vote-status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
}

.vote-status.is-voted .status-dot {
  background: var(--accent);
}

.candidate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px 10px;
}

.candidate-card {
  position: relative;
  min-width: 0;
}

.candidate-card.is-voted .image-button::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  content: "已投票";
  background: rgba(23, 23, 21, 0.44);
  color: white;
  font-size: 13px;
  font-weight: 700;
}

.image-button {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: #e8e8e4;
  cursor: pointer;
}

.image-button img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--image-position, center);
  transition: transform 300ms ease;
}

.image-button:active img {
  transform: scale(1.018);
}

.candidate-number {
  position: absolute;
  z-index: 1;
  top: 8px;
  left: 8px;
  min-width: 28px;
  padding: 5px 6px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-family: Georgia, serif;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.card-copy {
  padding-top: 10px;
}

.card-name-row,
.sheet-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card-name {
  margin: 0;
  overflow: hidden;
  font-family: "Noto Serif TC", "Songti TC", PMingLiU, serif;
  font-size: 18px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vote-count {
  flex: 0 0 auto;
  margin: 2px 0 0;
  color: var(--accent);
  font-family: Georgia, serif;
  font-size: 15px;
  font-weight: 700;
}

.vote-count small {
  margin-left: 2px;
  color: var(--muted);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 10px;
  font-weight: 400;
}

.card-meta {
  margin: 5px 0 9px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-action {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.card-action::after {
  content: "→";
  color: var(--accent);
  font-size: 16px;
  line-height: 1;
}

.card-action:disabled {
  color: var(--muted);
}

.page-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 44px 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.sheet-backdrop {
  position: fixed;
  z-index: 80;
  inset: 0;
  background: rgba(17, 17, 15, 0.48);
  opacity: 0;
  transition: opacity 220ms ease;
}

.sheet-backdrop.is-open {
  opacity: 1;
}

.bottom-sheet {
  position: fixed;
  z-index: 90;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  max-width: 520px;
  max-height: calc(100vh - 16px);
  max-height: calc(100dvh - 28px);
  margin: auto;
  overflow: hidden;
  overscroll-behavior: contain;
  background: var(--surface);
  border-radius: 8px 8px 0 0;
  box-shadow: var(--shadow);
  transform: translateY(102%);
  transition: transform 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.bottom-sheet.is-open {
  transform: translateY(0);
}

.sheet-close {
  position: absolute;
  z-index: 2;
  top: 12px;
  right: 12px;
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 3px 16px rgba(0, 0, 0, 0.12);
}

.icon-button span {
  font-family: Arial, sans-serif;
  font-size: 26px;
  font-weight: 300;
  line-height: 1;
}

.sheet-media {
  position: relative;
  flex: 0 1 auto;
  min-height: 160px;
  height: 42vh;
  max-height: 360px;
  height: min(42dvh, 360px);
  overflow: hidden;
  background: #e9e9e5;
}

.sheet-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--image-position, center);
}

.sheet-number {
  position: absolute;
  bottom: 12px;
  left: 14px;
  padding: 7px 9px;
  background: var(--accent);
  color: white;
  font-family: Georgia, serif;
  font-size: 12px;
  font-weight: 700;
}

.sheet-body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 20px 20px calc(20px + var(--safe-bottom));
}

.sheet-heading h2,
.rules-content h2 {
  margin: 0;
  font-family: "Noto Serif TC", "Songti TC", PMingLiU, serif;
  font-size: 26px;
  line-height: 1.2;
}

.sheet-heading p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.sheet-votes {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.sheet-votes strong {
  color: var(--accent);
  font-family: Georgia, serif;
  font-size: 25px;
}

.sheet-votes span {
  font-size: 11px;
}

.sheet-description {
  margin: 17px 0 20px;
  color: #565651;
  font-size: 14px;
  line-height: 1.8;
}

.primary-button,
.secondary-button {
  width: 100%;
  min-height: 50px;
  padding: 0 20px;
  border: 1px solid var(--accent);
  border-radius: 3px;
  background: var(--accent);
  color: white;
  font-size: 15px;
  font-weight: 700;
}

.primary-button:active {
  background: var(--accent-dark);
}

.primary-button:disabled {
  border-color: #d1d1cc;
  background: #d1d1cc;
  color: #777772;
}

.rules-content {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 34px 22px calc(22px + var(--safe-bottom));
}

@media (max-height: 560px) {
  .sheet-media {
    min-height: 132px;
    height: 34vh;
    height: 34dvh;
  }

  .sheet-body {
    padding-top: 16px;
  }

  .sheet-description {
    margin-top: 12px;
    margin-bottom: 14px;
    line-height: 1.65;
  }
}

.rules-content ol {
  margin: 24px 0 28px;
  padding: 0;
  list-style: none;
}

.rules-content li {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 12px;
  padding: 15px 0;
  border-top: 1px solid var(--line);
}

.rules-content li:last-child {
  border-bottom: 1px solid var(--line);
}

.rules-content li span {
  color: var(--accent);
  font-family: Georgia, serif;
  font-size: 13px;
  font-weight: 700;
}

.rules-content li p {
  margin: 0;
  font-size: 14px;
  line-height: 1.65;
}

.secondary-button {
  border-color: var(--ink);
  background: var(--ink);
}

.toast {
  position: fixed;
  z-index: 120;
  right: 20px;
  bottom: calc(24px + var(--safe-bottom));
  left: 20px;
  max-width: 420px;
  margin: auto;
  padding: 13px 16px;
  background: var(--ink);
  color: white;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(14px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

body.sheet-open {
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

@media (min-width: 620px) {
  .app-shell {
    padding-right: 24px;
    padding-left: 24px;
  }

  .intro {
    grid-template-columns: 1fr 1fr;
    align-items: end;
    padding-top: 42px;
    padding-bottom: 30px;
  }

  h1 {
    font-size: 48px;
  }

  .candidate-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 28px 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
