/* display.css */
html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
}

#display-root {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

#display-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.3rem 1rem;
  background: var(--bg2);
  border-bottom: 2px solid var(--accent);
  flex-shrink: 0;
  gap: 1rem;
}

#display-event-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}

#display-round-label {
  font-size: 0.9rem;
  padding: 0.15em 0.7em;
  background: var(--accent);
  color: #000;
  border-radius: 20px;
  font-weight: 700;
}

#display-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  gap: 0.8rem;
  align-items: center;
}

#connection-status {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

#connection-status.warn { background: var(--danger); }

#display-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Setup / idle screen */
#screen-setup {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  flex-direction: column;
  gap: 1rem;
  color: var(--text-muted);
}

#screen-setup h2 { font-size: 2rem; color: var(--accent); }

#setup-image {
  max-width: min(92vw, 1200px);
  max-height: min(65vh, 760px);
  object-fit: contain;
  border: 2px solid var(--border);
  border-radius: var(--radius);
}

/* ============ 1st Round Display ============ */
#screen-1st {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0.5rem;
  gap: 0.4rem;
}

.d1-q-label {
  text-align: center;
  font-size: 1.1rem;
  color: var(--text-muted);
  font-weight: 600;
}

#d1-players {
  flex: 1;
  display: flex;
  align-items: stretch;
  gap: 0.4rem;
  overflow-x: auto;
  min-height: 0;
}

.d1-player {
  flex: 1;
  min-width: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.3rem;
  transition: border-color 0.3s, opacity 0.3s, background 0.3s;
  gap: 0.3rem;
}

.d1-player.winner {
  border-color: var(--accent);
  background: #2a1e00;
}

.d1-player.resting {
  opacity: 1;
  border-color: #777;
  background: #3e3e3e;
}

.d1-player.combo-cand {
  box-shadow: var(--combo-glow);
  border-color: #fa0;
}

.d1-player.eliminated {
  opacity: 0.2;
}

.d1-pid {
  font-size: clamp(0.9rem, 2.1vh, 1.45rem);
  color: var(--text-muted);
  writing-mode: horizontal-tb;
  line-height: 1;
}

.d1-name-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.d1-name {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: clamp(1rem, 5.3vh, 3rem);
  font-weight: 700;
  line-height: 1;
  max-height: 100%;
  max-width: 100%;
  overflow: hidden;
}

.d1-circles {
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  justify-content: flex-start;
  align-items: center;
}

.d1-circles-wrap {
  position: relative;
  padding-top: 1.6rem;
}

.d1-rest-plate {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 3.2em;
  font-size: 1.2rem;
  font-weight: 900;
  line-height: 1;
  color: #111;
  background: #fff;
  border: 2px solid #000;
  border-radius: 4px;
  padding: 4px 10px;
  white-space: nowrap;
}

.d1-circle {
  width: clamp(18px, 4vw, 34px);
  height: clamp(18px, 4vw, 34px);
  border-radius: 50%;
  border: 2px solid #555;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
}

.d1-circle.filled {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
  font-weight: 700;
}

.d1-circle.handicap.filled {
  background: #669;
  border-color: #669;
  color: #fff;
}

.d1-circle.winner-dot {
  background: var(--accent);
  border-color: #fff;
}

.d1-badges {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ============ 2nd Round Display ============ */
#screen-2nd {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0.5rem;
  gap: 0.4rem;
}

.d2-q-label {
  text-align: center;
  font-size: 1.1rem;
  color: var(--text-muted);
  font-weight: 600;
}

#d2-players {
  flex: 1;
  display: flex;
  align-items: stretch;
  gap: 0.4rem;
  overflow: hidden;
  min-height: 0;
}

.d2-player {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
  background: var(--bg2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem;
  gap: 0.35rem;
}

.d2-player.qualified {
  border-color: var(--accent);
  background: #2a1e00;
}

.d2-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}

.d2-pid {
  font-size: clamp(0.7rem, 1.6vw, 1.2rem);
  color: var(--text-muted);
}

.d2-name {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: clamp(1rem, 5.1vh, 3rem);
  font-weight: 700;
  overflow: hidden;
  line-height: 1;
  max-height: 100%;
}

.d2-total {
  font-size: clamp(1.2rem, 3vw, 5rem);
  font-weight: 900;
  color: var(--accent);
  line-height: 1;
}

.d2-rank {
  font-size: clamp(0.8rem, 2vw, 4rem);
  color: var(--text-muted);
}

.d2-history {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  min-height: calc((clamp(1rem, 2.2vh, 1.8rem) + 8px) * 5);
}

.d2-q-cell {
  font-size: clamp(1rem, 2.2vh, 1.8rem);
  font-weight: 800;
  text-align: center;
  border-radius: 3px;
  padding: 4px 3px;
  background: var(--bg3);
}

.d2-q-cell.correct { background: #1a4a1a; color: #8f8; }
.d2-q-cell.wrong { background: #4a1a1a; color: #f88; }

.d2-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  padding-top: 0.25rem;
  border-radius: 4px;
}

.d2-meta.tie-pending {
  background: #ffe26a;
  border-top-color: #b08a00;
  color: #201500;
  padding: 0.25rem 0.3rem 0;
}

.d2-meta.tie-pending .d2-rank,
.d2-meta.tie-pending .d2-total {
  color: #201500;
}

/* ============ Final Display ============ */
#screen-final {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0.5rem;
  gap: 0.4rem;
}

.df-q-label {
  text-align: center;
  font-size: 1.1rem;
  color: var(--text-muted);
  font-weight: 600;
}

#df-players {
  flex: 1;
  display: flex;
  align-items: stretch;
  gap: 0.4rem;
  min-height: 0;
}

.df-player {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.3rem;
  gap: 0.3rem;
  transition: all 0.4s ease;
  position: relative;
}

.df-player.confirmed {
  opacity: 0.45;
  border-color: #555;
}

.df-player.warning {
  background: rgba(255, 210, 50, 0.62);
  border-color: #ffdc7a;
}

.df-player.confirmed .df-rank-num {
  color: var(--accent);
}

.df-rank-num {
  font-size: clamp(1.6rem, 7vh, 4rem);
  font-weight: 900;
  color: var(--text-muted);
  line-height: 1;
}

.df-pid {
  font-size: clamp(0.95rem, 2.2vh, 1.5rem);
  color: var(--text-muted);
  writing-mode: horizontal-tb;
  line-height: 1;
}

.df-name-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.df-name {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: clamp(1rem, 6.2vh, 3.8rem);
  font-weight: 700;
  max-height: 100%;
  max-width: 100%;
  overflow: hidden;
  line-height: 1;
}

.df-confirmed-label {
  font-size: 0.65rem;
  background: var(--accent);
  color: #000;
  border-radius: 3px;
  padding: 1px 4px;
  font-weight: 700;
}

.df-affiliation {
  min-height: 1.2em;
  font-size: clamp(0.7rem, 1.5vh, 1rem);
  color: #cfcfcf;
  writing-mode: horizontal-tb;
  text-align: center;
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Rank change animation */
@keyframes rankUp {
  0% { background: #0a3a0a; }
  83.333% { background: #0a3a0a; } /* 10秒保持 */
  100% { background: var(--bg2); }
}

@keyframes rankDown {
  0% { background: #3a0a0a; }
  83.333% { background: #3a0a0a; } /* 10秒保持 */
  100% { background: var(--bg2); }
}

.df-player.anim-up { animation: rankUp 12s linear; }
.df-player.anim-down { animation: rankDown 12s linear; }

.df-player.podium-1 { background: rgba(255, 215, 0, 0.58); }
.df-player.podium-2 { background: rgba(192, 192, 192, 0.52); }
.df-player.podium-3 { background: rgba(205, 127, 50, 0.56); }
