:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #111827;
  --muted: #64748b;
  --line: #d9e2ec;
  --primary: #136f63;
  --primary-ink: #ffffff;
  --danger: #b9383a;
  --success-bg: #ecfdf3;
  --success-line: #b7e4c6;
  --miss-bg: #fff3f3;
  --miss-line: #f2c2c2;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;

  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;

  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Noto Sans KR", sans-serif;
  line-height: 1.45;
}

.page {
  width: min(1380px, calc(100% - 20px));
  margin: 10px auto 22px;
  display: grid;
  gap: var(--s-3);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.topbar-title {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.topbar-title h1 {
  margin: 0;
  font-size: clamp(1.5rem, 2.5vw, 2.1rem);
  line-height: 1.15;
  letter-spacing: 0.01em;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mode {
  margin: 0;
  font-size: 0.83rem;
  color: #1e3a5f;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.18rem 0.56rem;
  background: #f8fafc;
}

.live-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: var(--s-3);
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}

#snapshot-view {
  padding: var(--s-4);
  display: grid;
  gap: var(--s-3);
}

#snapshot-view h2 {
  margin: 0;
}

.board {
  position: relative;
}

.board-panel {
  padding: 44px 12px 12px;
  display: grid;
  gap: 10px;
  overflow: visible;
  position: relative;
}

.phase-floating {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 6;
  pointer-events: none;
}

.phase-floating #phase-label {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  font-size: 0.79rem;
  color: #334155;
  font-weight: 600;
  letter-spacing: 0.01em;
  background: rgba(248, 250, 252, 0.92);
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(1px);
}

.phase-floating #phase-label::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #64748b;
}

.phase-floating #phase-label[data-phase='setup']::before {
  background: #475569;
}

.phase-floating #phase-label[data-phase='seat']::before {
  background: #0f766e;
}

.phase-floating #phase-label[data-phase='locked']::before {
  background: #b45309;
}

.phase-floating #phase-label[data-phase='running']::before {
  background: #2563eb;
}

.phase-floating #phase-label[data-phase='ended']::before {
  background: #7c3aed;
}

.phase-floating #phase-label[data-phase='snapshot']::before {
  background: #0284c7;
}

.phase-floating #phase-label[data-phase='snapshot-error']::before {
  background: #b91c1c;
}

.ladder-wrap {
  width: 100%;
  aspect-ratio: 1000 / 640;
  overflow: visible;
  position: relative;
}

.ladder-shell {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  padding: 16px;
  overflow: visible;
  position: relative;
}

#ladder-svg {
  width: 100%;
  height: 100%;
}

.seat-head-layer,
.result-foot-layer,
.token-layer {
  position: absolute;
  inset: 0;
}

.seat-head-layer,
.result-foot-layer {
  pointer-events: none;
  z-index: 2;
}

.token-layer {
  pointer-events: none;
  z-index: 3;
}

.start-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.22);
  border-radius: inherit;
}

.start-overlay.hidden {
  display: none !important;
}

.start-overlay-text {
  font-size: clamp(2.7rem, 8vw, 5.4rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.01em;
  color: #fff;
  animation: countdown-pop 180ms ease-out;
}

.start-overlay.go .start-overlay-text {
  color: #ffe7a3;
  animation: go-pop 140ms ease-out;
}

.control {
  padding: var(--s-3);
  display: grid;
  gap: var(--s-3);
  align-content: start;
  max-height: calc(100vh - 84px);
  overflow: auto;
}

.section-card {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-soft);
  padding: var(--s-3);
  display: grid;
  gap: var(--s-2);
}

.section-card h2,
.section-card h3 {
  margin: 0;
  line-height: 1.25;
}

.section-card h2 {
  font-size: 0.98rem;
}

.section-card h3 {
  font-size: 0.9rem;
}

label,
.muted {
  font-size: 0.84rem;
  color: var(--muted);
}

.row {
  display: flex;
  gap: var(--s-2);
}

.name-row #name-input {
  flex: 1 1 auto;
  min-width: 0;
}

.name-row #name-save {
  flex: 0 0 84px;
  min-width: 84px;
  white-space: nowrap;
}

.snapshot-row #snapshot-url {
  flex: 1 1 auto;
  min-width: 0;
}

.snapshot-row #snapshot-copy {
  flex: 0 0 72px;
  min-width: 72px;
  white-space: nowrap;
}

.motion-presets button {
  flex: 1;
  min-width: 0;
  font-size: 0.78rem;
}

.fold {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  overflow: hidden;
}

.fold > summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 12px;
  font-size: 0.88rem;
  font-weight: 700;
  color: #334155;
  border-bottom: 1px solid transparent;
}

.fold[open] > summary {
  border-bottom-color: var(--line);
  background: #f8fafc;
}

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

.fold > .section-card {
  border: 0;
  border-radius: 0;
  background: var(--surface);
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: #fff;
  color: var(--text);
  padding: 0 10px;
}

input[type='range'] {
  height: auto;
  border: 0;
  padding: 0;
  background: transparent;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: #f8fafc;
  color: var(--text);
  padding: 0.5rem 0.76rem;
  font-weight: 600;
  cursor: pointer;
}

button.primary {
  background: var(--primary);
  border-color: color-mix(in oklab, var(--primary) 65%, #000);
  color: var(--primary-ink);
}

button.danger {
  background: var(--danger);
  border-color: color-mix(in oklab, var(--danger) 60%, #000);
  color: #fff;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid color-mix(in oklab, var(--primary) 70%, #fff);
  outline-offset: 1px;
}

.host-actions-row {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: var(--s-2);
}

.host-claim-row #host-claim {
  width: 100%;
  min-height: 38px;
  padding: 0.5rem 0.76rem;
  font-size: inherit;
}

.host-actions-row button {
  width: auto;
  min-height: 34px;
  padding: 0.35rem 0.62rem;
  font-size: 0.82rem;
  flex: 0 0 auto;
}

.flash {
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: var(--r-sm);
  background: #f8fafc;
  min-height: 40px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 0.85rem;
  color: #334155;
}

.flash:empty {
  display: none;
}

.trail-path {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.94;
}

.seat-card {
  --seat-accent: #64748b;
  --seat-bg: #e7effd;
  --seat-fg: #162333;
  position: absolute;
  transform: translateX(-50%);
  width: 110px;
  min-height: 42px;
  border-radius: 11px;
  border: 1px solid color-mix(in oklab, var(--seat-accent) 38%, #d0ddf0);
  background: var(--seat-bg);
  color: var(--seat-fg);
  padding: 0.24rem 0.38rem;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "name chip"
    "name tag";
  row-gap: 2px;
  column-gap: 0.24rem;
  overflow: hidden;
}

.seat-card.empty {
  --seat-fg: #334155;
  border-style: dashed;
  border-color: #cad5e4;
  background: #f3f6fb;
}

.seat-card.me {
  outline: 2px solid color-mix(in oklab, var(--seat-accent) 62%, #0f172a);
}

.seat-name {
  grid-area: name;
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  align-self: center;
}

.seat-chip {
  grid-area: chip;
  width: 0.54rem;
  height: 0.54rem;
  border-radius: 50%;
  background: var(--seat-accent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7);
  justify-self: end;
  align-self: start;
}

.seat-tag {
  grid-area: tag;
  justify-self: end;
  border-radius: 999px;
  padding: 0.05rem 0.3rem;
  font-size: 0.56rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.86);
  color: #334155;
}

.result-pill {
  position: absolute;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 110px;
  min-height: 31px;
  border-radius: 11px;
  padding: 0.16rem 0.3rem;
  border: 1px solid #cdd8e7;
  background: #f8fbff;
  color: #334155;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.08;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-pill.win {
  background: var(--success-bg);
  border-color: var(--success-line);
  color: #155d34;
}

.result-pill.miss {
  background: var(--miss-bg);
  border-color: var(--miss-line);
  color: #8b1f1f;
}

.token {
  position: absolute;
  min-width: 64px;
  max-width: 132px;
  height: 30px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.54rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.24);
}

.token.token-arrive-win {
  animation: ring-win 760ms ease-out;
}

.token.token-arrive-miss {
  animation: ring-miss 760ms ease-out;
}

.arrival-feed {
  display: none;
}

.result-panel {
  margin-top: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  padding: var(--s-3);
}

.result-panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--s-2);
}

.result-panel-head h3 {
  margin: 0;
  font-size: 0.98rem;
}

.result-table {
  display: grid;
  gap: 6px;
}

.result-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 8px;
  align-items: center;
  border: 1px solid #d5dfea;
  border-radius: 10px;
  padding: 0.42rem 0.54rem;
  font-size: 0.84rem;
  background: #fff;
}

.result-row.win {
  background: #f7fdf9;
  border-color: var(--success-line);
}

.result-row.miss {
  background: #fff8f8;
  border-color: var(--miss-line);
}

.row-name {
  font-weight: 700;
}

.row-seat {
  font-size: 0.75rem;
  color: var(--muted);
}

.row-prize {
  font-weight: 700;
}

.result-empty {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 0.7rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  background: #f8fafc;
}

.arrival-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  padding: 0.3rem 0.65rem;
  color: #fff;
  font-size: 0.84rem;
  animation: pop 420ms ease;
}

.arrival-user-dot {
  width: 0.58rem;
  height: 0.58rem;
  border-radius: 50%;
  display: inline-block;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55);
}

.arrival-item.win {
  background: #1e7f43;
}

.arrival-item.miss {
  background: #b91c1c;
}

.notice.warning {
  border: 1px solid #f4cccc;
  border-radius: var(--r-sm);
  background: #fff5f5;
  color: #8a1d1d;
  padding: 0.5rem 0.7rem;
}

.result-list {
  display: grid;
  gap: 0.42rem;
}

.result-item {
  display: flex;
  align-items: center;
  gap: 0.42rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  background: #fff;
}

.result-item.miss {
  border-color: var(--miss-line);
  background: #fff7f7;
}

.hidden {
  display: none !important;
}

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

@keyframes countdown-pop {
  0% {
    transform: scale(0.95);
    opacity: 0.45;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes go-pop {
  0% {
    transform: scale(0.92);
    opacity: 0.5;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes ring-win {
  0% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.72), 0 2px 8px rgba(15, 23, 42, 0.24);
    transform: translate(-50%, -50%) scale(1);
  }
  45% {
    box-shadow: 0 0 0 12px rgba(34, 197, 94, 0), 0 2px 8px rgba(15, 23, 42, 0.24);
    transform: translate(-50%, -50%) scale(1.1);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0), 0 2px 8px rgba(15, 23, 42, 0.24);
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes ring-miss {
  0% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.72), 0 2px 8px rgba(15, 23, 42, 0.24);
    transform: translate(-50%, -50%) scale(1);
  }
  45% {
    box-shadow: 0 0 0 12px rgba(220, 38, 38, 0), 0 2px 8px rgba(15, 23, 42, 0.24);
    transform: translate(-50%, -50%) scale(1.1);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0), 0 2px 8px rgba(15, 23, 42, 0.24);
    transform: translate(-50%, -50%) scale(1);
  }
}

@media (max-width: 1100px) {
  .live-layout {
    grid-template-columns: 1fr;
  }

  .control {
    max-height: none;
  }

  .side-panel {
    order: 2;
  }

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

  .topbar-controls {
    width: 100%;
    justify-content: space-between;
  }

}

@media (max-width: 820px) {
  .page {
    width: calc(100% - 10px);
    margin: 8px auto 14px;
    gap: var(--s-2);
  }

  .topbar {
    padding: 10px 12px;
    border-radius: var(--r-md);
  }

  .topbar-title h1 {
    font-size: clamp(1.28rem, 6.7vw, 1.72rem);
  }

  .panel,
  .board-panel {
    border-radius: var(--r-md);
  }

  #snapshot-view {
    padding: var(--s-3);
    gap: var(--s-2);
  }

  .board-panel {
    padding: 38px 10px 10px;
    gap: 10px;
  }

  .phase-floating {
    top: 10px;
    right: 10px;
  }

  .ladder-shell {
    padding: 12px;
  }

  .control {
    padding: var(--s-2);
    gap: var(--s-2);
  }

  .section-card {
    padding: 10px;
  }

  .row {
    flex-wrap: wrap;
  }

  .name-row,
  .snapshot-row {
    flex-wrap: nowrap;
  }

  input,
  select,
  button {
    min-height: 36px;
  }

  .seat-card {
    width: clamp(64px, 13vw, 78px);
    min-height: 32px;
    padding: 0.16rem 0.24rem;
    border-radius: 9px;
  }

  .seat-name {
    font-size: 0.64rem;
  }

  .result-pill {
    width: clamp(64px, 13vw, 78px);
    min-height: 25px;
    font-size: 0.58rem;
    padding: 0.1rem 0.16rem;
    border-radius: 8px;
  }

  .token {
    min-width: 52px;
    max-width: 94px;
    height: 25px;
    font-size: 0.62rem;
    padding: 0 0.4rem;
  }

  .result-row {
    grid-template-columns: auto 1fr auto;
  }

  .row-seat {
    display: none;
  }
}

@media (max-width: 540px) {
  .board-panel {
    padding: 34px 8px 8px;
    gap: 6px;
  }

  .ladder-shell {
    padding: 10px;
  }

  .topbar-controls {
    gap: 6px;
  }

  .mode {
    font-size: 0.75rem;
  }

  .phase-floating {
    top: 8px;
    right: 8px;
  }

  .phase-floating #phase-label {
    font-size: 0.72rem;
    padding: 4px 8px;
    gap: 6px;
  }

  .host-actions-row {
    gap: 6px;
  }

  .seat-card {
    width: clamp(54px, 13vw, 66px);
    min-height: 29px;
    padding: 0.12rem 0.17rem;
    border-radius: 8px;
  }

  .seat-name {
    font-size: 0.58rem;
  }

  .seat-chip {
    width: 0.42rem;
    height: 0.42rem;
  }

  .seat-tag {
    font-size: 0.48rem;
    padding: 0.04rem 0.18rem;
  }

  .result-pill {
    width: clamp(54px, 13vw, 66px);
    min-height: 22px;
    font-size: 0.5rem;
    padding: 0.08rem 0.12rem;
    border-radius: 7px;
  }

  .token {
    min-width: 42px;
    max-width: 76px;
    height: 22px;
    font-size: 0.55rem;
    padding: 0 0.28rem;
  }

  .start-overlay-text {
    font-size: clamp(2.15rem, 10.2vw, 3.8rem);
  }
}
