:root {
  color-scheme: light;
  --paper: #f6eedf;
  --ink: #453025;
  --line: #b3a089;
  --cream: #fbf4e6;
  --start: #f9c29d;
  --again: #ced0af;
  --tm-selector-ui: Pretendard, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font: 16px/1.55 var(--tm-selector-ui);
}

header {
  width: min(1100px, calc(100% - 48px));
  margin: auto;
  padding: 14px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand {
  color: inherit;
  text-decoration: none;
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -.04em;
  min-height: 44px;
  display: flex;
  align-items: center;
}

main {
  width: min(1040px, calc(100% - 48px));
  margin: auto;
  padding: 6px 0 36px;
}

h1, h2, h3, p, figure { margin-top: 0; }
h1 { font: 700 clamp(34px, 4.5vw, 46px)/1.15 Gaegu, Pretendard, sans-serif; margin-bottom: 8px; text-wrap: balance; }
h2 { font: 700 28px/1.2 Gaegu, Pretendard, sans-serif; margin-bottom: 10px; }
h1, h2 { font-family: Gaegu, Pretendard, sans-serif; font-weight: 700; overflow-wrap: anywhere; text-wrap: balance; }
button, input, textarea, select { font-family: var(--tm-selector-ui) !important; }

#intro { max-width: 68ch; margin-bottom: 10px; }
.notice { min-height: 1.55em; font-size: 14px; margin-bottom: 12px; }
.notice:empty, .error:empty { display: none; }

/* Minimal top space in active phases (ready / revealing / result) */
body:not([data-phase="setup"]) header { padding: 8px 0; }
body:not([data-phase="setup"]) main { padding: 2px 0 28px; }
body:not([data-phase="setup"]) #title {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
body:not([data-phase="setup"]) #intro { display: none; }
body:not([data-phase="setup"]) .notice { margin-bottom: 8px; min-height: 0; }

/* Setup Layout & Mode Tabs */
.setup-layout { display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.6fr); gap: 32px; align-items: start; }
.setup-layout > form { min-width: 0; grid-column: 2; grid-row: 1; }
.setup-art { margin: 34px 0 0; grid-column: 1; grid-row: 1; }
.setup-art img { display: block; width: 100%; height: auto; aspect-ratio: 1; object-fit: contain; border-radius: 14px; }

.mode-tabs {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  background: #efe3ce;
  border: 1.5px solid #c5b197;
  border-radius: 14px;
  margin-bottom: 16px;
  width: min(420px, 100%);
}
body[data-tm-game-ui="ladder-role"] .mode-tab {
  min-height: 42px !important;
  padding: 7px 12px !important;
  border-radius: 10px !important;
  border: 1.5px solid transparent !important;
  background: transparent !important;
  color: #5c4330 !important;
  font-size: 15px !important;
  font-weight: 700;
  box-shadow: none !important;
}
body[data-tm-game-ui="ladder-role"] .mode-tab.is-active {
  background: #fffaf0 !important;
  border-color: var(--ink) !important;
  color: var(--ink) !important;
}

label { display: block; font-weight: 700; margin-bottom: 6px; }
.count-setting { max-width: 450px; margin-bottom: 20px; }
.stepper { display: flex; align-items: center; gap: 6px; width: 230px; max-width: 100%; }
.winner-stepper { width: 168px; }
.stepper input { width: 70px; min-width: 0; flex: 1; min-height: 46px; text-align: center; background: #fffbf3; border: 1.5px solid var(--line); border-radius: 8px; color: inherit; font: inherit; }
.count-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
body[data-tm-game-ui="ladder-role"] button.count-preset {
  min-height: 34px !important;
  min-width: 44px;
  padding: 4px 10px !important;
  border-radius: 999px !important;
  border: 1.5px solid #c5b197 !important;
  background: #fffaf0 !important;
  color: var(--ink) !important;
  font-size: 13px !important;
  font-weight: 700;
  box-shadow: none !important;
}
body[data-tm-game-ui="ladder-role"] button.count-preset.is-active {
  background: #f9c29d !important;
  border-color: var(--ink) !important;
}
.input-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.input-lists > div { min-width: 0; }
.input-lists:not(.is-winners-mode) > div { display: flex; flex-direction: column; }
.input-lists:not(.is-winners-mode) > div:first-child > textarea, .input-lists:not(.is-winners-mode) > div:last-child > :first-child { margin-block-start: auto; }
textarea { width: 100%; min-height: 160px; resize: vertical; color: inherit; background: #fffbf3; border: 1.5px solid var(--line); border-radius: 8px; padding: 10px; font: inherit; line-height: 1.6; caret-color: var(--ink); }

.winner-settings {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #fff8eb;
  border: 1.5px solid #d2bfa7;
  border-radius: 12px;
  padding: 14px;
}
.winner-field label { margin-bottom: 6px; }
.winner-field input[type="text"] {
  width: 100%;
  min-height: 46px;
  padding: 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  font: inherit;
}
.winner-field .hint { margin: 6px 0 0; font-size: 13px; }

.hint { font-size: 14px; color: #604a3b; margin: 7px 0 12px; }
.list-count { font-variant-numeric: tabular-nums; font-size: 15px; margin-bottom: 8px; }
.error { color: #8a2f25; min-height: 1.5em; margin: 8px 0; font-size: 15px; overflow-wrap: anywhere; }

button, .home-button {
  border: 1.5px solid var(--ink);
  border-radius: 9px 12px 10px 8px;
  background: #f8eacf;
  color: inherit;
  font: inherit;
  padding: 9px 15px;
  min-height: 46px;
  min-width: 46px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  line-height: 1.4;
  cursor: pointer;
  text-decoration: none;
}
button.primary { background: var(--start); font-weight: 700; }
button.secondary { background: var(--again); }
button:hover, .home-button:hover { filter: brightness(.97); }
button:disabled { opacity: .6; cursor: default; }
button[hidden] { display: none; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0 0; }
.actions .primary { min-width: 150px; }

.preview { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); }
.preview:empty { display: none; }
.preview h2 { font-size: 25px; }
.preview-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.preview-lists ol { margin: 0; padding-left: 25px; min-width: 0; }
.preview-lists li { overflow-wrap: anywhere; margin-bottom: 3px; }

/* Compact Topbar */
.ladder-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.status-pill {
  margin: 0;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1.5px solid #c5b197;
  background: #fffaf0;
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.status-pill:focus-visible { outline: 3px solid #6c6042; outline-offset: 4px; }
.completed-now { animation: complete .4s cubic-bezier(.16, 1, .3, 1); }
@keyframes complete { from { transform: translateY(4px); } to { transform: translateY(0); } }
.topbar-actions { margin: 0; gap: 8px; }
.topbar-actions button { min-height: 44px; padding: 8px 14px; }
.topbar-actions .primary { min-width: 120px; }
.ladder-result-share .tm-result-share { margin: 0; }
.ladder-result-share .tm-result-share [role="status"]:empty { position: absolute; }

/* Wooden Ladder Board */
.ladder-section { min-width: 0; }
.ladder-scroll {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-color: #9e8974 #f6eedf;
  border: 1.5px solid #c2ab8e;
  border-radius: 14px;
  background: #fffaf2;
  padding: 12px 10px;
}
.ladder-content {
  width: 100%;
  min-width: var(--board-min-width);
  margin-inline: auto;
}
.ladder-board-wrap { position: relative; }
.ladder { display: block; width: 100%; height: auto; overflow: visible; }

/* Top participant mascot pills & bottom cards */
.rail-labels {
  display: grid;
  grid-template-columns: repeat(var(--tracks), minmax(0, 1fr));
  gap: 8px;
  padding: 0 2px;
}
.rail-label {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.3;
  text-align: center;
}
body[data-tm-game-ui="ladder-role"] .person-node {
  border: 1.5px solid #d2bfa7 !important;
  border-radius: 12px !important;
  background: #fffaf0 !important;
  color: var(--ink) !important;
  padding: 5px 4px !important;
  min-height: 50px !important;
  min-width: 0;
  font-size: 13px !important;
  font-weight: 700;
  line-height: 1.25 !important;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  white-space: nowrap;
  cursor: default;
  box-shadow: none !important;
  transition: border-color .18s ease, background .18s ease, transform .18s ease;
}
body[data-tm-game-ui="ladder-role"] button.person-node { cursor: pointer; }
body[data-tm-game-ui="ladder-role"] button.person-node:hover {
  border-color: var(--node-color, var(--ink)) !important;
  background: #fff5e3 !important;
}
.node-avatar-wrap {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.node-avatar {
  width: 24px;
  height: 24px;
  object-fit: contain;
  display: block;
}
.node-name-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  max-width: 100%;
  min-width: 0;
}
.node-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--node-color, #e07a5f);
  flex: none;
  opacity: .35;
  transition: opacity .18s ease;
}
.person-node.is-running .node-dot,
.person-node.is-done .node-dot { opacity: 1; }
body[data-tm-game-ui="ladder-role"] .person-node.is-running {
  border-color: var(--node-color) !important;
  border-width: 2px !important;
  background: #fff3dd !important;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--node-color) 26%, transparent) !important;
  transform: translateY(-1px);
}
body[data-tm-game-ui="ladder-role"] .person-node.is-done {
  border-color: color-mix(in srgb, var(--node-color) 55%, #c5b197) !important;
}
.node-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.role-card {
  background: #f3e4ca;
  border: 1.5px solid #cbb598;
  border-radius: 10px;
  padding: 6px 5px;
  min-height: 42px;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .2s ease, background .2s ease, transform .2s ease;
}
.role-card.is-landed {
  border-color: var(--node-color);
  border-width: 2px;
  background: color-mix(in srgb, var(--node-color) 14%, #fffaf0);
  animation: rolePop .35s cubic-bezier(.16, 1, .3, 1);
}
.role-card.is-winner-slot {
  background: #fdebd2;
  border-color: #d9833b;
  color: #7a2e0e;
}
.role-card.is-winner-slot.is-landed {
  background: #fde0bb;
  border-color: #d96b27;
  box-shadow: 0 2px 10px #d96b272e;
}
.role-card.is-pass-slot {
  background: #f7efe2;
  border-color: #d7c7b2;
  color: #7a6452;
  font-weight: 500;
}
@keyframes rolePop {
  0% { transform: scale(.95); }
  55% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
.role-card.is-shuffling {
  animation: slotShuffle .24s cubic-bezier(.16, 1, .3, 1);
}
@keyframes slotShuffle {
  0% { transform: scale(.92) rotate(-2deg); }
  50% { transform: scale(1.06) rotate(1.5deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* Hand-Drawn Honey-Birch Wood SVG Styles */
.wood-shadow { fill: #3b2a1e; opacity: .13; }
.wood-rail { fill: url(#wood-rail-grad); stroke: #3b2a1e; stroke-width: 1.6; stroke-linejoin: round; }
.wood-rung { fill: url(#wood-rung-grad); stroke: #3b2a1e; stroke-width: 1.6; stroke-linejoin: round; transition: filter .15s ease; }
.wood-highlight { stroke: #fff5e1; stroke-width: 1.6; stroke-linecap: round; opacity: .72; }
.wood-hatch { stroke: #8f5d32; stroke-width: 1; stroke-linecap: round; opacity: .25; }
.wood-peg { fill: #c98548; stroke: #3b2a1e; stroke-width: 1.1; }

.rung-group.rung-hit .wood-rung {
  filter: drop-shadow(0 0 7px #f5b041cc) brightness(1.08);
  stroke: #9a5b13;
  stroke-width: 2;
}
.rung-group.rung-hit .wood-peg { fill: #f5b041; }

/* Mystery Curtain in Ready Phase (higher specificity than game-ui-system.css) */
body[data-tm-game-ui="ladder-role"] button.mystery-curtain {
  position: absolute;
  inset: 14% 10px;
  width: calc(100% - 20px);
  min-height: 0 !important;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 14px !important;
  border: 1.5px dashed #9b7e5c !important;
  background-color: #f7ebd4 !important;
  background-image: repeating-linear-gradient(135deg, #f7ebd4 0 12px, #f2e2c4 12px 24px) !important;
  box-shadow: inset 0 0 0 2px #fffaf099 !important;
  cursor: pointer;
  padding: 10px !important;
  font-size: 13px !important;
}
body[data-tm-game-ui="ladder-role"] button.mystery-curtain:hover {
  filter: brightness(.98);
  border-color: var(--ink) !important;
}
.curtain-badge {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #453025;
  color: #fbf4e6;
  font: 700 22px/1 Gaegu, Pretendard, sans-serif;
  display: grid;
  place-items: center;
}
.curtain-text {
  font-size: 13px;
  font-weight: 700;
  color: #5c4330;
  background: #fffaf0e0;
  padding: 4px 12px;
  border-radius: 999px;
  text-align: center;
}

/* Traces & Mascot Runner */
.trace-glow { fill: none; stroke-width: 11; stroke-linecap: round; stroke-linejoin: round; opacity: .28; }
.trace-active { fill: none; stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; }
.runner-halo { fill: var(--runner-color, #e07a5f); opacity: .28; animation: runnerPulse .7s ease-in-out infinite alternate; }
.landing-ripple { fill: none; stroke-width: 2.5; opacity: 0; }
.landing-ripple.rippling { animation: rippleOut .48s ease-out forwards; }
.burst-star { fill: #f59e0b; stroke: #7a2e0e; stroke-width: 1; }
.winner-star-burst.bursting { animation: starBurst .55s cubic-bezier(.16, 1, .3, 1) forwards; }
@keyframes runnerPulse { from { r: 14; opacity: .24; } to { r: 18; opacity: .4; } }
@keyframes rippleOut { 0% { r: 6; opacity: .85; stroke-width: 3; } 100% { r: 22; opacity: 0; stroke-width: 1; } }
@keyframes starBurst { 0% { opacity: 0; } 30% { opacity: 1; } 100% { opacity: 0; } }

/* Mapping Table & Winner Summary */
.mapping-section { margin-top: 18px; min-width: 0; }
.mapping-head h2 { margin-bottom: 4px; font-size: 24px; }
.mapping-head .hint { margin: 0 0 10px; font-size: 13px; }
.winner-summary-pill {
  background: #fde6cc;
  border: 1.5px solid #d96b27;
  border-radius: 12px;
  padding: 8px 12px;
  font-weight: 700;
  font-size: 14px;
  color: #7a2e0e;
  margin: 0 0 10px;
}
table { border-collapse: collapse; width: 100%; table-layout: fixed; }
th, td { text-align: left; border-bottom: 1px solid var(--line); padding: 8px 6px; vertical-align: middle; overflow-wrap: anywhere; }
thead th { font-size: 13px; font-weight: 700; }
thead th:first-child { width: 36%; }
thead th:nth-child(2) { width: 34%; }
thead th:last-child { width: 30%; }
tbody th { font-weight: 700; font-size: 14px; }
tbody td:nth-child(2) { font: 700 22px/1.25 Gaegu, Pretendard, sans-serif; }
tr[data-visible="false"] .row-role,
.wide-result-card[data-visible="false"] .row-role {
  font: 600 15px/1.35 var(--tm-selector-ui);
  color: #7a6655;
}
.row-person { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.row-avatar { width: 20px; height: 20px; object-fit: contain; flex: none; }
.row-name { min-width: 0; overflow-wrap: anywhere; }
.winner-badge-cell {
  display: inline-block;
  background: #fde6cc;
  border: 1.5px solid #d96b27;
  border-radius: 999px;
  padding: 2px 10px;
  font: 700 15px/1.35 var(--tm-selector-ui);
  color: #7a2e0e;
}
.is-pass-row .row-role {
  color: #8c7764;
  font: 500 15px/1.35 var(--tm-selector-ui);
}
.path-button { padding: 6px 8px; width: 100%; font-size: 13px; min-height: 40px; }

.privacy { margin-top: 24px; max-width: 78ch; color: #604a3b; font-size: 13px; }
a { color: inherit; text-underline-offset: 4px; }
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, .ladder-scroll:focus-visible { outline: 3px solid #6c6042; outline-offset: 4px; }
::selection { background: #d8d8b9; color: var(--ink); }

dialog { max-width: min(460px, calc(100% - 32px)); max-height: 85vh; overflow: auto; color: var(--ink); background: #fff8eb; border: 2px solid var(--ink); border-radius: 14px; padding: 24px; }
dialog::backdrop { background: #45302555; }
#confirm-body { white-space: pre-line; overflow-wrap: anywhere; }
dialog form { display: flex; flex-wrap: wrap; gap: 12px; }
dialog form button { flex: 1; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

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

/* Desktop 2-column layout (>= 960px) for 2-8 people; stacked wide stage for 9-30 people */
@media (min-width: 960px) {
  body[data-tm-selector-ui] header,
  body[data-tm-selector-ui] main {
    width: min(1280px, calc(100% - 48px));
  }
  body[data-tm-selector-ui][data-wide-ladder="true"] header,
  body[data-tm-selector-ui][data-wide-ladder="true"] main {
    width: min(1480px, 96vw) !important;
    max-width: min(1480px, 96vw) !important;
  }
  .setup-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); align-items: start; gap: clamp(24px, 4vw, 52px); }
  .setup-art { margin: 8px 0 0; max-width: 440px; justify-self: center; align-self: start; }

  body:not([data-wide-ladder="true"]) #app:has(.mapping-section) {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(260px, 0.85fr);
    align-items: start;
    gap: 12px 24px;
  }
  body:not([data-wide-ladder="true"]) #app:has(.mapping-section) .ladder-topbar { grid-column: 1 / -1; margin-bottom: 0; }
  body:not([data-wide-ladder="true"]) #app:has(.mapping-section) .ladder-section { grid-column: 1; }
  body:not([data-wide-ladder="true"]) #app:has(.mapping-section) .mapping-section { grid-column: 2; margin-top: 0; }

  body[data-wide-ladder="true"] .ladder-scroll[data-wide-ladder="true"] {
    overflow-x: hidden;
  }
}

/* Density tiers for 9-30 columns */
.ladder-scroll[data-density="medium"] .rail-labels { gap: 5px; }
body[data-tm-game-ui="ladder-role"] .ladder-scroll[data-density="medium"] .person-node {
  font-size: 12px !important;
  padding: 4px 2px !important;
}
.ladder-scroll[data-density="medium"] .role-card {
  font-size: 12px;
  padding: 5px 2px;
}

.ladder-scroll[data-density="dense"] .rail-labels { gap: 3px; padding: 0; }
body[data-tm-game-ui="ladder-role"] .ladder-scroll[data-density="dense"] .person-node {
  font-size: 11px !important;
  padding: 3px 2px !important;
  min-height: 44px !important;
  border-radius: 9px !important;
}
.ladder-scroll[data-density="dense"] .node-avatar-wrap,
.ladder-scroll[data-density="dense"] .node-avatar { width: 20px; height: 20px; }
.ladder-scroll[data-density="dense"] .node-dot { width: 5px; height: 5px; }
.ladder-scroll[data-density="dense"] .role-card {
  font-size: 11px;
  padding: 4px 2px;
  min-height: 34px;
  border-radius: 8px;
}

.ladder-scroll[data-density="ultra"] { padding: 8px 6px; }
.ladder-scroll[data-density="ultra"] .rail-labels { gap: 2px; padding: 0; }
body[data-tm-game-ui="ladder-role"] .ladder-scroll[data-density="ultra"] .person-node {
  font-size: 10.5px !important;
  letter-spacing: -0.04em;
  padding: 3px 1px !important;
  min-height: 40px !important;
  border-radius: 8px !important;
}
.ladder-scroll[data-density="ultra"] .node-avatar-wrap,
.ladder-scroll[data-density="ultra"] .node-avatar { width: 18px; height: 18px; }
.ladder-scroll[data-density="ultra"] .node-dot { display: none; }
.ladder-scroll[data-density="ultra"] .role-card {
  font-size: 10.5px;
  letter-spacing: -0.04em;
  padding: 3px 1px;
  min-height: 30px;
  border-radius: 7px;
}

/* Wide multi-column result grid */
.wide-results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
}
.wide-result-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #fffaf0;
  border: 1.5px solid #d2bfa7;
  border-radius: 12px;
  padding: 7px 10px;
  min-width: 0;
}
.wide-result-card.is-winner-row {
  background: #fff3e3;
  border-color: #d96b27;
}
.wide-result-card .row-person {
  flex: 1 1 auto;
  min-width: 0;
}
.wide-result-card .row-role {
  flex: 0 1 auto;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}
body[data-tm-game-ui="ladder-role"] .wide-result-card .path-button {
  width: auto !important;
  min-width: 64px;
  flex: none;
  min-height: 36px !important;
  padding: 4px 10px !important;
  font-size: 12px !important;
}

/* Mobile Layout (<= 700px) */
@media (max-width: 700px) {
  header, main { width: calc(100% - 28px); }
  header { padding: 8px 0; }
  body:not([data-phase="setup"]) header { padding: 6px 0; }
  main { padding-top: 2px; }
  #intro { display: none; }
  .setup-layout { grid-template-columns: 1fr; gap: 0; }
  .setup-layout > form { grid-column: auto; grid-row: auto; }
  .setup-art { display: none; }
  .count-setting { margin-bottom: 10px; }
  .input-lists { gap: 12px; }
  .input-lists.is-winners-mode { grid-template-columns: 1fr; }
  textarea { min-height: 128px; font-size: 16px; }
  .preview-lists { gap: 12px; }
  .actions button, .home-button { flex: 1; }

  .ladder-topbar {
    gap: 6px;
    margin-bottom: 8px;
  }
  .status-pill {
    width: 100%;
    text-align: center;
    font-size: 13px;
    padding: 5px 10px;
  }
  .topbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .topbar-actions:has(> button:nth-child(3)) {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .topbar-actions button {
    min-width: 0;
    width: 100%;
    min-height: 44px;
    padding: 6px 6px;
    font-size: 14px;
    white-space: nowrap;
  }
  .topbar-actions:has(> button:nth-child(3)) button {
    padding: 6px 4px;
    font-size: 13px !important;
  }

  .ladder-scroll { padding: 8px 4px; }
  .rail-labels { gap: 6px; }
  body[data-tm-game-ui="ladder-role"] .person-node {
    font-size: 12px !important;
    padding: 4px 2px !important;
    min-height: 46px !important;
    gap: 2px;
    white-space: nowrap;
    word-break: keep-all;
  }
  .node-avatar-wrap, .node-avatar { width: 20px; height: 20px; }
  .node-dot { width: 6px; height: 6px; }
  .role-card {
    font-size: 12px;
    padding: 5px 2px;
    min-height: 38px;
  }
  .mapping-section { margin-top: 14px; }
  th, td { padding: 7px 4px; }
  tbody td:nth-child(2) { font-size: 20px; }
  .path-button { padding: 6px 4px; font-size: 12px; }
}

.node-number { display: none; }
@media (max-width: 700px) {
  .ladder-scroll .ladder-content {
    display: grid;
    grid-template-columns: minmax(0, 28%) minmax(0, 1fr) minmax(0, 23%);
    grid-template-rows: repeat(var(--tracks), minmax(46px, 1fr));
    min-width: 0;
  }
  .ladder-scroll .ladder-content > * { grid-row: 1 / -1; }
  .ladder-content .people-labels { grid-column: 1; }
  .ladder-content .ladder-board-wrap { grid-column: 2; }
  .ladder-content .role-labels { grid-column: 3; }
  .ladder-scroll .ladder-content .rail-labels {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: subgrid;
    gap: 0;
    align-items: center;
    padding: 0;
  }
  body[data-tm-game-ui="ladder-role"] .ladder-content .person-node {
    min-height: 44px !important;
    flex-direction: row;
    justify-content: start;
    padding: 3px !important;
    gap: 3px;
    white-space: normal;
    text-align: start;
  }
  .ladder-content .node-avatar-wrap, .ladder-content .node-dot { display: none; }
  .ladder-content .node-number {
    display: inline-grid;
    place-items: center;
    min-width: 1.5em;
    height: 1.5em;
    border-radius: 50%;
    background: #f4e7d1;
    font-size: 11px;
  }
  .ladder-content .node-name-row { display: block; }
  .ladder-content .node-text, .ladder-content .role-card {
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: normal;
  }
  .ladder-content .node-text { overflow: visible; }
  .ladder-content .ladder {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }
  body[data-tm-game-ui="ladder-role"] .ladder-content button.mystery-curtain {
    inset: 3px 13%;
    width: auto;
    padding: 4px !important;
  }
  .ladder-content .curtain-text { padding: 4px; }
}

/* The projected result leads with the assignments while keeping paths below it. */
@media (min-width: 960px) {
  body[data-tm-game-ui="ladder-role"][data-tm-present="1"][data-phase="result"] #app {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }
  body[data-tm-game-ui="ladder-role"][data-tm-present="1"][data-phase="result"] #app > .ladder-topbar {
    grid-area: 1 / 1;
    margin-bottom: 0;
  }
  body[data-tm-game-ui="ladder-role"][data-tm-present="1"][data-phase="result"] #app > .mapping-section {
    grid-area: 2 / 1;
    margin-top: 0;
  }
  body[data-tm-game-ui="ladder-role"][data-tm-present="1"][data-phase="result"] #app > .ladder-section {
    grid-area: 3 / 1;
  }
  body[data-tm-game-ui="ladder-role"][data-tm-present="1"][data-phase="result"] .ladder-section :is(.node-text, .role-card) {
    overflow-wrap: anywhere;
    text-overflow: clip;
    white-space: normal;
  }
  body[data-tm-game-ui="ladder-role"][data-tm-present="1"][data-phase="result"] .mapping-head h2 {
    font-size: 30px;
  }
  body[data-tm-game-ui="ladder-role"][data-tm-present="1"][data-phase="result"] .mapping-head .hint {
    margin-bottom: 6px;
  }
  body[data-tm-game-ui="ladder-role"][data-tm-present="1"][data-phase="result"] #results :is(.row-name, .row-role, .winner-badge-cell) {
    font: 700 19px/1.3 var(--tm-selector-ui);
    white-space: normal;
    overflow-wrap: anywhere;
  }
  body[data-tm-game-ui="ladder-role"][data-tm-present="1"][data-phase="result"] #results td:last-child {
    text-align: right;
  }
  body[data-tm-game-ui="ladder-role"][data-tm-present="1"][data-phase="result"] #results .path-button {
    width: auto;
    min-width: 68px;
  }
  body[data-tm-game-ui="ladder-role"][data-tm-present="1"][data-phase="result"] .wide-results-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  body[data-tm-game-ui="ladder-role"][data-tm-present="1"][data-phase="result"] .wide-result-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    min-height: 58px;
  }
}
