:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f4f6;
  color: #19181d;
  --heart-guide-x: 48%;
  --heart-guide-y: 64%;
  --heart-guide-width: 16%;
  --heart-guide-height: 21%;
}

* { box-sizing: border-box; }

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

body { min-height: 100vh; }

button, input, select { font: inherit; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 52px;
  padding: 8px 12px;
  border: 1px solid #dedde3;
  border-radius: 10px;
  background: #fff;
}

.toolbar h1 { margin: 0 auto 0 0; font-size: 1rem; font-weight: 650; }

.tool { display: flex; align-items: center; gap: 7px; font-size: .9rem; }

.tool input[type="color"] { width: 38px; height: 34px; padding: 2px; border: 1px solid #ccc; border-radius: 6px; background: white; }

.tool input[type="range"] { width: 110px; }

button {
  min-height: 44px;
  padding: 7px 14px;
  border: 1px solid #cfced5;
  border-radius: 7px;
  background: #fff;
  color: #19181d;
  cursor: pointer;
}

button:active { background: #ecebf0; }
button:disabled { opacity: .5; cursor: not-allowed; }

button.danger { color: #b42318; }

.canvas-shell {
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #d7d6dc;
  border-radius: 12px;
  background: #10192f;
  box-shadow: 0 8px 28px rgba(23, 20, 31, .08);
}

body:not(.display-page) .app > .canvas-shell { grid-row: 5; }

.scene-stage {
  position: relative;
  flex: none;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #10192f;
  touch-action: none;
}

.scene-background {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 50%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.drawing-canvas {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: block;
  width: 100%;
  height: 100%;
  background: transparent !important;
  touch-action: none;
}

.draw-ai-result {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 50%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 550ms ease;
}
.draw-page .scene-stage[data-view="ai"] .draw-ai-result { opacity: 1; }
.draw-page .drawing-canvas { transition: opacity 300ms ease; }
.draw-page .scene-stage[data-view="ai"] .drawing-canvas { opacity: 0; }
select { min-height: 44px; padding: 6px 8px; border: 1px solid #cfced5; border-radius: 7px; background: #fff; }
.tool input[type="text"] { min-height: 40px; width: min(220px, 42vw); padding: 6px 9px; border: 1px solid #cfced5; border-radius: 7px; }
.rotate-hint { display: none; margin: 0; text-align: center; font-size: .82rem; color: #66616f; }

.ai-panel {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px;
  padding: 8px 12px;
  border: 1px solid #dedde3;
  border-radius: 10px;
  background: #fff;
}

.ai-panel h2 { margin: 0 auto 0 0; font-size: .95rem; font-weight: 650; }
.switch input { width: 19px; height: 19px; }
.ai-status, .ai-countdown { font-size: .82rem; color: #66616f; }
.ai-status[data-state="generating"] { color: #8a5a00; }
.ai-status[data-state="ready"] { color: #18794e; }
.ai-status[data-state="error"], .ai-status[data-state="not-configured"] { color: #b42318; }

.campaign-intro {
  padding: 13px 16px;
  border: 1px solid #ead8a1;
  border-radius: 12px;
  text-align: center;
  background: linear-gradient(135deg, #fffdf7, #fff7dc);
}
.campaign-intro h1 { margin: 0; color: #7a5710; font-size: 1.3rem; }
.campaign-intro p { margin: 5px 0 0; color: #735f32; font-size: .9rem; }
.heart-guide {
  display: none;
  position: absolute;
  z-index: 2;
  left: var(--heart-guide-x);
  top: var(--heart-guide-y);
  width: var(--heart-guide-width);
  height: var(--heart-guide-height);
  pointer-events: none;
  opacity: .3;
  transform: translate(-50%, -50%);
  transition: opacity 500ms ease;
}
.heart-guide svg { display: block; width: 100%; height: 100%; overflow: visible; }
.heart-guide path { fill: none; stroke: #FFD45A; stroke-width: 2; stroke-dasharray: 5 4; stroke-linecap: round; stroke-linejoin: round; }
.heart-guide span { position: absolute; top: -1.35rem; left: 50%; width: max-content; max-width: 52vw; transform: translateX(-50%); color: #fff6ce; font-size: clamp(.55rem, 1.25vw, .78rem); text-shadow: 0 1px 5px #10192f; }
.heart-guide.is-hidden { opacity: 0; }
body[data-campaign="golden-heart"] .heart-guide { display: block; }
body[data-campaign="golden-heart"] #aiSubjectField,
body[data-campaign="golden-heart"] #aiStyleField { display: none; }

#drawCanvas { touch-action: none; cursor: crosshair; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .84rem;
  color: #66616f;
}

.status::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #e5484d;
}

.status[data-state="connected"]::before { background: #30a46c; }
.status[data-state="connecting"]::before { background: #f5a524; }

.display-page { background: #000; overflow: hidden; }
.display-page[data-campaign="golden-heart"] { background: #020713; }
.display-page[data-campaign="golden-heart"] .canvas-shell { background: #10192f; }
.display-page .app { width: 100vw; height: 100vh; min-height: 0; padding: 0; display: grid; place-items: center; }
.display-page .canvas-shell { width: 100vw; height: 100vh; border: 0; border-radius: 0; box-shadow: none; background: #111; }
.display-page .scene-stage { width: min(100vw, calc(100vh * 16 / 9)); height: min(100vh, calc(100vw * 9 / 16)); }
.display-page .status { position: fixed; top: 12px; left: 12px; z-index: 4; padding: 7px 10px; border-radius: 999px; background: rgba(255,255,255,.9); }
.display-stage .ai-result-image { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; object-fit: cover; object-position: 50% 50%; opacity: 0; pointer-events: none; }
.display-stage[data-view="ai"] #aiImage { opacity: 1; transition: opacity 400ms ease; }
.display-stage[data-view="raw"] #aiImage { opacity: 0; transition: none; }
.display-stage[data-view="ai"] #displayCanvas { visibility: hidden; }
.display-ai-status { position: fixed; top: 58px; left: 12px; z-index: 4; min-height: 1.9rem; padding: 6px 10px; border-radius: 8px; background: rgba(0,0,0,.68); color: #fff; font-size: .82rem; }
.display-ai-status:empty { display: none; }
.view-toggle { position: fixed; right: 12px; top: 12px; z-index: 4; background: rgba(255,255,255,.92); }

/* Minimal kiosk-style drawing screen. The 16:9 stage remains identical to /display. */
.draw-page {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: #050812;
}

.draw-page .draw-app {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  display: block;
  padding: 0;
  overflow: hidden;
}

.draw-page .draw-shell {
  position: relative;
  grid-row: auto;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: #050812;
}

.draw-page .scene-prompt {
  position: absolute;
  z-index: 4;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 7px 14px;
  transform: translateX(-50%);
  border-color: rgba(255, 226, 141, .3);
  border-radius: 999px;
  background: rgba(8, 13, 27, .64);
  backdrop-filter: blur(8px);
}

.draw-page .scene-prompt h1 { display: none; }
.draw-page .scene-prompt p { margin: 0; color: #fff7dc; font-size: clamp(.72rem, 1.6vw, .92rem); }

.draw-controls {
  position: fixed;
  z-index: 5;
  right: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  width: min(720px, calc(100vw - max(24px, env(safe-area-inset-left)) - max(24px, env(safe-area-inset-right))));
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px 9px 14px;
  transform: translateX(50%);
  border: 1px solid rgba(255, 255, 255, .34);
  border-radius: 28px;
  background:
    linear-gradient(155deg, rgba(255, 255, 255, .22), rgba(255, 255, 255, .08) 44%, rgba(20, 28, 50, .32)),
    rgba(7, 13, 28, .46);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .32),
    inset 0 -1px 0 rgba(255, 255, 255, .08),
    0 18px 44px rgba(0, 0, 0, .32),
    0 2px 8px rgba(0, 0, 0, .2);
  color: #fff;
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  isolation: isolate;
}

.draw-controls::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 1px 18px auto;
  height: 38%;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .16), transparent);
  pointer-events: none;
}

.control-meta,
.control-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-meta {
  min-width: max-content;
  direction: rtl;
}

.draw-controls .control-button {
  min-height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 14px;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 20px;
  background: rgba(255, 255, 255, .14);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .24), 0 4px 12px rgba(0, 0, 0, .12);
  color: rgba(255, 255, 255, .94);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.draw-controls .control-button:hover { background: rgba(255, 255, 255, .22); }
.draw-controls .control-button:active { transform: scale(.96); background: rgba(255, 255, 255, .28); }
.draw-controls .control-button:focus-visible { outline: 3px solid rgba(255, 212, 90, .72); outline-offset: 2px; }
.draw-controls .control-button:disabled { opacity: .42; }
.draw-controls .control-button svg {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.draw-controls .primary-action {
  min-width: 180px;
  border-color: rgba(255, 232, 158, .92);
  background: linear-gradient(145deg, #ffe890, #ffd34f 66%, #efb927);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .86), 0 7px 20px rgba(221, 162, 12, .3);
  color: #342500;
  font-weight: 700;
}
.draw-controls .primary-action:hover { background: linear-gradient(145deg, #fff0b1, #ffdb65 66%, #f5c33b); }
.draw-controls .primary-action:active { background: linear-gradient(145deg, #f8d96d, #efbf39); }
.draw-controls .danger { color: #ffb8b5; }

.draw-controls .status {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 999px;
  background: rgba(2, 7, 19, .24);
  color: #f2f3f7;
  white-space: nowrap;
}

.draw-controls .compact-switch {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px 0 8px;
  white-space: nowrap;
  color: rgba(255, 255, 255, .9);
  font-size: .85rem;
  cursor: pointer;
}

.draw-controls .compact-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  position: relative;
  width: 46px;
  height: 28px;
  flex: none;
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: 999px;
  background: rgba(1, 5, 14, .36);
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, .28);
  transition: background 180ms ease, border-color 180ms ease;
}

.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 7px rgba(0, 0, 0, .3);
  transition: transform 220ms cubic-bezier(.2, .8, .2, 1);
}

.compact-switch input:checked + .switch-track {
  border-color: rgba(255, 226, 119, .9);
  background: linear-gradient(135deg, #ffd95c, #f0b81f);
}
.compact-switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); }
.compact-switch input:focus-visible + .switch-track { outline: 3px solid rgba(255, 212, 90, .7); outline-offset: 2px; }
.compact-switch input:disabled + .switch-track { opacity: .42; }
.draw-controls .ai-status,
.draw-controls .ai-countdown {
  position: absolute;
  bottom: calc(100% + 8px);
  max-width: min(360px, calc(100vw - 32px));
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 999px;
  background: rgba(7, 13, 28, .6);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .24);
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
}
.draw-controls .ai-status { right: 0; }
.draw-controls .ai-countdown { left: 0; }
.draw-controls .ai-countdown:empty { display: none; }

.draw-page .rotate-hint {
  position: fixed;
  z-index: 6;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  width: max-content;
  max-width: calc(100vw - 24px);
  padding: 7px 12px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: rgba(7, 11, 23, .8);
  color: #fff;
}

.campaign-judge {
  position: fixed;
  z-index: 5;
  right: 50%;
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 84px);
  max-width: min(430px, calc(100vw - 24px));
  padding: 7px 12px;
  transform: translateX(50%);
  border: 1px solid rgba(255, 212, 90, .26);
  border-radius: 999px;
  background: rgba(7, 11, 23, .78);
  color: #fff7dc;
  font-size: .82rem;
  text-align: center;
  backdrop-filter: blur(10px);
}
.campaign-judge:empty { display: none; }
.campaign-judge[data-state="winner"] { border-color: #FFD45A; background: rgba(91, 62, 0, .84); }
.campaign-judge[data-state="error"] { border-color: rgba(255, 130, 130, .55); color: #ffd8d8; }

.campaign-score-card {
  --score-percent: 0%;
  --win-threshold: 80%;
  position: fixed;
  z-index: 10;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 2.2vh, 24px);
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 14% 15%, rgba(255, 255, 255, .92), transparent 28%),
    radial-gradient(circle at 84% 20%, rgba(79, 169, 255, .38), transparent 32%),
    radial-gradient(circle at 50% 100%, rgba(38, 121, 211, .24), transparent 42%),
    repeating-linear-gradient(90deg, rgba(18, 92, 166, .045) 0 1px, transparent 1px 72px),
    repeating-linear-gradient(0deg, rgba(18, 92, 166, .035) 0 1px, transparent 1px 72px),
    linear-gradient(135deg, rgba(239, 248, 255, .98), rgba(185, 218, 249, .97) 52%, rgba(221, 239, 255, .98));
  color: #0b2a55;
  text-align: center;
  -webkit-backdrop-filter: blur(24px) saturate(145%);
  backdrop-filter: blur(24px) saturate(145%);
  overflow: hidden;
}
.campaign-score-card[hidden] { display: none; }
.campaign-score-card::before,
.campaign-score-card::after {
  content: "";
  position: absolute;
  width: min(34vw, 420px);
  aspect-ratio: 1;
  border: 1px solid rgba(32, 119, 207, .16);
  border-radius: 50%;
  box-shadow: 0 0 90px rgba(42, 139, 230, .16);
  pointer-events: none;
}
.campaign-score-card::before { top: -18%; left: -8%; }
.campaign-score-card::after { right: -10%; bottom: -24%; }
.comparison-header { position: relative; z-index: 1; }
.comparison-header p,
.comparison-header h1,
.comparison-result,
#campaignScorePhase { margin: 0; }
.campaign-score-card #campaignScoreEyebrow {
  margin-bottom: 4px;
  color: #1767b8;
  font-size: clamp(.8rem, 1.4vw, 1rem);
  font-weight: 750;
  letter-spacing: .05em;
}
.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-inline-end: 5px;
  border-radius: 50%;
  background: #2588e8;
  box-shadow: 0 0 0 4px rgba(37, 136, 232, .14), 0 0 18px rgba(37, 136, 232, .8);
  animation: live-pulse 900ms ease-in-out infinite;
}
.draw-comparison .comparison-header > p {
  margin-bottom: 4px;
  color: #1767b8;
  font-size: clamp(.8rem, 1.4vw, 1rem);
  font-weight: 750;
  letter-spacing: .05em;
}
.campaign-score-card h1 {
  font-size: clamp(1.35rem, 3vw, 2.5rem);
  line-height: 1.25;
  text-wrap: balance;
}

.heart-duel {
  position: relative;
  z-index: 1;
  width: min(1120px, 92vw);
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(112px, 13vw, 170px) minmax(0, 1fr);
  align-items: center;
  gap: clamp(12px, 2.2vw, 32px);
}

.duel-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .82);
  border-radius: clamp(20px, 2.8vw, 34px);
  background: linear-gradient(145deg, rgba(255,255,255,.78), rgba(224,241,255,.5));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.92), 0 22px 58px rgba(38, 98, 159, .22);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  backdrop-filter: blur(18px) saturate(150%);
  transition: border-color 350ms ease, box-shadow 350ms ease, transform 350ms ease;
}
.campaign-score-card:not([hidden]) .reference-card { animation: rival-enter-left 520ms cubic-bezier(.16,.8,.24,1) both; }
.campaign-score-card:not([hidden]) .user-card { animation: rival-enter-right 520ms cubic-bezier(.16,.8,.24,1) both; }
.campaign-score-card:not([hidden]) .score-arena { animation: arena-enter 620ms 120ms cubic-bezier(.16,.8,.24,1) both; }
.duel-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(120deg, transparent 22%, rgba(255,255,255,.5) 42%, transparent 60%);
  transform: translateX(-120%);
  animation: duel-sheen 2.8s ease-in-out infinite;
  pointer-events: none;
}
.duel-image-frame {
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-bottom: 1px solid rgba(42, 111, 180, .16);
  background: #d6ebff;
}
.duel-image-frame img { display: block; width: 100%; height: 100%; object-fit: cover; }
.reference-card .duel-image-frame img { object-position: 14% 50%; }
.user-card .duel-image-frame img { object-position: 48% 64%; }
.duel-label {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  direction: rtl;
  text-align: right;
}
.duel-label span { color: rgba(29, 70, 116, .72); font-size: clamp(.72rem, 1.1vw, .88rem); }
.duel-label strong { color: #0b2a55; font-size: clamp(.95rem, 1.6vw, 1.2rem); }
.user-card { border-color: rgba(44, 136, 225, .48); box-shadow: inset 0 1px 0 rgba(255,255,255,.92), 0 0 38px rgba(42, 139, 230, .16), 0 24px 60px rgba(38, 98, 159, .2); }

.score-arena {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.score-arena::before,
.score-arena::after {
  content: "✦";
  position: absolute;
  z-index: -1;
  color: #FFD45A;
  text-shadow: 0 0 18px #ffca37;
  animation: arena-spark 1.15s ease-in-out infinite alternate;
}
.score-arena::before { top: 28%; left: -8px; font-size: 1.15rem; }
.score-arena::after { right: -2px; bottom: 24%; font-size: .72rem; animation-delay: -520ms; }
.versus-badge {
  display: grid;
  place-items: center;
  width: 52px;
  height: 34px;
  border: 1px solid rgba(39, 126, 214, .38);
  border-radius: 999px;
  background: rgba(255, 255, 255, .58);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.88), 0 8px 24px rgba(30, 105, 181, .14);
  color: #145fae;
  font-weight: 850;
  letter-spacing: .08em;
}
.score-meter { --score-angle: 0deg; }
.score-ring {
  position: relative;
  width: clamp(104px, 11vw, 150px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(from -90deg, #8dd0ff 0deg, #2385e5 var(--score-angle), rgba(36, 111, 184, .12) var(--score-angle), rgba(36, 111, 184, .12) 360deg);
  box-shadow: 0 14px 42px rgba(31, 111, 191, .24), inset 0 0 0 1px rgba(255,255,255,.78);
}
.score-ring::before {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: inherit;
  background: radial-gradient(circle at 42% 30%, #ffffff, #dceeff 72%);
  box-shadow: inset 0 1px 10px rgba(40, 114, 187, .12);
}
.score-ring > span { position: relative; z-index: 1; display: flex; align-items: baseline; direction: ltr; }
.campaign-score-card #campaignScoreValue {
  color: #0e5da9;
  font-size: clamp(2.35rem, 5.5vw, 4.5rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-shadow: 0 2px 16px rgba(27, 113, 199, .2);
}
.draw-comparison #drawScoreValue {
  color: #0e5da9;
  font-size: clamp(2.35rem, 5.5vw, 4.5rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-shadow: 0 2px 16px rgba(27, 113, 199, .2);
}
.score-ring small { color: #2379ca; font-size: clamp(.9rem, 1.8vw, 1.35rem); font-weight: 800; }
#campaignScorePhase { color: rgba(22, 69, 117, .8); font-size: clamp(.75rem, 1.2vw, .92rem); }
#drawScorePhase { margin: 0; color: rgba(22, 69, 117, .8); font-size: clamp(.75rem, 1.2vw, .92rem); }
.target-progress {
  position: relative;
  width: min(132px, 11vw);
  height: 8px;
  overflow: hidden;
  border: 1px solid rgba(35, 112, 188, .2);
  border-radius: 999px;
  background: rgba(39, 111, 181, .12);
  box-shadow: inset 0 1px 4px rgba(28, 89, 151, .12);
}
.score-progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--score-percent);
  border-radius: inherit;
  background: linear-gradient(90deg, #176bc0, #58b6ff);
  box-shadow: 0 0 14px rgba(35, 133, 229, .42);
  transition: width 80ms linear;
}
.target-progress i {
  position: absolute;
  z-index: 2;
  top: -2px;
  bottom: -2px;
  left: var(--win-threshold);
  width: 2px;
  background: #d49a08;
  box-shadow: 0 0 8px rgba(212, 154, 8, .5);
}
.win-target { color: #155fa9; font-size: clamp(.7rem, 1vw, .8rem); font-weight: 700; white-space: nowrap; }
.comparison-result {
  position: relative;
  z-index: 1;
  min-height: 1.6em;
  max-width: min(760px, 88vw);
  color: #163f6b;
  font-size: clamp(.9rem, 1.5vw, 1.1rem);
  line-height: 1.6;
}
.campaign-score-card[data-outcome="scoring"] .score-ring { animation: score-breathe 1.2s ease-in-out infinite; }
.campaign-score-card[data-outcome="winner"] {
  background: radial-gradient(circle at 50% 43%, rgba(255, 213, 76, .3), transparent 34%), radial-gradient(circle at 12% 16%, rgba(255,255,255,.9), transparent 30%), linear-gradient(135deg, rgba(234, 247, 255, .98), rgba(167, 208, 246, .97));
}
.campaign-score-card[data-outcome="winner"] .user-card { transform: translateY(-5px) scale(1.015); border-color: #e6ad19; box-shadow: inset 0 1px 0 rgba(255,255,255,.92), 0 0 52px rgba(255, 195, 32, .28), 0 28px 70px rgba(35, 96, 157, .24); }
.campaign-score-card[data-outcome="winner"] .score-ring { animation: winner-pop 650ms cubic-bezier(.2,.8,.2,1) both; }
.campaign-score-card[data-outcome="winner"] .score-progress-fill { background: linear-gradient(90deg, #f0b31d, #fff2a8); box-shadow: 0 0 22px #FFD45A; }
.campaign-score-card[data-outcome="winner"] .score-arena::before { content: "✦  ✧  ✦"; left: -34px; font-size: 1.5rem; }
.campaign-score-card[data-outcome="winner"] .score-arena::after { content: "✦  ✧"; right: -26px; font-size: 1.1rem; }
.campaign-score-card[data-outcome="retry"] .score-ring { box-shadow: 0 14px 42px rgba(31, 111, 191, .24); }
.display-page.is-comparing > .app > .status,
.display-page.is-comparing .display-ai-status,
.display-page.is-comparing .view-toggle { opacity: 0; pointer-events: none; }
.comparison-close {
  position: absolute;
  z-index: 4;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: 46px;
  min-height: 46px;
  padding: 0;
  border: 1px solid rgba(31, 105, 179, .2);
  border-radius: 50%;
  background: rgba(255,255,255,.62);
  color: #174f87;
  font-size: 1.8rem;
  line-height: 1;
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}
.draw-page.is-comparing .draw-controls,
.draw-page.is-comparing .campaign-judge,
.draw-page.is-comparing .scene-prompt { opacity: 0; pointer-events: none; }

@keyframes duel-sheen {
  0%, 42% { transform: translateX(-120%); }
  72%, 100% { transform: translateX(120%); }
}
@keyframes score-breathe {
  0%, 100% { transform: scale(.97); filter: brightness(.9); }
  50% { transform: scale(1.025); filter: brightness(1.16); }
}
@keyframes winner-pop {
  0% { transform: scale(.82); }
  58% { transform: scale(1.1); }
  100% { transform: scale(1); }
}
@keyframes live-pulse {
  50% { opacity: .55; transform: scale(.8); }
}
@keyframes rival-enter-left {
  from { opacity: 0; transform: translateX(-56px) rotate(-2deg) scale(.96); }
  to { opacity: 1; transform: none; }
}
@keyframes rival-enter-right {
  from { opacity: 0; transform: translateX(56px) rotate(2deg) scale(.96); }
  to { opacity: 1; transform: none; }
}
@keyframes arena-enter {
  from { opacity: 0; transform: scale(.68); filter: blur(8px); }
  to { opacity: 1; transform: scale(1); filter: none; }
}
@keyframes arena-spark {
  from { opacity: .25; transform: scale(.72) rotate(0); }
  to { opacity: 1; transform: scale(1.2) rotate(25deg); }
}

@media (max-width: 760px), (max-height: 620px) {
  .campaign-score-card { gap: 10px; padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .heart-duel { width: min(1020px, 96vw); grid-template-columns: minmax(0, 1fr) 92px minmax(0, 1fr); gap: 10px; }
  .duel-card { border-radius: 20px; }
  .duel-label { min-height: 46px; padding: 7px 10px; }
  .score-ring { width: 88px; }
  .target-progress { width: 88px; }
  .score-ring::before { inset: 7px; }
  .versus-badge { width: 44px; height: 28px; font-size: .78rem; }
}

@media (max-width: 560px) and (orientation: portrait) {
  .campaign-score-card { justify-content: flex-start; overflow-y: auto; }
  .heart-duel { grid-template-columns: 1fr 72px 1fr; align-items: start; }
  .score-arena { padding-top: 18vw; }
  .duel-image-frame { aspect-ratio: 3 / 4; }
  .duel-label { display: grid; gap: 2px; }
  .score-ring { width: 70px; }
  .target-progress { width: 70px; }
  .score-ring::before { inset: 6px; }
  .score-ring #campaignScoreValue,
  .score-ring #drawScoreValue { font-size: 1.8rem; }
  .score-ring small { font-size: .76rem; }
  #campaignScorePhase { font-size: .7rem; }
}

@media (prefers-reduced-motion: reduce) {
  .duel-card::after,
  .live-dot,
  .campaign-score-card:not([hidden]) .reference-card,
  .campaign-score-card:not([hidden]) .user-card,
  .campaign-score-card:not([hidden]) .score-arena,
  .score-arena::before,
  .score-arena::after,
  .campaign-score-card[data-outcome="scoring"] .score-ring,
  .campaign-score-card[data-outcome="winner"] .score-ring { animation: none; }
}

@media (max-width: 700px) {
  .app { padding: 8px; gap: 8px; }
  .toolbar { align-content: center; }
  .toolbar h1 { width: 100%; }
  .tool input[type="range"] { width: 90px; }
  .rotate-hint { display: none; }
  .app { grid-template-rows: auto auto auto auto minmax(0, 1fr); }
  .ai-panel h2 { width: 100%; }
}

@media (max-width: 760px) {
  .draw-controls { width: calc(100vw - 20px); min-height: 66px; gap: 7px; padding: 7px 8px; border-radius: 24px; }
  .draw-controls .control-button { min-height: 48px; gap: 5px; padding: 6px 10px; border-radius: 17px; font-size: .78rem; }
  .draw-controls .primary-action { min-width: 146px; }
  .draw-controls .control-button svg { width: 18px; height: 18px; }
  .draw-controls .status { min-height: 30px; padding: 0 8px; font-size: .72rem; }
  .draw-controls .compact-switch { gap: 5px; padding-inline: 2px; font-size: .72rem; }
  .switch-track { width: 40px; height: 24px; }
  .switch-thumb { width: 18px; height: 18px; }
  .compact-switch input:checked + .switch-track .switch-thumb { transform: translateX(16px); }
  .draw-controls .status::before { width: 7px; height: 7px; }
}

@media (max-width: 620px) {
  .draw-controls { width: calc(100vw - 16px); }
  .control-meta { position: absolute; right: 4px; bottom: calc(100% + 8px); padding: 3px 5px; border: 1px solid rgba(255,255,255,.2); border-radius: 999px; background: rgba(7,13,28,.54); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
  .control-actions { width: 100%; justify-content: space-between; }
  .draw-controls .control-button { flex: 0 1 auto; }
  .draw-controls .primary-action { flex: 1 1 auto; min-width: 0; }
  .draw-controls .ai-status,
  .draw-controls .ai-countdown { bottom: calc(100% + 56px); }
  .draw-controls .ai-status { right: 0; }
  .draw-controls .ai-countdown { left: 0; }
  .campaign-judge { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 128px); }
}

@media (max-width: 430px) {
  .draw-controls .control-button { width: 48px; padding-inline: 0; }
  .draw-controls .control-button > span { display: none; }
  .draw-controls .primary-action { width: auto; padding-inline: 14px; }
  .draw-controls .primary-action > span { display: inline; }
}

@media (orientation: portrait) {
  body:not(.display-page) .rotate-hint { display: block; }
}

@media (max-width: 700px) and (orientation: landscape) {
  .rotate-hint { display: none; }
  .app { grid-template-rows: auto auto auto auto minmax(0, 1fr); }
  .toolbar { padding: 4px 8px; gap: 6px; }
  .toolbar h1 { display: none; }
  .ai-panel { padding: 4px 8px; gap: 6px; }
  .ai-panel h2 { display: none; }
}
