* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

:root {
  --bg: #070a14;
  --panel: rgba(23, 28, 48, 0.72);
  --panel-border: rgba(120, 140, 220, 0.22);
  --text: #eef1ff;
  --muted: #9aa3c7;
  --accent: #6d8bff;
  --radius: 16px;
}

body {
  font-family: "Noto Sans KR", system-ui, -apple-system, "Malgun Gothic", sans-serif;
  background:
    radial-gradient(900px 500px at 12% -8%, rgba(91, 124, 250, 0.28), transparent 62%),
    radial-gradient(700px 480px at 96% 4%, rgba(57, 224, 200, 0.16), transparent 60%),
    radial-gradient(820px 600px at 50% 120%, rgba(160, 90, 255, 0.16), transparent 65%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* 화면 위쪽으로 사라지는 격자 무늬 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(circle at 50% 0%, #000 0%, transparent 75%);
  mask-image: radial-gradient(circle at 50% 0%, #000 0%, transparent 75%);
}

.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(12px, 3vw, 20px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(20, 25, 44, 0.6);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
  font-size: 14px;
  font-weight: 600;
  color: #cfd6f5;
  word-break: break-all;
}

.user-bar::before {
  content: "";
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #39e0c8;
  box-shadow: 0 0 10px rgba(57, 224, 200, 0.9);
}

.word-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  border-radius: 10px;
  background: #1b2036;
  border: 1px solid #2c3352;
}

.word-label {
  font-size: 14px;
  font-weight: 600;
  color: #c9cff0;
}

.word-row {
  display: flex;
  gap: 8px;
}

.word-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #39406a;
  background: #10142a;
  color: #f2f4ff;
  font-size: 15px;
}

.word-input:focus {
  outline: 2px solid #5b7cfa;
  outline-offset: 1px;
}

.word-button {
  flex: 1 1 auto;
  width: 100%;
  padding: 13px 20px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #6d8bff, #8b5cf6);
  color: #ffffff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(99, 122, 255, 0.35);
  transition: transform 0.12s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

.word-button:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(99, 122, 255, 0.42);
}

.word-button:active:not(:disabled) {
  transform: translateY(0) scale(0.995);
}

.word-button:disabled {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
}

.word-status {
  margin: 0;
  min-height: 20px;
  font-size: 14px;
  color: #a9b0d6;
  word-break: break-all;
}

.word-status.is-ok {
  color: #6ee7a8;
}

.word-status.is-error {
  color: #ff9a9a;
}

/* 공식 랭킹 등록 상태 안내 */
.rank-status {
  margin: 0;
  min-height: 20px;
  font-size: 14px;
  color: #a9b0d6;
  word-break: break-all;
}

.rank-status.is-ok {
  color: #6ee7a8;
}

.rank-status.is-error {
  color: #ff9a9a;
}

/* 반응속도 게임 영역 */
.game {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: clamp(180px, 38vh, 260px);
  padding: 24px;
  border-radius: 24px;
  border: 1px solid var(--panel-border);
  background:
    radial-gradient(circle at 50% 120%, rgba(109, 139, 255, 0.22), transparent 60%),
    linear-gradient(160deg, #1a2038, #131829);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 18px 40px rgba(0, 0, 0, 0.45);
  text-align: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: background 0.14s linear, border-color 0.18s ease, box-shadow 0.18s ease, transform 0.12s ease;
}

/* 아래쪽에서 비쳐 오는 빛무리 */
.game::before {
  content: "";
  position: absolute;
  bottom: -60%;
  left: 50%;
  width: 420px;
  height: 420px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(109, 139, 255, 0.18), transparent 70%);
  pointer-events: none;
}

.game:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.game:active {
  transform: scale(0.995);
}

.game.is-wait {
  background:
    radial-gradient(circle at 50% 120%, rgba(255, 110, 140, 0.2), transparent 60%),
    linear-gradient(160deg, #38161f, #241019);
  border-color: rgba(255, 120, 150, 0.45);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 0 0 1px rgba(255, 120, 150, 0.18), 0 18px 40px rgba(0, 0, 0, 0.45);
}

.game.is-ready {
  background:
    radial-gradient(circle at 50% 120%, rgba(57, 224, 200, 0.35), transparent 62%),
    linear-gradient(160deg, #0d6b52, #0a4a3a);
  border-color: #35e6a8;
  box-shadow: 0 0 0 2px rgba(53, 230, 168, 0.35), 0 0 42px rgba(53, 230, 168, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  animation: ready-pop 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.4);
}

.game.is-early {
  background:
    radial-gradient(circle at 50% 120%, rgba(240, 200, 70, 0.22), transparent 60%),
    linear-gradient(160deg, #4a3c10, #2b240c);
  border-color: rgba(230, 196, 70, 0.55);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 18px 40px rgba(0, 0, 0, 0.45);
}

.game.is-round {
  background:
    radial-gradient(circle at 50% 120%, rgba(109, 139, 255, 0.22), transparent 62%),
    linear-gradient(160deg, #1b2340, #131a30);
  border-color: rgba(143, 164, 255, 0.45);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 0 0 1px rgba(109, 139, 255, 0.18), 0 18px 40px rgba(0, 0, 0, 0.45);
}

.game.is-done {
  background:
    radial-gradient(circle at 50% 120%, rgba(139, 92, 246, 0.26), transparent 62%),
    linear-gradient(160deg, #1d2550, #141a38);
  border-color: rgba(143, 164, 255, 0.6);
  box-shadow: 0 0 0 2px rgba(109, 139, 255, 0.22), 0 18px 40px rgba(0, 0, 0, 0.45);
}

.game-face {
  position: relative;
  margin: 0;
  font-size: clamp(26px, 7vw, 40px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.45);
  transition: font-size 0.12s ease;
}

.game.is-ready .game-face {
  font-size: clamp(34px, 9vw, 52px);
  color: #ecfffa;
  text-shadow: 0 0 26px rgba(53, 230, 168, 0.55);
}

.game-hint {
  position: relative;
  margin: 0;
  font-size: 13px;
  color: rgba(220, 228, 255, 0.8);
  letter-spacing: 0.02em;
}

@keyframes ready-pop {
  0% {
    transform: scale(0.98);
  }
  60% {
    transform: scale(1.02);
  }
  100% {
    transform: scale(1);
  }
}

.result {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.32);
}

.result-line {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  word-break: break-all;
}

#resultLine {
  color: #dbe2ff;
  font-variant-numeric: tabular-nums;
}

#roundLine {
  font-variant-numeric: tabular-nums;
}

#bestLine {
  font-size: 17px;
  font-weight: 800;
  color: #ffe9a8;
  font-variant-numeric: tabular-nums;
}

.ranking {
  padding: 16px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.32);
}

.ranking-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.ranking-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.ranking-title::before {
  content: "";
  flex: 0 0 auto;
  width: 3px;
  height: 16px;
  border-radius: 2px;
  background: linear-gradient(#6d8bff, #39e0c8);
}

.rank-button {
  padding: 7px 14px;
  border: 1px solid rgba(143, 164, 255, 0.28);
  border-radius: 999px;
  background: rgba(16, 20, 42, 0.9);
  color: #dfe3ff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.rank-button:hover:not(:disabled) {
  background: rgba(109, 139, 255, 0.18);
  border-color: rgba(143, 164, 255, 0.5);
}

.rank-button:disabled {
  opacity: 0.55;
  cursor: default;
}

.rank-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rank-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(12, 16, 30, 0.75);
  font-size: 14px;
  transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.rank-item:hover {
  background: rgba(22, 28, 50, 0.9);
  border-color: rgba(143, 164, 255, 0.28);
  transform: translateX(2px);
}

.rank-no {
  flex: 0 0 auto;
  min-width: 46px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(143, 164, 255, 0.28);
  background: rgba(143, 164, 255, 0.1);
  font-size: 12px;
  font-weight: 700;
  color: #a7b6ff;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.rank-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-ms {
  flex: 0 0 auto;
  font-weight: 700;
  color: #dfe6ff;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.rank-empty {
  margin: 0;
  padding: 14px 4px;
  border-radius: 12px;
  border: 1px dashed rgba(143, 164, 255, 0.22);
  background: rgba(12, 16, 30, 0.45);
  font-size: 14px;
  color: #a9b0d6;
  text-align: center;
  line-height: 1.5;
}

/* 1~3등 강조: 순위 행을 메달 카드처럼 보여준다. */
.rank-item.rank-top {
  position: relative;
  overflow: hidden;
  align-items: center;
  border-radius: 14px;
  font-weight: 700;
}

.rank-item.rank-top1 {
  padding: 15px 14px;
  font-size: 18px;
  background: linear-gradient(100deg, #6b5510 0%, #2a2410 70%);
  border: 1px solid #e8c14a;
  box-shadow: 0 0 0 1px rgba(232, 193, 74, 0.35), 0 8px 22px rgba(0, 0, 0, 0.45), 0 0 30px rgba(232, 193, 74, 0.16);
}

.rank-item.rank-top2 {
  padding: 12px 12px;
  font-size: 17px;
  background: linear-gradient(100deg, #49526b 0%, #232838 70%);
  border: 1px solid #b9c3d6;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35), 0 0 22px rgba(185, 195, 214, 0.12);
}

.rank-item.rank-top3 {
  padding: 11px 12px;
  font-size: 16px;
  background: linear-gradient(100deg, #5e4028 0%, #2a2018 70%);
  border: 1px solid #c98a4b;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35), 0 0 22px rgba(201, 138, 75, 0.12);
}

/* 1등 행 위를 지나가는 반짝임 */
.rank-item.rank-top1::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -40px;
  width: 40px;
  background: linear-gradient(100deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.38), rgba(255, 255, 255, 0));
  animation: rank-shine 2.8s linear infinite;
  pointer-events: none;
}

@keyframes rank-shine {
  0% {
    left: -40px;
  }
  60%,
  100% {
    left: 110%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rank-item.rank-top1::after,
  .game.is-ready {
    animation: none;
  }

  .rank-item:hover,
  .word-button:hover:not(:disabled) {
    transform: none;
  }
}

/* 좁은 화면·낮은 iframe에서 여백을 줄여 플레이 영역을 확보한다. */
@media (max-width: 420px) {
  .app {
    gap: 10px;
  }

  .game {
    padding: 16px;
  }

  .result,
  .ranking {
    padding: 13px;
  }
}

/* CSS로 그린 메달 도형 (1~3등) */
.rank-item.rank-top .rank-no.rank-medal {
  position: relative;
  z-index: 0;
  flex: 0 0 34px;
  width: 32px;
  height: 32px;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 800;
  color: #2b2004;
  background: radial-gradient(circle at 32% 26%, #fff8d4 0%, #f2cd57 46%, #a97f12 100%);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.22), 0 3px 8px rgba(0, 0, 0, 0.45);
}

/* 메달 아래로 늘어지는 리본 */
.rank-item.rank-top .rank-no.rank-medal::before {
  content: "";
  position: absolute;
  z-index: -1;
  bottom: -7px;
  left: 50%;
  width: 22px;
  height: 12px;
  transform: translateX(-50%);
  background: linear-gradient(#e8c14a, #8f6c0d);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.rank-item.rank-top2 .rank-no.rank-medal {
  color: #1d2230;
  background: radial-gradient(circle at 32% 26%, #ffffff 0%, #cdd5e4 46%, #77808f 100%);
}

.rank-item.rank-top2 .rank-no.rank-medal::before {
  background: linear-gradient(#c7d0de, #6b7484);
}

.rank-item.rank-top3 .rank-no.rank-medal {
  color: #2b1607;
  background: radial-gradient(circle at 32% 26%, #ffe2c4 0%, #d08a45 46%, #7d4a1c 100%);
}

.rank-item.rank-top3 .rank-no.rank-medal::before {
  background: linear-gradient(#d18f4d, #7a4614);
}

.rank-item.rank-top .rank-ms {
  color: #fff3c4;
}

/* 시크릿 타이머: Ctrl+Shift+1 로 켜고 끄는 확인용 안내. 기본은 숨김 */
.secret-timer {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 5;
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 200, 90, 0.5);
  background: rgba(20, 16, 4, 0.9);
  color: #ffe6a8;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.secret-timer[hidden] {
  display: none;
}
