/* Existing tools hierarchy: Gaegu,Pretendard,sans-serif headings/results, system UI body and controls. */

:root {
  color-scheme: light;
  --paper:#f6eedf;
  --ink:#453025;
  --line:#8a7461;
  --start:#f9c29d;
  --again:#ced0af;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font:
    16px/1.55 Pretendard,sans-serif;
}
header {
  max-width: 1100px;
  margin: auto;
  padding: 20px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.brand {
  font-weight: 700;
  font-size: 25px;
  letter-spacing: -.04em;
  text-decoration: none;
  color: inherit;
  display: flex;
  align-items: center;
  min-height: 44px;
}
main {
  max-width: 1040px;
  margin: auto;
  padding: 8px 24px 48px;
}
h1,
h2,
h3,
p {
  margin-top: 0;
}
h1 {
  font: 700 clamp(34px, 5vw, 48px)/1.15 Gaegu,Pretendard,sans-serif;
  margin-bottom: 8px;
  text-wrap: balance;
}
h2 {
  font: 700 33px/1.25 Gaegu,Pretendard,sans-serif;
  margin-bottom: 10px;
}
h3 {
  font-size: 17px;
  margin-bottom: 12px;
}
.intro {
  margin-bottom: 12px;
}
.notice {
  min-height: 1.6em;
  margin-bottom: 14px;
  font-size: 15px;
  max-width: 70ch;
}
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, .9fr);
  gap: 36px;
  align-items: start;
}
.stage {
  position: relative;
  min-height: 310px;
  background: #fbf4e6;
  border: 1.5px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding: 16px 20px 20px;
}
.scene {
  display: block;
  width: min(100%, 280px);
  height: auto;
  aspect-ratio: 1;
  object-fit: contain;
  margin: 0 auto 14px;
  border-radius: 16px;
  mix-blend-mode: multiply;
  animation: tm-mascot-float 3.6s ease-in-out infinite;
  will-change: transform;
}
@keyframes tm-mascot-float {
  0%, 100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-6px) rotate(1deg);
  }
}
.letter {
  position: relative;
  background: #fffaf0;
  border: 2px solid var(--ink);
  border-radius: 5px 8px 4px 7px;
  width: min(100%, 350px);
  min-height: 120px;
  text-align: center;
  padding: 26px 18px 20px;
  overflow-wrap: anywhere;
  box-shadow: 0 8px 18px #45302512;
}
.letter-flap {
  pointer-events: none;
  position: absolute;
  top: -1px;
  left: calc(50% - 12px);
  border: 12px solid transparent;
  border-top-color: #bcbe99;
}
.letter-open {
  padding-top: 38px;
}
.letter-open .letter-flap {
  top: -15px;
  left: 0;
  right: 0;
  height: 15px;
  border: 0;
  background: #c4c4a2;
  clip-path: polygon(0 100%, 38% 4%, 62% 4%, 100% 100%);
  transform-origin: bottom center;
}
.letter-postmark {
  position: absolute;
  top: 7px;
  right: 9px;
  width: 33px;
  height: 24px;
  border: 1px solid #865f54;
  border-radius: 50%;
  color: #865f54;
  transform: rotate(-12deg);
  pointer-events: none;
}
.letter-postmark::before,
.letter-postmark::after {
  content: "";
  position: absolute;
  left: 6px;
  right: 6px;
  height: 4px;
  border-block: 1px solid currentColor;
}
.letter-postmark::before { top: 6px; }
.letter-postmark::after { bottom: 5px; }
.letter-arrived .letter-flap {
  animation: envelope-open .28s cubic-bezier(.2, .6, .3, 1) both;
}
.letter-arrived .letter-postmark {
  animation: postmark-press .44s ease-out both;
}
@keyframes envelope-open {
  from { transform: perspective(180px) rotateX(-92deg); }
  to { transform: none; }
}
@keyframes postmark-press {
  0%, 35% { opacity: 0; transform: translateY(-4px) rotate(-18deg) scale(1.2); }
  68% { opacity: 1; transform: rotate(-12deg) scale(.92); }
  100% { opacity: 1; transform: rotate(-12deg); }
}
.letter small {
  display: block;
  font-size: 14px;
  margin-bottom: 4px;
}
.winner {
  font: 700 clamp(28px, 5vw, 40px)/1.25 Gaegu,Pretendard,sans-serif;
  margin: 0;
  overflow-wrap: anywhere;
  max-width: 100%;
}
.stage-caption {
  position: relative;
  text-align: center;
  font-size: 15px;
  margin: 12px 0 0;
}
.delivering .letter {
  animation: deliver 1.1s cubic-bezier(.16, 1, .3, 1) both;
}
@keyframes deliver {
  0% {
    transform: translate(70px, -65px) rotate(9deg);
  }
  55% {
    transform: translate(-10px, -15px) rotate(-3deg);
  }
  100% {
    transform: none;
  }
}
.setup-panel {
  min-width: 0;
}
.field-label {
  font-weight: 700;
  display: block;
  margin-bottom: 5px;
}
.hint {
  font-size: 14px;
  margin: 5px 0 12px;
  color: #604a3b;
}
textarea,
select {
  font: inherit;
  color: inherit;
  background: #fffbf3;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  width: 100%;
  min-height: 46px;
}
textarea {
  resize: vertical;
  min-height: 165px;
  line-height: 1.5;
  caret-color: var(--ink);
}
.purpose {
  margin: 16px 0;
}
button,
.home-button {
  font: inherit;
  color: inherit;
  border: 1.5px solid var(--ink);
  border-radius: 9px 12px 10px 8px;
  min-height: 46px;
  min-width: 46px;
  padding: 9px 17px;
  background: #f8eacf;
  cursor: pointer;
  line-height: 1.4;
  text-decoration: none;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}
button:hover,
.home-button:hover {
  filter: brightness(.97);
}
button:disabled {
  opacity: .6;
  cursor: default;
}
button.primary {
  background: var(--start);
  font-weight: 700;
}
button.secondary {
  background: var(--again);
}
.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.actions .primary {
  flex: 1;
}
.count {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  margin-bottom: 12px;
}
.rosters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 28px;
  border-top: 1px solid #b8a28d;
  padding-top: 20px;
}
.rosters > section {
  min-width: 0;
}
.rosters ol {
  margin: 0;
  padding-left: 26px;
}
.rosters li {
  overflow-wrap: anywhere;
  margin-bottom: 4px;
}
.empty {
  font-size: 15px;
  margin-bottom: 0;
}
.privacy {
  font-size: 13px;
  max-width: 75ch;
  margin: 28px 0 0;
  color: #604a3b;
}
.error {
  color: #8a2f25;
  min-height: 1.5em;
  font-size: 15px;
  margin: 8px 0;
}
.list-preview {
  font-size: 14px;
  margin-top: 12px;
  max-height: 180px;
  overflow: auto;
  border-top: 1px solid #b8a28d;
  padding-top: 10px;
}
.list-preview ol {
  padding-left: 25px;
  margin: 5px 0;
}
.list-preview li {
  overflow-wrap: anywhere;
}
.review-hint {
  margin: 0;
  font-size: 14px;
}
a {
  color: inherit;
  text-underline-offset: 4px;
}
button:focus-visible,
a:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid #6c6042;
  outline-offset: 4px;
}
::selection {
  background: #d8d8b9;
  color: var(--ink);
}
dialog {
  background: #fff8eb;
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 15px;
  max-width: min(440px, calc(100% - 32px));
  padding: 25px;
}
dialog::backdrop {
  background: #45302555;
}
dialog form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
dialog form button {
  flex: 1;
}
.result-heading:focus {
  outline: none;
}
.result-heading:focus-visible {
  outline: 3px solid #6c6042;
  outline-offset: 4px;
}
.complete {
  font-size: 17px;
  margin-bottom: 14px;
}
@media (max-width: 700px) {
  header {
    padding: 14px 18px;
  }
  main {
    padding: 4px 18px 34px;
  }
  .layout {
    grid-template-columns: 1fr;
    gap: 22px;
  }
  .stage {
    min-height: 240px;
    padding-top: 22px;
  }
  .scene {
    width: min(100%, 180px);
    margin-bottom: 12px;
  }
  .stage .letter {
    min-height: 103px;
    padding-top: 24px;
  }
  .stage .letter-open { padding-top: 38px; }
  .setup-layout .stage {
    display: none;
  }
  .rosters {
    gap: 14px;
    margin-top: 24px;
  }
  .winner {
    font-size: 34px;
  }
  .privacy {
    margin-top: 24px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *:before,
  *:after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
/* Empty-list recovery is hidden while any user-entered names are present. */
.actions button[hidden] {
  display: none;
}
.count-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.count-field { min-width: 0; margin: 0 0 14px; }
.count-field .field-label { min-height: 3em; }
.stepper { display: flex; gap: 4px; }
.stepper input { width: 62px; min-width: 0; flex: 1; min-height: 46px; text-align: center; font: inherit; color: inherit; background: #fffbf3; border: 1.5px solid var(--line); border-radius: 8px; }
.stepper button { min-width: 44px; padding-inline: 10px; }
.stepper input:focus-visible { outline: 3px solid #6c6042; outline-offset: 4px; }
.selected-people { margin: 12px 0 0; padding-left: 1.5em; text-align: left; font: 700 30px/1.3 Gaegu,Pretendard,sans-serif; }
.selected-people li { overflow-wrap: anywhere; margin-bottom: 5px; }
@media(max-width: 900px) { .count-controls { grid-template-columns: 1fr; gap: 0; } .count-field .field-label { min-height: 0; } }

/* Keep the names and settings together while shortening the path to Start. */
@media(max-height:650px) {
 .setup-layout .count-controls{grid-template-columns:1fr 1fr;gap:12px}
 .setup-layout .count-field{margin-bottom:4px}
 .setup-layout .count-field .field-label{min-height:3em;font-size:14px}
 .setup-layout .count-field .hint{font-size:12px;line-height:1.3;margin:4px 0}
 .setup-layout textarea{min-height:88px;height:88px}
 .setup-layout .purpose{margin:8px 0}
 .setup-layout .actions{margin-top:8px}
 .setup-layout #validation:empty{display:none}
 .setup-layout #names-hint{font-size:13px;line-height:1.35;margin:3px 0 6px}
 .round-hint{margin-top:12px}
}
@media(max-width:700px) and (max-height:650px) { header{padding:8px 18px} #intro{margin-bottom:8px;font-size:14px;line-height:1.35} h1{font-size:30px} .setup-layout .count-field .field-label{line-height:1.3;min-height:2.6em} .setup-layout .count-field .hint{min-height:3.9em} .setup-layout .purpose .field-label{margin-bottom:3px;font-size:14px} }

.selection-help{margin-top:12px}.selection-help summary{min-height:44px;padding-block:9px;cursor:pointer}
@media(max-height:650px){ .setup-layout #names-hint{margin-bottom:4px} header{padding-block:8px} #intro{margin-bottom:8px} }
@media(max-width:700px) and (max-height:650px){ #intro{display:none} }
@media(min-width:701px) and (max-height:650px){ .setup-layout .count-field .field-label{min-height:2.6em} }
.notice:empty{display:none}

/* Shared selector roles: existing Gaegu,Pretendard,sans-serif display, platform UI for reading and controls. */
:root{--tm-selector-ui:Pretendard,sans-serif}
body{font-family:var(--tm-selector-ui)}
button,input,textarea,select{font-family:var(--tm-selector-ui)!important}
h1,h2{font-family:Gaegu,Pretendard,sans-serif;font-weight:700;overflow-wrap:anywhere;text-wrap:balance}


.round-layout #validation:empty {
  display: none;
}
.round-layout .actions .primary {
  flex-basis: 100%;
}

@media (min-width: 740px) and (min-height: 600px) {
  .layout {
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    gap: clamp(22px, 3vw, 48px);
  }
  .count-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .count-field .field-label { min-height: 3em; }
}

@media (min-width: 1200px) {
  body[data-tm-game-ui="cloud-pick"][data-tm-selector-ui] :is(header, main) { max-width: 1480px; }
  body[data-tm-game-ui="cloud-pick"][data-tm-selector-ui] main { padding-bottom: 24px; }
  body[data-tm-game-ui="cloud-pick"][data-tm-selector-ui] .notice:empty { display: none; min-height: 0; margin: 0; }
  body[data-tm-game-ui="cloud-pick"][data-tm-selector-ui] .setup-layout { grid-template-columns: minmax(0, .95fr) minmax(0, 1fr); }
  body[data-tm-game-ui="cloud-pick"][data-tm-selector-ui] .stage { justify-content: center; }
  body[data-tm-game-ui="cloud-pick"][data-tm-selector-ui] .round-layout .stage { min-height: 190px; padding: 12px 18px 14px; }
  body[data-tm-game-ui="cloud-pick"][data-tm-selector-ui] .scene { width: min(100%, 170px); margin-bottom: 8px; }
  body[data-tm-game-ui="cloud-pick"] .setup-layout .scene { width: min(100%, 300px); margin-bottom: 14px; }
  body[data-tm-game-ui="cloud-pick"] .letter { width: min(100%, 440px); min-height: 92px; padding: 16px 18px 14px; }
  body[data-tm-game-ui="cloud-pick"] .letter-open { padding-top: 24px; }
  body[data-tm-game-ui="cloud-pick"] .round-layout .actions { margin-top: 12px; gap: 8px; }
  body[data-tm-game-ui="cloud-pick"] .round-layout .actions .primary { flex-basis: auto; }
  body[data-tm-game-ui="cloud-pick"] .round-layout .tm-result-share { margin: 10px 0 0; }
}
