/* 카메라가 배경이고, 컨트롤은 그 위에 뜬 유리판.
   영상이 주인공이라 UI는 비켜서되, 어떤 화면 위에서도 글씨가 읽혀야 한다. */

:root {
  /* 토스 파랑은 흰 바탕 기준 값이다. 어두운 유리 위에서는 한 단계 옅게 써야
     같은 세기로 읽힌다. 채우는 색(행동)과 글자색(상태)을 나눠 쓴다. */
  --blue-fill: #3182f6;              /* 누르는 것 */
  --blue-tint: rgba(49, 130, 246, 0.2);
  --win: #6ba8fb;                    /* 어두운 바탕 위 글자·표시 */
  --lose: #ff6b78;
  --even: #9aa4b0;  /* 무승부 — 이긴 것도 진 것도 아닌 중립 회색 */

  --t1: #fff;                          /* 본문 */
  --t2: rgba(255, 255, 255, 0.62);     /* 보조 */
  --t3: rgba(255, 255, 255, 0.38);     /* 흐린 것 */

  --glass: rgba(255, 255, 255, 0.11);
  --glass-strong: rgba(255, 255, 255, 0.17);
  --hairline: rgba(255, 255, 255, 0.22);
  --sheen: inset 0 1px 0 rgba(255, 255, 255, 0.26);

  --r-lg: 26px;
  --r-md: 18px;
  --spring: cubic-bezier(0.32, 0.72, 0, 1);
  --font: 'Pretendard Variable', Pretendard, -apple-system, system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #0b0b0d;
  color: var(--t1);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

#app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: grid;
  place-items: center;
  isolation: isolate;
}

/* ---------------- 카메라 배경 ---------------- */

.stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 0%, #23242a, #0b0b0d 70%);
}

#cam, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

/* 위아래를 눌러둬야 어떤 영상 위에서도 글씨가 읽힌다 */
.scrim {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(0,0,0,0.55) 0%, transparent 22%, transparent 52%, rgba(0,0,0,0.72) 100%);
}

.flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}
.flash.on { animation: flash 0.5s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

.stage.shake { animation: shake 0.34s; }
@keyframes shake {
  0%, 100% { transform: none; }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-2px); }
}

/* 설정·결과 화면에서는 배경을 눌러 글씨에 집중시킨다 */
/* 라이브 영상에 filter: blur()를 걸면 매 프레임 전체를 다시 블러한다.
   안드로이드에선 이것만으로 화면이 멈춘다. 어둡게 덮는 쪽이 같은 의도에 공짜다. */
.stage.dim .scrim { background: rgba(9, 9, 12, 0.8); }
.stage.dim #cam { filter: brightness(0.7); }
.stage.dim #overlay { opacity: 0; }

/* ---------------- 유리판 ---------------- */

.glass {
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border: 0.5px solid var(--hairline);
  box-shadow: var(--sheen), 0 8px 28px rgba(0, 0, 0, 0.3);
}

/* ---------------- 화면 틀 ---------------- */

.screen {
  position: relative;
  z-index: 1;
  display: none;
  width: 100%;
  max-width: 440px;
  height: 100%;
  min-height: 0;
  flex-direction: column;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-left))
    max(18px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-right));
}
.screen.active { display: flex; }

@media (min-width: 620px) and (min-height: 660px) {
  .screen { max-width: 460px; height: min(100%, 820px); }
}
@media (max-height: 560px) {
  .screen { padding-top: 10px; padding-bottom: 10px; }
  h1 { font-size: 26px !important; letter-spacing: -0.9px !important; }
  .h1-pre { font-size: 15px; }
  .lead { font-size: 13px; }
  .seg-btn, .btn { height: 46px; }
}

/* ---------------- 설정 ---------------- */

/* 세로 영상으로 잘라낼 때 아래가 먼저 날아간다. 가운데로 올려 잡는다. */
#screen-setup { justify-content: center; gap: 18px; padding-bottom: 6vh; }

.lead-block { padding: 0 6px; }

.h1-pre {
  display: block;
  margin-bottom: 6px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.4px;
  color: var(--t2);
}

h1 {
  font-size: clamp(34px, 9.5vw, 42px);
  font-weight: 700;
  line-height: 1.22;
  letter-spacing: -1.3px; /* 큰 한글은 바짝 조여야 덩어리로 읽힌다 */
}

.lead {
  margin-top: 12px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.65;
  color: var(--t2);
}

.panel {
  padding: 18px;
  display: grid;
  gap: 12px;
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 0.5px solid var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--sheen), 0 16px 44px rgba(0, 0, 0, 0.4);
}
.panel.row { grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }

.section {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.2px;
  color: var(--t2);
}

.segmented { display: flex; gap: 6px; }

.seg-btn {
  flex: 1;
  min-width: 0;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  color: var(--t2);
  background: var(--glass);
  border: 0.5px solid transparent;
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.16s, color 0.16s, transform 0.12s var(--spring);
}
.seg-btn:active { transform: scale(0.95); }
.seg-btn.on {
  color: var(--win);
  background: var(--blue-tint);
  border-color: rgba(107, 168, 251, 0.42);
  animation: nudge 0.3s var(--spring);
}
@keyframes nudge {
  0% { transform: scale(0.94); }
  60% { transform: scale(1.03); }
  100% { transform: none; }
}
.seg-btn.write { padding: 0 6px; }
.seg-btn.write input {
  width: 100%;
  min-width: 0;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  color: var(--t1);
  background: none;
  border: none;
  outline: none;
}
.seg-btn.write input::placeholder { color: var(--t3); }
.seg-btn.write:focus-within { background: var(--glass-strong); }
.seg-btn.write input::-webkit-outer-spin-button,
.seg-btn.write input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.btn {
  width: 100%;
  height: 54px;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: #fff;
  background: var(--blue-fill);
  border: none;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.12s var(--spring), opacity 0.16s;
}
.btn:active:not(:disabled) { transform: scale(0.975); opacity: 0.88; }
.btn:disabled { color: var(--t3); background: var(--glass); box-shadow: none; cursor: progress; }
.btn.quiet {
  color: var(--t1);
  background: var(--glass-strong);
  border: 0.5px solid var(--hairline);
}

.assist {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--t3);
  text-align: center;
  min-height: 19px;
}
.assist.bad { color: var(--lose); }

:where(button, input):focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

#screen-setup.active .h1-pre { animation: settle 0.5s var(--spring) both; }
#screen-setup.active h1 { animation: settle 0.5s var(--spring) 0.05s both; }
#screen-setup.active .lead { animation: settle 0.5s var(--spring) 0.1s both; }
#screen-setup.active .panel { animation: rise 0.55s var(--spring) 0.14s both; }
@keyframes settle {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(22px); }
  to { opacity: 1; transform: none; }
}

/* ---------------- 대결 ---------------- */

#screen-play { justify-content: space-between; }

/* 진행도·점수와 '지금 무슨 손인지'를 한 덩어리로 위에 모은다 */
.top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.top .hud { width: 100%; }
/* 알약이 늘어나지 않고 가운데 서도록 못 박는다 */
.top .read { align-self: center; width: auto; margin: 0 auto; }

.hud { display: flex; align-items: center; gap: 8px; padding-top: 4px; }

.progress {
  flex: 1;
  display: flex;
  gap: 4px;
  height: 34px;
  padding: 0 12px;
  align-items: center;
  border-radius: 999px;
}
.seg {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.26);
  border-radius: 2px;
  transform-origin: center;
  transition: background 0.2s;
}
.seg.win { background: var(--win); }
.seg.lose { background: var(--lose); }
.seg.draw { background: var(--even); }
.seg.pop { animation: segpop 0.42s var(--spring); }
@keyframes segpop {
  0% { transform: scaleY(1); }
  40% { transform: scaleY(2.8); }
  100% { transform: scaleY(1); }
}

.score {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 34px;
  padding: 0 14px;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  border-radius: 999px;
}
.score em { font-style: normal; color: var(--t3); }
.score span { font-size: 11px; font-weight: 600; color: var(--t3); }
.score b { display: inline-block; min-width: 11px; text-align: center; }
.score #scoreMe { color: var(--win); }
.score #scoreAi { color: var(--lose); }
.score b.tick { animation: tick 0.4s var(--spring); }
@keyframes tick {
  0% { transform: translateY(5px) scale(1.28); }
  100% { transform: none; }
}

/* 가운데가 아니라 위쪽으로 당겨 붙인다.
   세로로 잘라낸 영상에서 손과 결과가 화면 중앙보다 위에 있어야 잘 담긴다. */
.machine {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 4vh;
  pointer-events: none;
}

.ai-hand {
  font-size: clamp(64px, min(26vw, 17vh), 116px);
  line-height: 1;
  filter: drop-shadow(0 18px 34px rgba(0, 0, 0, 0.55));
  transform: translateY(-16px);
  will-change: transform;
}
.ai-hand.pumping { animation: pump 0.5s ease-in-out infinite; }
@keyframes pump {
  0%, 100% { transform: translateY(-26px) rotate(-6deg); }
  50% { transform: translateY(26px) rotate(6deg); }
}
.ai-hand.thrown { animation: throwdown 0.26s cubic-bezier(0.3, 1.5, 0.4, 1) forwards; }
@keyframes throwdown {
  0% { transform: translateY(-26px) rotate(-6deg); }
  100% { transform: translateY(10px) scale(1.12); }
}
/* 확대된 손은 레이아웃 상자보다 아래로 삐져나온다.
   많이 내리면 바로 밑 판정을 덮으므로 제자리 근처에서 확정시킨다. */
.ai-hand.locked { animation: lockin 0.42s cubic-bezier(0.2, 1.6, 0.35, 1) forwards; }
@keyframes lockin {
  0% { transform: translateY(-6px) scale(1.85); }
  100% { transform: translateY(8px) scale(1.16); }
}

.ai-move {
  margin-bottom: 20px; /* 손이 transform으로 위로 올라오므로 그만큼 비운다 */
  min-height: 40px;
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: -0.4px;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.6);
}
.ai-move.count {
  font-size: 44px;
  font-variant-numeric: tabular-nums;
  animation: popin 0.28s var(--spring);
}
.ai-move.name { font-size: 28px; animation: popin 0.3s var(--spring); }
@keyframes popin {
  0% { transform: scale(1.7); opacity: 0; }
  100% { transform: none; opacity: 1; }
}

.callout {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  text-align: center;
  pointer-events: none;
}
.callout .big {
  font-size: clamp(24px, 7vw, 32px);
  font-weight: 700;
  letter-spacing: -0.6px;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.7);
}
.callout .big.beat { animation: beat 0.42s var(--spring); }
@keyframes beat {
  from { opacity: 0; transform: scale(1.22); }
  to { opacity: 1; transform: none; }
}

.callout .sub {
  margin-top: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--t2);
}
.callout .big.beat + .sub { animation: settle 0.4s var(--spring) 0.06s both; }

.bottom { position: relative; display: grid; gap: 10px; }

.read {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px;
  font-size: 13px;
  font-weight: 500;
  color: var(--t2);
  border-radius: 999px;
  transition: opacity 0.2s;
}
/* 판정이 뜨는 동안에는 비켜준다 */
#app.judging .read { opacity: 0; }
.read .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--t3);
  transition: background 0.2s;
}
.read.locked { color: var(--t1); }
.read.locked .dot { background: var(--win); box-shadow: 0 0 8px var(--win); }

/* 판정 — 유리판이 올라온다 */
/* 판정은 손 바로 아래에 붙는다. 화면 맨 아래에 있으면
   세로로 잘라낸 영상에서 손과 결과가 따로 놀아 한눈에 안 읽힌다. */
.sheet {
  margin-top: 34px;
  padding: 14px 22px;
  text-align: center;
  background: var(--glass-strong);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 0.5px solid var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--sheen), 0 16px 44px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translateY(-10px) scale(0.96);
  transition: opacity 0.2s linear, transform 0.34s var(--spring);
  pointer-events: none;
}
.sheet.on { opacity: 1; transform: none; }

.sheet.on .verdict { animation: settle 0.34s var(--spring) 0.1s both; }
.sheet.on .detail { animation: settle 0.34s var(--spring) 0.15s both; }

.verdict {
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -0.6px;
}
.verdict.win { color: var(--win); }
.verdict.lose { color: var(--lose); }
.verdict.draw { color: var(--even); }

.detail {
  margin-top: 4px;
  font-size: 14px;
  font-weight: 500;
  color: var(--t2);
}

.hands { display: none; gap: 8px; width: 100%; }
.hands.active { display: flex; }
.hand {
  flex: 1;
  height: 58px;
  font-size: 25px;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.12s var(--spring), background 0.16s;
}
.hand:active:not(:disabled) { transform: scale(0.95); background: var(--glass-strong); }
.hand:disabled { opacity: 0.35; cursor: default; }

/* ---------------- 결과 모달 ---------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  visibility: hidden;
  transition: visibility 0s 0.44s;
}
.modal.on { visibility: visible; transition-delay: 0s; }

.modal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  opacity: 0;
  transition: opacity 0.3s;
}
.modal.on .modal-scrim { opacity: 1; }

/* 모바일: 아래에서 올라오는 시트 */
.modal-card {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: 92dvh;
  overflow-y: auto;
  display: grid;
  gap: 14px;
  padding: 14px 20px max(20px, env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.13);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 0.5px solid var(--hairline);
  border-radius: 28px 28px 0 0;
  box-shadow: var(--sheen), 0 -12px 50px rgba(0, 0, 0, 0.5);
  transform: translateY(100%);
  transition: transform 0.44s var(--spring);
}
.modal.on .modal-card { transform: none; }

/* 데스크톱: 가운데 다이얼로그. 넓은 화면에서 아래 시트는 어색하다. */
@media (min-width: 620px) and (min-height: 660px) {
  .modal { align-items: center; padding: 24px; }
  .modal-card {
    max-width: 400px;
    max-height: calc(100dvh - 48px);
    padding: 24px;
    border-radius: 28px;
    opacity: 0;
    transform: translateY(14px) scale(0.96);
    transition: transform 0.36s var(--spring), opacity 0.24s;
  }
  .modal.on .modal-card { opacity: 1; transform: none; }
  .modal-card .grabber { display: none; }
}

/* 모바일 바텀시트의 손잡이 */
.grabber {
  display: block;
  width: 36px;
  height: 4px;
  margin: 0 auto 12px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
}

.result-head { text-align: center; }

.result-emoji {
  font-size: 54px;
  line-height: 1;
  margin-bottom: 10px;
}

.result-title {
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -0.6px;
}
.result-title.win { color: var(--win); }
.result-title.lose { color: var(--lose); }
.result-title.tie { color: var(--even); }

.result-line {
  margin-top: 6px;
  font-size: 15px;
  font-weight: 500;
  color: var(--t2);
}

.result-head .assist { margin-top: 8px; }

.modal.on .result-emoji { animation: popin 0.5s var(--spring) 0.16s both; }
.modal.on .result-title { animation: settle 0.44s var(--spring) 0.22s both; }
.modal.on .result-line { animation: settle 0.44s var(--spring) 0.27s both; }
.modal.on .result-head .assist { animation: settle 0.44s var(--spring) 0.31s both; }
.modal.on #cardCanvas { animation: cardin 0.5s var(--spring) 0.34s both; }

#cardCanvas {
  justify-self: center;
  width: min(196px, 44vw);
  max-height: 40dvh;
  height: auto;
  object-fit: contain;
  border-radius: 14px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
}
@keyframes cardin {
  from { opacity: 0; transform: translateY(14px) scale(0.94); }
  to { opacity: 1; transform: none; }
}

.modal-actions {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}


/* 유리가 지원되지 않거나 기기가 버거울 때: 불투명한 바탕으로 떨어진다 */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass, .panel, .sheet, .modal-card { background: rgba(28, 29, 34, 0.94); }
}

html.no-glass .glass,
html.no-glass .panel,
html.no-glass .sheet,
html.no-glass .modal-card {
  background: rgba(28, 29, 34, 0.94);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
html.no-glass .stage.dim .scrim { background: rgba(9, 9, 12, 0.88); }
