:root {
  --ink: #4a2a2a;
  --ink-soft: #8a5a55;
  --card: rgba(255, 250, 246, 0.94);
  --accent: #ff6f7d;
  --accent-2: #ffb36b;
  --good: #49c28a;
  --bad: #e2474f;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #f3c4ab;
  font-family: var(--font, "Apple SD Gothic Neo", "Noto Sans KR", "PingFang SC", "Hiragino Sans", "Noto Sans CJK KR", "Malgun Gothic", system-ui, sans-serif);
  color: var(--ink);
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
}
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; }
.hidden { display: none !important; }
button { font-family: inherit; color: inherit; cursor: pointer; }

/* HUD */
#hud { position: fixed; left: 0; right: 0; top: 0; padding: calc(8px + var(--safe-top)) 10px 0; pointer-events: none; z-index: 5; }
.hud-row { display: flex; gap: 6px; max-width: 760px; margin: 0 auto; }
.hud-box {
  flex: 1 1 0; min-width: 0; background: var(--card); border-radius: 14px; padding: 6px 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(120, 50, 40, 0.15);
}
.hud-label { font-size: 11px; color: var(--ink-soft); white-space: nowrap; }
.hud-val { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hud-val.warn { color: var(--bad); animation: pulse 0.5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); } }
.pain-box { flex: 1.4 1 0; flex-direction: row; gap: 6px; }
#hud-face { width: 34px; height: 34px; flex: none; }
.pain-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.pain-bar { width: 100%; height: 10px; border-radius: 6px; background: #f1dcd5; overflow: hidden; margin-top: 3px; }
.pain-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #ffc27a, #ff6f7d, #d8283a); border-radius: 6px; transition: width 0.12s; }

#hint {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(76px + var(--safe-bottom)); z-index: 5; pointer-events: none;
  background: rgba(74, 42, 42, 0.78); color: #fff; font-size: 13px; padding: 6px 12px; border-radius: 999px;
  max-width: calc(100vw - 32px); text-align: center; line-height: 1.35;
}

/* Toolbar */
#toolbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; gap: 8px; align-items: center;
  padding: 8px 10px calc(10px + var(--safe-bottom));
  max-width: 760px; margin: 0 auto;
}
.tool {
  border: none; background: var(--card); border-radius: 16px; padding: 8px 12px; font-size: 14px; font-weight: 700;
  display: flex; align-items: center; gap: 6px; min-height: 48px; box-shadow: 0 2px 8px rgba(120, 50, 40, 0.18);
}
.tool.active { background: #fff; outline: 3px solid var(--accent); }
.tool.small { padding: 8px 10px; font-size: 13px; }
.tool span, .tool { white-space: nowrap; }
.tool.finish { background: var(--accent); color: #fff; }
.tool.glow { animation: glow 0.9s infinite alternate; }
@keyframes glow { to { box-shadow: 0 0 0 6px rgba(255, 111, 125, 0.35), 0 2px 8px rgba(120, 50, 40, 0.18); } }
.spacer { flex: 1; }
.ic { display: inline-block; width: 20px; height: 20px; border-radius: 50%; }
.ic-hand { background: radial-gradient(circle at 35% 35%, #ffe3d3, #f0a98f); border: 2px solid #d98a74; }
.ic-pad { background: radial-gradient(circle, #fff 40%, #f1ece8 41%, #fff 60%); border: 2px solid #ddd2cc; }

/* Screens */
.screen {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  background: rgba(246, 200, 180, 0.35); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  overflow-y: auto;
}
.title-card, .result-card {
  width: 100%; max-width: 420px; background: var(--card); border-radius: 28px; padding: 22px 18px;
  box-shadow: 0 10px 40px rgba(120, 50, 40, 0.25); margin: auto;
}
.logo { text-align: center; margin-bottom: 14px; position: relative; }
.logo h1 { margin: 6px 0 0; font-size: 36px; letter-spacing: -1px; color: #e2505f; text-shadow: 0 3px 0 #ffd2c4; }
.logo .sub { margin: 2px 0 0; font-size: 14px; color: var(--ink-soft); letter-spacing: 2px; }
.logo-dot {
  display: inline-block; width: 46px; height: 46px; border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #fffbe6 0 30%, #f3d27e 31% 38%, #f08c7f 39%, #e0675e 100%);
  box-shadow: 0 0 0 8px rgba(255, 120, 110, 0.18);
  animation: bob 1.6s ease-in-out infinite;
}
@keyframes bob { 50% { transform: scale(1.1, 0.92); } }
.big-btn {
  width: 100%; border: none; border-radius: 18px; padding: 14px 12px; margin: 6px 0; font-size: 18px; font-weight: 800;
  background: #fff; box-shadow: 0 3px 0 #e8c2b6; display: flex; flex-direction: column; align-items: center;
}
.big-btn small { font-size: 12px; font-weight: 500; color: var(--ink-soft); margin-top: 2px; }
.big-btn.primary { background: linear-gradient(180deg, #ff8a93, #ff6f7d); color: #fff; box-shadow: 0 3px 0 #d94f5c; }
.big-btn.primary small { color: #ffe7e9; }
.big-btn.ghost { background: transparent; box-shadow: none; font-size: 15px; color: var(--ink-soft); }
.big-btn:active { transform: translateY(2px); box-shadow: none; }
.howto { list-style: none; padding: 0; margin: 14px 0 4px; font-size: 13px; line-height: 1.45; color: var(--ink); }
.howto li { padding: 5px 0; border-top: 1px dashed #efd6cd; display: grid; grid-template-columns: 82px 1fr; gap: 6px; }
.howto b { color: #e2505f; }
.best { text-align: center; font-size: 13px; color: var(--ink-soft); margin: 8px 0 0; min-height: 1em; }
#result-img { width: 100%; max-height: 40vh; object-fit: contain; border-radius: 16px; display: block; background: #fff; }
.result-buttons { margin-top: 6px; display: flex; gap: 8px; }
.result-buttons .big-btn { flex: 1 1 0; min-width: 0; }
.big-btn { white-space: nowrap; }
.big-btn small { white-space: normal; text-align: center; }

/* 자랑 다시보기 */
.replay-box { position: relative; margin-bottom: 10px; border-radius: 18px; overflow: hidden; background: #f1c0a3; box-shadow: 0 3px 0 #e8c2b6; }
#replay { display: block; width: 100%; aspect-ratio: 16 / 10; max-height: 34vh; }
.replay-title {
  position: absolute; left: 10px; bottom: 8px; z-index: 1; font-size: 11px; font-weight: 800; color: #fff;
  background: rgba(226, 80, 95, 0.85); padding: 3px 9px; border-radius: 999px; white-space: nowrap; pointer-events: none;
}

/* 공유 */
.share-row { display: flex; gap: 8px; margin-top: 10px; }
.share-btn {
  flex: 1 1 0; min-width: 0; border: none; border-radius: 16px; min-height: 46px; padding: 8px 4px;
  display: flex; align-items: center; justify-content: center; gap: 5px; font-size: 13.5px; font-weight: 800; white-space: nowrap;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
}
.share-btn svg { width: 17px; height: 17px; flex: none; }
.share-btn span { overflow: hidden; text-overflow: ellipsis; }
.share-btn:active { transform: translateY(2px); box-shadow: none; }
.share-btn.sx { background: #1d1b1f; color: #fff; }
.share-btn.sig { flex-grow: 1.3; background: linear-gradient(135deg, #f7b24a, #ee3f73 50%, #8a49d6); color: #fff; }
.share-btn.sg { background: #fff; color: var(--ink); box-shadow: 0 3px 0 #e8c2b6; }

/* 언어 */
.lang-picker { display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; margin: 0 0 6px; }
.result-card .lang-picker { margin: 6px 0 0; }
.lang-picker button {
  border: none; background: rgba(255, 255, 255, 0.7); border-radius: 999px; padding: 5px 11px; font-size: 13px; font-weight: 700;
  color: var(--ink-soft); white-space: nowrap; min-height: 32px;
}
.lang-picker button.active { background: var(--accent); color: #fff; }

/* 알림 */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); z-index: 30;
  background: rgba(74, 42, 42, 0.92); color: #fff; padding: 10px 16px; border-radius: 16px; font-size: 14px; font-weight: 700;
  max-width: calc(100vw - 32px); text-align: center; white-space: pre-line; line-height: 1.4; pointer-events: none;
}
.toast.show { animation: toastIn 0.25s ease-out; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } }

/* 넓은 가로 화면: 카드 왼쪽, 다시보기와 버튼 오른쪽 */
@media (min-width: 760px) and (min-aspect-ratio: 1/1) {
  .result-card { max-width: 860px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); column-gap: 18px; align-items: start; }
  #result-img { grid-column: 1; grid-row: 1 / span 6; max-height: calc(100vh - 90px); }
  .result-card > :not(#result-img) { grid-column: 2; }
  .result-card .share-row { margin-top: 0; }
  #replay { max-height: 46vh; }
}

@media (min-width: 700px) {
  .hud-val { font-size: 20px; }
  .hud-label { font-size: 12px; }
  #hint { font-size: 14px; bottom: 84px; }
}
