:root {
  --ink: #f4ead6;
  --ink-soft: #c9bfa9;
  --panel: rgba(18, 22, 38, 0.78);
  --line: rgba(244, 234, 214, 0.22);
  --sun: #ffb648;
  --moon: #62d6cc;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #141a2b; color: var(--ink);
  font-family: var(--serif);
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#ui { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; padding: 16px; }
[hidden] { display: none !important; }

.panel {
  pointer-events: auto;
  width: min(360px, 100%);
  padding: 28px 26px 24px;
  display: flex; flex-direction: column; gap: 12px; align-items: stretch; text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: rise 0.35s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.logo {
  margin: 0; font-size: 54px; font-weight: 600; letter-spacing: 1px; line-height: 1;
  background: linear-gradient(100deg, var(--sun) 10%, #fff3d6 50%, var(--moon) 90%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 2px 30px rgba(255, 190, 110, 0.18);
}
.logo.has-art { background: none; height: 120px; color: transparent; text-shadow: none;
  background-image: url(assets/logo.webp); background-size: contain; background-repeat: no-repeat; background-position: center; }
h2 { margin: 0; font-size: 40px; font-weight: 600; }
h2.win { color: var(--sun); }
h2.lose { color: var(--ink-soft); }
.tagline { margin: 0 0 10px; color: var(--ink-soft); font-style: italic; font-size: 16px; }
.label { margin: 0; color: var(--ink-soft); font-size: 14px; letter-spacing: 2px; text-transform: uppercase; }
.code { margin: 0; font-size: 64px; letter-spacing: 10px; padding-left: 10px; font-weight: 600; color: var(--sun);
  -webkit-user-select: text; user-select: text; }
.waiting { margin: 6px 0; color: var(--ink-soft); font-style: italic; }
.dots::after { content: ""; animation: dots 1.6s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.msg { margin: 0; min-height: 20px; font-size: 14px; color: #ffb0a0; }

button, input {
  font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 16px; min-height: 46px;
  background: rgba(255, 255, 255, 0.07);
}
button { cursor: pointer; transition: background 0.15s, transform 0.08s, border-color 0.15s; }
button:hover { background: rgba(255, 255, 255, 0.14); border-color: rgba(244, 234, 214, 0.4); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--sun); outline-offset: 2px; }
button.primary {
  background: linear-gradient(180deg, #ffc566, #e8973a); color: #2a1a08; font-weight: 600;
  border-color: rgba(255, 220, 160, 0.7); font-size: 18px;
  box-shadow: 0 6px 18px rgba(232, 151, 58, 0.3);
}
button.primary:hover { background: linear-gradient(180deg, #ffd083, #f0a044); }
button.quiet { background: transparent; border-color: transparent; color: var(--ink-soft); }
button.quiet:hover { color: var(--ink); background: rgba(255, 255, 255, 0.06); }
#f-join { display: flex; gap: 8px; }
#i-code { flex: 1; min-width: 0; text-align: center; letter-spacing: 6px; text-transform: uppercase; font-size: 18px;
  -webkit-user-select: text; user-select: text; }
#i-code::placeholder { color: rgba(244, 234, 214, 0.35); letter-spacing: 4px; }

#banner {
  position: fixed; top: max(14px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 18px; border-radius: 999px; font-size: 15px; text-align: center;
  background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(8px);
}
#corner {
  position: fixed; right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom));
  display: flex; gap: 6px; pointer-events: auto;
}
.chip { min-height: 34px; padding: 6px 12px; font-size: 13px; border-radius: 999px; background: rgba(18, 22, 38, 0.6); color: var(--ink-soft); }

@media (max-height: 560px) {
  .panel { padding: 16px 20px; gap: 8px; }
  .logo { font-size: 40px; } .logo.has-art { height: 80px; }
  .code { font-size: 46px; }
}
@media (prefers-reduced-motion: reduce) { .panel { animation: none; } }

/* ---- Loading, story and ceremony ---- */
.bare {
  pointer-events: auto; width: min(420px, 100%);
  display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;
}
#load-ring { width: 240px; height: 240px; }
#s-loading .logo { font-size: 60px; animation: shimmer 5s ease-in-out infinite; background-size: 220% 100%; }
@keyframes shimmer { 0%, 100% { background-position: 0% 0; } 50% { background-position: 100% 0; } }
#s-title .logo { animation: shimmer 7s ease-in-out infinite; background-size: 220% 100%; }
.logo.has-art { animation: none !important; background-size: contain !important; }
#load-line { min-height: 22px; transition: opacity 0.4s; }
#b-enter { min-width: 220px; transition: opacity 0.9s, transform 0.9s, visibility 0s; animation: breathe 2.4s ease-in-out infinite; }
#b-enter.ghost { visibility: hidden; opacity: 0; transform: translateY(8px); animation: none; }
@keyframes breathe { 0%, 100% { box-shadow: 0 6px 18px rgba(232, 151, 58, 0.3); } 50% { box-shadow: 0 6px 34px rgba(255, 190, 110, 0.75); } }
button.small { min-height: 30px; padding: 4px 10px; font-size: 13px; font-style: italic; }

.story {
  pointer-events: auto; cursor: pointer;
  position: fixed; inset: 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  padding: 0 24px max(34px, env(safe-area-inset-bottom));
}
#story-text {
  margin: 0 0 22px; max-width: 760px; text-align: center;
  font-size: clamp(22px, 3.6vw, 36px); line-height: 1.35; font-style: italic;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.9), 0 0 40px rgba(0, 0, 0, 0.6);
  min-height: 2.7em;
}
#story-text .w { display: inline-block; white-space: pre; }
#story-text .l { display: inline-block; opacity: 0; animation: letter 0.7s ease-out forwards; }
@keyframes letter { from { opacity: 0; filter: blur(6px); transform: translateY(6px); } to { opacity: 1; filter: none; transform: none; } }
.story-nav { display: flex; align-items: center; gap: 18px; }
#story-dots { display: flex; gap: 8px; }
#story-dots i { width: 7px; height: 7px; border-radius: 50%; background: rgba(244, 234, 214, 0.3); transition: background 0.5s, box-shadow 0.5s; }
#story-dots i.on { background: var(--sun); box-shadow: 0 0 10px var(--sun); }

#versus {
  position: fixed; left: 0; right: 0; top: 27%; transform: translateY(-50%);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: baseline; gap: 4px 18px;
  padding: 26px 20px 22px; pointer-events: none;
  background: linear-gradient(90deg, rgba(10, 10, 24, 0), rgba(10, 10, 24, 0.82) 22%, rgba(10, 10, 24, 0.82) 78%, rgba(10, 10, 24, 0));
  animation: versus 2.9s ease-in-out forwards;
  font-size: clamp(22px, 4.2vw, 44px); font-weight: 600;
}
#versus .v-sun { text-align: right; color: var(--sun); text-shadow: 0 0 26px rgba(255, 182, 72, 0.6); animation: from-left 2.9s cubic-bezier(0.2, 0.9, 0.2, 1) forwards; }
#versus .v-moon { text-align: left; color: var(--moon); text-shadow: 0 0 26px rgba(98, 214, 204, 0.6); animation: from-right 2.9s cubic-bezier(0.2, 0.9, 0.2, 1) forwards; }
#versus em { font-size: 0.5em; font-weight: 400; color: var(--ink-soft); }
#versus small { grid-column: 1 / -1; text-align: center; font-size: 0.42em; font-weight: 400; font-style: italic; color: var(--ink-soft); }
@keyframes versus { 0% { opacity: 0; } 12%, 78% { opacity: 1; } 100% { opacity: 0; } }
@keyframes from-left { 0% { transform: translateX(-60px); } 25%, 100% { transform: none; } }
@keyframes from-right { 0% { transform: translateX(60px); } 25%, 100% { transform: none; } }

h2.win { text-shadow: 0 0 34px rgba(255, 190, 110, 0.7); animation: crown 1.2s ease-out; }
@keyframes crown { from { letter-spacing: 14px; opacity: 0; filter: blur(8px); } }

#veil { position: fixed; inset: 0; background: radial-gradient(circle at 50% 50%, #2a2440, #080916 75%); opacity: 0; pointer-events: none; transition: opacity 0.33s ease-in-out; }
#veil.on { opacity: 1; pointer-events: auto; }

@media (max-height: 620px) {
  #load-ring { width: 170px; height: 170px; }
  #s-loading .logo { font-size: 42px; }
}
@media (prefers-reduced-motion: reduce) {
  #story-text .l { animation: none; opacity: 1; }
  #versus .v-sun, #versus .v-moon { animation: none; }
}
