:root {
  color-scheme: light;
  --paper: #fff;
  --ink: #0d0d0d;
  --muted: #777;
  --hairline: #e8e2db;
  --soft: #f8f6f2;
  --danger: #9a1f1f;
  --ok: #346b45;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Manrope', 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
}

a,
button,
input,
textarea,
select {
  color: inherit;
  font: inherit;
}

a {
  text-decoration: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1160px;
  margin: 0 auto;
  padding: 34px 28px;
}

.brand {
  font-family: var(--serif);
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 500;
}

.nav {
  display: flex;
  align-items: center;
  gap: 28px;
  font-size: 14px;
  color: var(--muted);
}

.nav a:hover,
.link-button:hover {
  color: var(--ink);
}

.language-select {
  width: auto;
  min-width: 58px;
  padding: 0 0 4px;
  border-bottom-color: transparent;
  color: var(--muted);
  cursor: pointer;
}

.language-select:hover,
.language-select:focus {
  color: var(--ink);
  border-bottom-color: var(--hairline);
}

.link-button {
  width: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.duel-shell {
  display: grid;
  min-height: calc(100vh - 120px);
  place-items: center;
  align-content: center;
  gap: 34px;
  width: 100%;
  max-width: 1880px;
  margin: 0 auto;
  padding: 20px clamp(18px, 3vw, 56px) 70px;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-transform: lowercase;
}

.duel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  width: 100%;
  gap: clamp(24px, 3vw, 56px);
}

.duel.duel-wide {
  grid-template-columns: minmax(0, 1fr);
  width: min(1680px, 100%);
  gap: clamp(28px, 5vh, 58px);
  justify-items: center;
}

.duel.duel-wide .divider {
  order: 2;
  justify-self: center;
  width: 100%;
  text-align: center;
}

.duel.duel-wide #left-card {
  order: 1;
}

.duel.duel-wide #right-card {
  order: 3;
}

.duel.duel-wide .nickname-choice {
  min-height: 172px;
  padding: 28px clamp(16px, 2vw, 34px);
}

.choice-card {
  position: relative;
  display: grid;
  min-width: 0;
  width: 100%;
  justify-items: center;
  align-content: center;
}

.report-button {
  position: absolute;
  top: 58px;
  right: clamp(16px, 2vw, 34px);
  z-index: 4;
  display: grid;
  place-items: center;
  width: 32px;
  height: 28px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  padding-top: 5px;
}

.report-button::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--hairline);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  transition: background 160ms ease;
}

.report-button:hover,
.report-button:focus-visible {
  color: var(--ink);
  outline: none;
}

.report-button:hover::before,
.report-button:focus-visible::before {
  background: #d8d0c8;
}

.report-button[hidden] {
  display: none;
}

.nickname-choice {
  display: grid;
  min-width: 0;
  width: 100%;
  min-height: 300px;
  place-items: center;
  align-content: center;
  gap: 18px;
  padding: 36px clamp(16px, 1.8vw, 30px);
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  text-align: center;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.nickname-choice:hover:not(:disabled),
.nickname-choice:focus-visible {
  border-color: var(--hairline);
  background: var(--soft);
  outline: none;
  transform: translateY(-2px);
}

.nickname-choice:disabled {
  cursor: default;
}

.nickname-text {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  white-space: nowrap;
  font-family: var(--serif);
  font-size: clamp(48px, 7vw, 104px);
  font-weight: 500;
  line-height: 0.9;
}

.nickname-meta {
  min-height: 24px;
  color: var(--muted);
  font-size: 13px;
}

.nickname-details {
  width: min(520px, 88%);
  margin-top: -42px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  z-index: 2;
}

.nickname-details summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  padding: 0;
  border-bottom: 1px solid var(--hairline);
  cursor: pointer;
  list-style: none;
  transition: border-color 160ms ease;
}

.nickname-details summary:hover {
  border-bottom-color: var(--muted);
}

.nickname-details summary::-webkit-details-marker {
  display: none;
}

.nickname-details summary::after {
  content: '⌄';
  transform: translateY(-1px);
  font-size: 16px;
  line-height: 1;
}

.nickname-details[open] summary::after {
  transform: rotate(180deg) translateY(1px);
}

.nickname-details p {
  margin: 8px 0 0;
  overflow-wrap: anywhere;
  text-align: center;
}

.divider {
  color: var(--muted);
  font-family: var(--serif);
  font-size: 28px;
  font-style: italic;
}

.duel-message {
  min-height: 24px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.duel-message.error,
.message.error {
  color: var(--danger);
}

.duel-message.ok,
.message.ok {
  color: var(--ok);
}

.quiet-actions {
  display: flex;
  gap: 24px;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
}

.submit-dialog {
  width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--hairline);
  padding: 34px;
  background: var(--paper);
}

.report-dialog {
  width: min(480px, calc(100vw - 32px));
}

.submit-dialog::backdrop {
  background: rgb(255 255 255 / 0.72);
  backdrop-filter: blur(8px);
}

.submit-dialog form {
  display: grid;
  gap: 12px;
}

.submit-dialog h1,
.leaderboard-shell h1 {
  margin: 0 0 22px;
  font-family: var(--serif);
  font-size: clamp(42px, 6vw, 76px);
  font-weight: 500;
  line-height: 0.95;
}

label {
  color: var(--muted);
  font-size: 13px;
}

.field-note {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

input,
textarea,
select {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  border-radius: 0;
  background: transparent;
  padding: 12px 0;
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-bottom-color: var(--ink);
}

textarea {
  resize: vertical;
}

.submit-button {
  width: auto;
  justify-self: start;
  margin-top: 14px;
  border: 0;
  border-bottom: 1px solid var(--ink);
  background: transparent;
  padding: 4px 0;
  cursor: pointer;
}

.close-button {
  position: absolute;
  top: 18px;
  right: 20px;
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 24px;
}

.message {
  min-height: 22px;
  margin: 0;
  font-size: 13px;
}

.leaderboard-shell {
  max-width: 860px;
  margin: 0 auto;
  padding: 64px 28px 96px;
}

.leaderboard-list {
  display: grid;
  gap: 0;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 22px;
  padding: 24px 0;
  border-top: 1px solid var(--hairline);
}

.leaderboard-row:last-child {
  border-bottom: 1px solid var(--hairline);
}

.rank {
  color: var(--muted);
  font-family: var(--serif);
  font-size: 34px;
  line-height: 1;
}

.leaderboard-row h2 {
  margin: 0;
  max-width: 100%;
  white-space: nowrap;
  font-family: var(--serif);
  font-size: clamp(30px, 5vw, 52px);
  font-weight: 500;
  line-height: 1;
}

.leaderboard-row p,
.empty-state {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.admin-shell {
  max-width: 920px;
  margin: 0 auto;
  padding: 76px 28px 96px;
}

.admin-login {
  width: min(420px, 100%);
  margin: 18vh auto 0;
}

.admin-login form {
  display: grid;
  gap: 14px;
}

.admin-content {
  display: grid;
  gap: 34px;
}

.admin-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--hairline);
  padding-bottom: 22px;
}

.admin-header h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(42px, 6vw, 76px);
  font-weight: 500;
  line-height: 0.95;
}

.admin-actions {
  display: flex;
  align-items: center;
  gap: 18px;
}

.panel h2 {
  margin: 0 0 14px;
  font-family: var(--serif);
  font-size: clamp(30px, 4vw, 46px);
  font-weight: 500;
}

.list {
  display: grid;
  border-top: 1px solid var(--hairline);
}

.item {
  display: grid;
  gap: 6px;
  padding: 18px 0;
  border-bottom: 1px solid var(--hairline);
}

.item h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 500;
}

.item .meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.report-item {
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 22px;
}

.report-rank {
  color: var(--muted);
  font-family: var(--serif);
  font-size: 34px;
  line-height: 1;
}

.report-body {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.report-body h3 span {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 400;
}

.admin-comments {
  width: 100%;
  color: var(--muted);
  font-size: 13px;
}

.admin-comments summary {
  width: max-content;
  border-bottom: 1px solid var(--hairline);
  cursor: pointer;
  list-style: none;
}

.admin-comments summary::-webkit-details-marker {
  display: none;
}

.admin-comments summary::after {
  content: '⌄';
  margin-left: 8px;
}

.admin-comments[open] summary::after {
  content: '⌃';
}

.admin-comments ul {
  display: grid;
  gap: 10px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.admin-comments li {
  border-left: 1px solid var(--hairline);
  padding-left: 12px;
}

.admin-comments p {
  margin: 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.admin-comments span {
  color: var(--muted);
  font-size: 12px;
}

/* ── Countdown overlay ─────────────────────────────────────── */
.countdown-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: none; /* Hidden by default to prevent overlapping with content when idle */
  align-items: center;
  justify-content: center;
  pointer-events: none; /* Let all clicks pass through to content, we will use JS global click listener instead */
  background: transparent;
}

.countdown-overlay.active {
  display: flex; /* Shown only when active during countdown */
}

.countdown-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: rgba(255, 255, 255, 0.88); /* Glassmorphic card background */
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--hairline);
  border-radius: 28px;
  padding: 32px 40px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.08);
  pointer-events: auto; /* Capture clicks on the widget itself */
}

.countdown-label {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  text-transform: lowercase;
  opacity: 0.8;
  letter-spacing: 0.05em;
}

.countdown-ring {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 180px;
  height: 180px;
}

.countdown-ring svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.countdown-ring svg circle {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.5;
  stroke-linecap: round;
  transition: none;
}

.countdown-ring svg circle.track {
  stroke: var(--hairline);
  stroke-width: 1.5;
}

.countdown-digit {
  position: relative;
  top: -4px; /* Move slightly up to account for vertical alignment in the circle */
  z-index: 1;
  font-family: var(--serif);
  font-size: 88px;
  font-weight: 500;
  line-height: 1;
  font-variant-numeric: lining-nums;
  -moz-font-feature-settings: "lnum";
  -webkit-font-feature-settings: "lnum";
  font-feature-settings: "lnum"; /* Prevent hanging old-style numerals */
  color: var(--ink);
  user-select: none;
}

@keyframes cd-in {
  from { transform: scale(1.4); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

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

@keyframes cd-overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes cd-overlay-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

.countdown-overlay.cd-entering {
  animation: cd-overlay-in 240ms ease forwards;
}

.countdown-overlay.cd-exiting {
  animation: cd-overlay-out 320ms ease forwards;
}

.countdown-digit.cd-digit-in {
  animation: cd-in 220ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.countdown-digit.cd-digit-out {
  animation: cd-out 180ms ease-in forwards;
}

/* ── Circle progress animation ──────────────────────────────── */
@keyframes progress-drain {
  from { stroke-dashoffset: 0; }
  to   { stroke-dashoffset: var(--cd-circumference); }
}

.progress-arc {
  animation: progress-drain var(--cd-duration, 1s) linear forwards;
}

/* ── Card entrance animation ────────────────────────────────── */
@keyframes card-enter-left {
  from { opacity: 0; transform: translateX(-48px) scale(0.94); }
  to   { opacity: 1; transform: translateX(0)     scale(1); }
}

@keyframes card-enter-right {
  from { opacity: 0; transform: translateX(48px) scale(0.94); }
  to   { opacity: 1; transform: translateX(0)    scale(1); }
}

@keyframes card-enter-up {
  from { opacity: 0; transform: translateY(38px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.choice-card.card-entering-left {
  animation: card-enter-left 420ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.choice-card.card-entering-right {
  animation: card-enter-right 420ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.choice-card.card-entering-up {
  animation: card-enter-up 420ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* ── Divider entrance ───────────────────────────────────────── */
@keyframes divider-enter {
  from { opacity: 0; transform: scale(0.7); }
  to   { opacity: 1; transform: scale(1); }
}

.divider.divider-entering {
  animation: divider-enter 380ms cubic-bezier(0.22, 1, 0.36, 1) 120ms both;
}

/* ── Choice button locked state ─────────────────────────────── */
.nickname-choice.choice-locked {
  pointer-events: none;
  opacity: 0.45;
  cursor: default;
}

@media (max-width: 768px) {
  .topbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    justify-items: center;
    width: 100%;
    min-width: 0;
    padding: 24px 18px;
    text-align: center;
  }

  .brand {
    max-width: 100%;
    overflow-wrap: anywhere;
    font-size: clamp(30px, 9vw, 38px);
  }

  .nav {
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px 18px;
    width: 100%;
    min-width: 0;
  }

  .duel-shell {
    min-height: auto;
    overflow: hidden;
    padding: 42px 18px 40px;
  }

  .duel {
    grid-template-columns: 1fr;
    gap: 28px;
    justify-items: center;
  }

  .duel .divider {
    order: 2;
  }

  #left-card {
    order: 1;
  }

  #right-card {
    order: 3;
  }

  .nickname-choice {
    width: 100%;
    max-width: 100%;
    min-height: 210px;
    padding: 58px 18px 24px;
    overflow: hidden;
  }

  .report-button {
    top: 10px;
    right: 10px;
  }

  .nickname-text {
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    font-size: clamp(34px, 11vw, 54px);
    line-height: 0.9;
  }

  .divider {
    font-size: 22px;
  }

  .quiet-actions {
    flex-wrap: wrap;
  }

  .submit-dialog {
    padding: 28px 22px;
  }

  .admin-header {
    align-items: start;
    flex-direction: column;
  }

  .report-item {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

/* ── Choice card selected and dimmed states ────────────────── */
.choice-card {
  transition: opacity 280ms ease, transform 280ms ease;
}

.choice-card.choice-selected,
.choice-card.choice-dimmed {
  cursor: default;
}

.choice-card.choice-selected .nickname-choice {
  border-color: var(--ink);
  background: var(--soft);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.03);
  transform: scale(1.02);
}

.choice-card.choice-dimmed .nickname-choice {
  cursor: pointer;
}

.choice-card.choice-dimmed {
  opacity: 0.35;
  transform: scale(0.96);
}
