* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* 요넥스 로고 컬러 */
  --blue: #0b50a1;
  --blue-deep: #083b7a;
  --blue-light: #2f74c8;
  --blue-tint: #e4eef8;
  --green: #1d9533;
  --green-deep: #157026;
  --green-light: #34b84a;
  --green-tint: #e4f3e7;
  --red: #ff7b7b;         /* 당첨 - 연한 레드 */
  --red-deep: #e85555;

  --surface: #ffffff;
  --text: #23303f;
  --muted: #6c7889;
  --line: #dde5ee;
  --line-strong: #c4d1e0;
}

body {
  font-family: "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 0 16px 60px;
  /* 프로그램 바깥 배경: 진한 곤색 */
  background: radial-gradient(1200px 700px at 50% -10%, #14315e 0%, #0a1b3a 55%, #071228 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

.app { width: 100%; max-width: 760px; }

.screen { display: none; animation: fadeUp .4s ease; }
.screen.active { display: block; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ===== Hero ===== */
.hero {
  text-align: center;
  color: #fff;
  border-radius: 0 0 28px 28px;
  padding: 44px 24px 36px;
  margin: 0 -16px 28px;
  background: linear-gradient(120deg, var(--blue) 0%, var(--blue-light) 45%, var(--green) 100%);
  background-size: 200% 200%;
  animation: heroFlow 12s ease infinite;
  box-shadow: 0 14px 34px rgba(11, 80, 161, .3);
}
@keyframes heroFlow {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
.hero-emoji { font-size: 50px; display: inline-block; animation: float 3.2s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }
.hero h1 { font-size: clamp(24px, 6vw, 33px); margin-top: 6px; letter-spacing: .5px; font-weight: 800; text-shadow: 0 2px 10px rgba(0,0,0,.15); }
.hero h1 .accent { color: #a9f0b5; }
.hero-sub { color: rgba(255,255,255,.92); margin-top: 10px; font-size: 14px; }
.hero-bar { height: 5px; width: 70px; margin: 16px auto 0; background: #a9f0b5; border-radius: 3px; }

/* ===== Card ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 26px;
  box-shadow: 0 12px 32px rgba(30, 70, 120, .1);
}

.field { margin-bottom: 24px; }
.field-label { display: block; font-weight: 800; margin-bottom: 12px; font-size: 15px; color: var(--blue); }
.field-hint { display: block; color: var(--muted); font-size: 13px; margin-top: 8px; }
.label-note { color: var(--green-deep); font-size: 12px; font-weight: 700; }

.field-center { display: flex; flex-direction: column; align-items: center; text-align: center; }

/* ===== Stepper ===== */
.stepper { display: flex; align-items: center; gap: 12px; }
.step-btn {
  width: 46px; height: 46px; border-radius: 14px; border: none;
  background: linear-gradient(135deg, var(--blue), var(--green));
  color: #fff; font-size: 24px; font-weight: 800;
  cursor: pointer; transition: transform .12s, box-shadow .2s, filter .2s;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 5px 14px rgba(11, 80, 161, .28);
}
.step-btn:hover { filter: brightness(1.08); transform: translateY(-2px); box-shadow: 0 8px 18px rgba(11, 80, 161, .38); }
.step-btn:active { transform: scale(.9); }
.count-input {
  width: 84px; height: 46px; text-align: center; font-size: 22px; font-weight: 800;
  border-radius: 14px; border: 2px solid var(--blue); background: #fff; color: var(--blue);
}
.count-input::-webkit-outer-spin-button,
.count-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ===== Inputs ===== */
.text-input {
  width: 100%; height: 46px; padding: 0 14px; font-size: 15px;
  border-radius: 14px; border: 2px solid var(--line); background: #fff; color: var(--text);
  transition: border-color .18s, box-shadow .18s;
}
.text-input::placeholder { color: #aeb9c7; }
.text-input:focus, .count-input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 4px rgba(29, 149, 51, .16); }

/* ===== Entry rows ===== */
.entry-list { display: flex; flex-direction: column; gap: 10px; }
.entry-row { display: flex; align-items: center; gap: 10px; }
.entry-index {
  width: 32px; height: 32px; flex: none; border-radius: 10px; font-size: 13px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--green));
  box-shadow: 0 4px 10px rgba(11, 80, 161, .28);
}
.entry-row .text-input { height: 44px; flex: 1; min-width: 0; }

/* 결과 빠른입력 버튼 (당첨 / 꽝) */
.preset-btn {
  flex: none; height: 44px; padding: 0 12px; border: none; border-radius: 12px;
  font-size: 13px; font-weight: 800; color: #fff; cursor: pointer; white-space: nowrap;
  transition: transform .1s, filter .2s;
}
.preset-btn:hover { filter: brightness(1.08); }
.preset-btn:active { transform: scale(.92); }
.preset-btn.win { background: linear-gradient(135deg, var(--red), var(--red-deep)); }
.preset-btn.lose { background: linear-gradient(135deg, #7c8a9c, #55606f); }

/* ===== Buttons ===== */
.primary-btn {
  width: 100%; height: 52px; border: none; border-radius: 16px; cursor: pointer;
  font-size: 16px; font-weight: 800; color: #fff; letter-spacing: .5px;
  background: linear-gradient(120deg, var(--blue), var(--green));
  background-size: 180% 180%;
  box-shadow: 0 10px 24px rgba(11, 80, 161, .32);
  transition: transform .12s, box-shadow .2s, background-position .4s;
}
.primary-btn:hover { background-position: 100% 50%; transform: translateY(-2px); box-shadow: 0 14px 28px rgba(11, 80, 161, .42); }
.primary-btn:active { transform: translateY(0) scale(.99); }
.primary-btn.green { background: linear-gradient(120deg, var(--green), var(--blue)); box-shadow: 0 10px 24px rgba(29, 149, 51, .32); }
.ghost-btn {
  border: 2px solid var(--line-strong); background: #fff; color: var(--blue);
  padding: 12px 16px; border-radius: 14px; cursor: pointer; font-weight: 700; font-size: 14px;
  transition: all .15s;
}
.ghost-btn:hover { background: linear-gradient(120deg, var(--blue), var(--green)); color: #fff; border-color: transparent; }

/* ===== Game ===== */
.game-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 22px 4px 18px; }
#gameTopic { font-size: 22px; color: #ffffff; font-weight: 800; }

.board-wrap {
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 16px;
  box-shadow: 0 12px 32px rgba(30, 70, 120, .1);
}
.labels { display: flex; justify-content: space-around; }
.labels .chip {
  flex: 1; margin: 0 3px; text-align: center; padding: 10px 4px; border-radius: 12px;
  font-weight: 800; font-size: 14px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: transform .14s, box-shadow .2s, background .3s;
}
.top-labels .chip { background: linear-gradient(135deg, var(--blue), var(--blue-deep)); color: #fff; box-shadow: 0 5px 12px rgba(11,80,161,.32); }
.top-labels .chip:hover { transform: translateY(-3px); box-shadow: 0 9px 18px rgba(11,80,161,.45); }
.top-labels .chip.picked { background: linear-gradient(135deg, var(--green-light), var(--green-deep)); box-shadow: 0 7px 16px rgba(29,149,51,.42); }
.bottom-labels .chip { background: var(--blue-tint); border: 2px dashed var(--line-strong); color: var(--muted); }
.bottom-labels .chip.revealed {
  color: #fff; border: none;
  background: linear-gradient(135deg, var(--green), var(--blue));
  box-shadow: 0 6px 15px rgba(29, 149, 51, .4);
  animation: pop .35s ease;
}
/* 당첨 결과는 연한 레드로 강조 */
.bottom-labels .chip.revealed.win {
  background: linear-gradient(135deg, var(--red), var(--red-deep));
  box-shadow: 0 6px 15px rgba(232, 85, 85, .45);
}
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.08); } 100% { transform: scale(1); opacity: 1; } }
#ladderCanvas { display: block; width: 100%; }

.game-controls { display: flex; gap: 12px; margin-top: 18px; }
.game-controls .primary-btn { height: 50px; font-size: 15px; }

.result-box { margin-top: 18px; display: flex; flex-direction: column; gap: 8px; }
.result-line {
  background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--green); border-radius: 12px;
  padding: 12px 14px; font-weight: 700; animation: fadeUp .3s ease; box-shadow: 0 4px 12px rgba(30,70,120,.08);
}
.result-line b { color: var(--blue); }
.result-line .arrow { color: var(--muted); margin: 0 8px; }
.result-line .dest { color: var(--green-deep); }
.result-line.win { border-left-color: var(--red-deep); }
.result-line.win .dest { color: var(--red-deep); }

/* ===== 기록 화면 ===== */
.history-open-btn { width: 100%; margin-top: 12px; text-align: center; }

/* 참가자 이름 검색 */
.history-search { position: relative; margin-bottom: 14px; }
.history-search .text-input { padding-right: 44px; }
.history-search-clear {
  display: none; position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border: none; border-radius: 9px; cursor: pointer;
  background: var(--blue-tint); color: var(--muted); font-size: 14px; font-weight: 800;
  align-items: center; justify-content: center; transition: filter .15s, background .2s, color .2s;
}
.history-search-clear:hover { background: linear-gradient(135deg, var(--blue), var(--green)); color: #fff; }

/* 필터 토글 (당첨자만 보기) */
.history-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filter-chip {
  border: 2px solid var(--line-strong); background: #fff; color: var(--blue);
  padding: 9px 15px; border-radius: 999px; cursor: pointer; font-weight: 800; font-size: 13px;
  transition: transform .1s, filter .2s, background .2s, color .2s, border-color .2s;
}
.filter-chip:hover { transform: translateY(-1px); filter: brightness(1.02); }
.filter-chip:active { transform: scale(.96); }
.filter-chip.active {
  color: #fff; border-color: transparent;
  background: linear-gradient(135deg, var(--red), var(--red-deep));
  box-shadow: 0 6px 15px rgba(232, 85, 85, .4);
}

.history-count { color: rgba(255,255,255,.85); font-size: 13px; font-weight: 700; margin: 0 2px 12px; }
.history-count:empty { display: none; }

.history-list { display: flex; flex-direction: column; gap: 12px; }
.history-empty {
  background: var(--surface); border: 1px dashed var(--line-strong); border-radius: 16px;
  padding: 30px 22px; text-align: center; color: var(--muted); font-weight: 700; line-height: 1.6;
}
.history-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px 18px; box-shadow: 0 8px 22px rgba(30, 70, 120, .1); animation: fadeUp .3s ease;
}
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.history-topic { font-weight: 800; color: var(--blue); font-size: 16px; }
.history-del {
  flex: none; width: 30px; height: 30px; border: none; border-radius: 9px; cursor: pointer;
  background: var(--blue-tint); color: var(--muted); font-size: 15px; font-weight: 800;
  transition: filter .15s, transform .1s, background .2s, color .2s;
}
.history-del:hover { background: linear-gradient(135deg, var(--red), var(--red-deep)); color: #fff; }
.history-del:active { transform: scale(.9); }
.history-meta { color: var(--muted); font-size: 13px; font-weight: 700; margin-top: 4px; }
.history-rows { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.history-row {
  display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px;
  background: var(--blue-tint); border-radius: 10px; padding: 8px 12px;
  border-left: 4px solid var(--green);
}
.history-row .hr-player { color: var(--blue); }
.history-row .arrow { color: var(--muted); }
.history-row .hr-result { color: var(--green-deep); }
.history-row.win { border-left-color: var(--red-deep); background: #fdeaea; }
.history-row.win .hr-result { color: var(--red-deep); }
/* 검색어와 일치하는 참가자 행 강조 */
.history-row.match { box-shadow: 0 0 0 2px var(--green-light); }
.history-row.match .hr-player { text-decoration: underline; }

.history-controls { margin-top: 18px; }
.history-controls .ghost-btn { width: 100%; }
.ghost-btn.danger { color: var(--red-deep); border-color: var(--red); }
.ghost-btn.danger:hover { background: linear-gradient(135deg, var(--red), var(--red-deep)); color: #fff; border-color: transparent; }

/* ===== 커스텀 팝업 ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: none; align-items: center; justify-content: center;
  background: rgba(7, 18, 40, .55); backdrop-filter: blur(3px);
  padding: 20px;
}
.modal-overlay.open { display: flex; animation: fadeUp .2s ease; }
.modal-box {
  width: 100%; max-width: 360px; background: #fff; border-radius: 20px;
  padding: 30px 26px 24px; text-align: center;
  box-shadow: 0 24px 60px rgba(7, 18, 40, .45);
  animation: modalPop .28s cubic-bezier(.2,.9,.3,1.3);
}
@keyframes modalPop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-icon {
  width: 58px; height: 58px; margin: 0 auto 16px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 28px;
  background: linear-gradient(135deg, var(--red), var(--red-deep));
  box-shadow: 0 8px 18px rgba(232, 85, 85, .4);
}
.modal-msg { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 22px; line-height: 1.5; }
.modal-box .primary-btn { height: 48px; }

/* ===== 반응형 ===== */

/* 태블릿 이하 */
@media (max-width: 640px) {
  .card { padding: 22px 18px; border-radius: 18px; }
  .board-wrap { padding: 12px; }
  .hero { padding: 36px 20px 30px; }
  .hero-emoji { font-size: 44px; }
  #gameTopic { font-size: 20px; }
  .game-header { padding: 18px 2px 16px; }
}

/* 모바일 */
@media (max-width: 480px) {
  body { padding: 0 12px 48px; }
  .hero { margin: 0 -12px 22px; border-radius: 0 0 22px 22px; }
  .card { padding: 20px 14px; }
  .field { margin-bottom: 20px; }

  /* 결과 입력행: 인덱스+입력+버튼이 좁은 폭에서도 정렬 */
  .entry-row { gap: 7px; }
  .entry-index { width: 26px; height: 26px; border-radius: 8px; font-size: 12px; }
  .preset-btn { padding: 0 9px; font-size: 12px; }
  .text-input { font-size: 14px; }

  /* 하단 컨트롤 버튼 세로 정렬 */
  .game-controls { flex-direction: column; }
  .game-controls .primary-btn,
  .game-controls .ghost-btn { width: 100%; }

  .labels .chip { font-size: 11px; padding: 8px 1px; margin: 0 2px; border-radius: 9px; }
  .result-line { font-size: 14px; padding: 11px 12px; }
}

/* 소형 모바일 */
@media (max-width: 360px) {
  .hero h1 { letter-spacing: 0; }
  .preset-btn { padding: 0 7px; font-size: 11px; }
  .step-btn { width: 42px; height: 42px; font-size: 22px; }
  .count-input { width: 74px; height: 42px; font-size: 20px; }
  .labels .chip { font-size: 10px; }
}
