:root {
  color-scheme: dark;
  --ink: #fff8fa;
  --muted: #cdbdc3;
  --paper: #110d12;
  --panel: rgba(31, 22, 32, 0.94);
  --panel-soft: rgba(255, 255, 255, 0.055);
  --line: rgba(255, 255, 255, 0.15);
  --rose: #ff6f91;
  --rose-deep: #c72e5a;
  --gold: #f1c66a;
  --teal: #5ad1c5;
  --danger: #ff6b72;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.4);
  --radius: 18px;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--paper); }

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 4%, rgba(255, 111, 145, 0.2), transparent 27rem),
    radial-gradient(circle at 92% 8%, rgba(90, 209, 197, 0.12), transparent 24rem),
    linear-gradient(145deg, #100b11, #231520 52%, #101b1d);
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
img { max-width: 100%; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid rgba(241, 198, 106, 0.78); outline-offset: 3px; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 12px; font-size: clamp(2rem, 5vw, 4rem); line-height: 0.98; letter-spacing: -0.045em; }
h2 { margin-bottom: 10px; font-size: clamp(1.25rem, 2.4vw, 1.8rem); letter-spacing: -0.025em; }
h3 { margin-bottom: 8px; }
p { color: var(--muted); line-height: 1.55; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 10px clamp(14px, 4vw, 46px);
  border-bottom: 1px solid var(--line);
  background: rgba(14, 10, 15, 0.82);
  backdrop-filter: blur(18px);
}

.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--ink); text-decoration: none; }
.brand-mark { display: grid; width: 42px; height: 42px; place-items: center; border: 1px solid rgba(255,255,255,.2); border-radius: 14px; color: var(--rose); background: rgba(255,255,255,.06); font-size: 1.65rem; }
.brand strong, .brand small { display: block; }
.brand strong { line-height: 1; font-size: 1.04rem; }
.brand small { margin-top: 3px; color: var(--muted); font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.signed-in { color: var(--muted); font-size: .86rem; }

main { width: min(1500px, 100%); margin: 0 auto; padding: clamp(16px, 3vw, 38px); }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(180deg, rgba(39,27,40,.96), rgba(22,16,23,.95)); box-shadow: var(--shadow); }
.center-card { width: min(560px, 100%); margin: clamp(30px, 9vh, 100px) auto; padding: clamp(24px, 5vw, 46px); }
.status-card { min-height: 220px; display: grid; place-items: center; align-content: center; gap: 16px; text-align: center; }
.status-card p { margin: 0; }
.spinner { width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.14); border-top-color: var(--rose); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.eyebrow { margin-bottom: 8px; color: var(--rose); font-size: .74rem; font-weight: 900; text-transform: uppercase; letter-spacing: .12em; }
.auth-layout { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(320px, .95fr); gap: clamp(24px, 6vw, 88px); align-items: center; min-height: calc(100dvh - 150px); }
.auth-intro { padding: clamp(10px, 4vw, 50px); }
.auth-intro > p:not(.eyebrow) { max-width: 620px; font-size: clamp(1rem, 2vw, 1.25rem); }
.feature-list { display: grid; gap: 12px; margin: 28px 0 0; padding: 0; list-style: none; }
.feature-list li { display: flex; gap: 10px; color: var(--muted); }
.feature-list li::before { content: "♡"; color: var(--gold); font-weight: 900; }
.auth-cards { display: grid; gap: 16px; }
.auth-cards .panel { padding: 25px; }

.form-stack { display: grid; gap: 15px; }
label, .field-label, legend { color: var(--muted); font-size: .84rem; font-weight: 800; }
label small { color: #988a90; font-weight: 600; }
input, select, textarea {
  width: 100%;
  margin-top: 7px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 11px;
  color: var(--ink);
  background: rgba(8,6,9,.72);
}
input, select { min-height: 48px; padding: 0 13px; }
textarea { min-height: 90px; padding: 12px 13px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: rgba(241,198,106,.58); background: rgba(8,6,9,.95); }
input[readonly] { color: var(--muted); }

.button { display: inline-flex; min-height: 45px; align-items: center; justify-content: center; gap: 8px; padding: 0 17px; border: 1px solid transparent; border-radius: 11px; color: white; font-weight: 900; text-decoration: none; transition: transform .16s ease, filter .16s ease, border-color .16s ease; }
.button:hover { transform: translateY(-1px); filter: brightness(1.06); }
.button:disabled { cursor: not-allowed; opacity: .48; transform: none; }
.button-primary { background: linear-gradient(135deg, #ff7898, #cf3562 55%, #9c224c); box-shadow: 0 13px 28px rgba(207,53,98,.25); }
.button-secondary { color: #151013; background: linear-gradient(135deg, #f7d582, #d5a540); }
.button-quiet { border-color: var(--line); color: var(--ink); background: rgba(255,255,255,.06); }
.button-warning { border-color: rgba(241,198,106,.45); color: var(--gold); background: rgba(241,198,106,.08); }
.button-danger { border-color: rgba(255,107,114,.45); color: #ff9ca1; background: rgba(255,107,114,.08); }
.icon-button { display: grid; width: 42px; height: 42px; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: var(--panel-soft); font-size: 1.4rem; }
.form-error { margin: 0; color: #ffadb2; font-size: .86rem; font-weight: 750; }

.studio { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 18px; align-items: start; }
.game-sidebar { position: sticky; top: 90px; overflow: hidden; padding: 16px; }
.sidebar-heading, .section-heading, .modal-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.sidebar-heading h2, .section-heading h2, .modal-heading h2 { margin: 0; }
.game-list { display: grid; gap: 8px; margin-top: 18px; }
.game-list button { width: 100%; padding: 13px; border: 1px solid transparent; border-radius: 12px; color: var(--ink); text-align: left; background: transparent; }
.game-list button:hover, .game-list button.active { border-color: var(--line); background: rgba(255,255,255,.07); }
.game-list strong, .game-list span { display: block; }
.game-list strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-list span { margin-top: 5px; color: var(--muted); font-size: .73rem; }
.studio-main { min-width: 0; }
.empty-studio, .partner-studio { min-height: 480px; display: grid; place-items: center; align-content: center; padding: clamp(30px, 8vw, 90px); text-align: center; }
.empty-studio > span { color: var(--rose); font-size: 4rem; }
.empty-studio p, .partner-studio p { max-width: 620px; }

#editor { display: grid; gap: 14px; }
.editor-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 22px; }
.editor-header h1 { margin: 8px 0 7px; font-size: clamp(1.55rem, 4vw, 2.65rem); }
.editor-header p { margin: 0; }
.editor-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }
.status-line { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: .77rem; }
.status-pill, .usage-pill { display: inline-flex; align-items: center; min-height: 29px; padding: 0 10px; border: 1px solid rgba(90,209,197,.26); border-radius: 999px; color: var(--teal); background: rgba(90,209,197,.08); font-weight: 850; text-transform: capitalize; }
.editor-tabs { display: flex; gap: 5px; overflow-x: auto; padding: 7px; box-shadow: none; }
.tab-button { flex: 1 0 auto; min-height: 43px; padding: 0 14px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; font-weight: 850; }
.tab-button.active { color: var(--ink); background: rgba(255,255,255,.09); }
.tab-panel.panel { padding: clamp(20px, 4vw, 34px); }
.section-heading { margin-bottom: 22px; }
.save-status { color: var(--teal); font-size: .83rem; font-weight: 800; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.full-field { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; }
.theme-field { margin: 0; padding: 0; border: 0; }
.theme-options { display: grid; grid-template-columns: repeat(4, minmax(110px, 1fr)); gap: 10px; margin-top: 9px; }
.theme-option { position: relative; min-height: 115px; overflow: hidden; display: flex; align-items: end; padding: 12px; border: 2px solid transparent; border-radius: 14px; color: white; cursor: pointer; }
.theme-option input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.theme-option:has(input:checked) { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(241,198,106,.15); }
.theme-option span { position: relative; z-index: 1; font-weight: 900; text-shadow: 0 1px 8px rgba(0,0,0,.5); }
.theme-rose { background: radial-gradient(circle at 25% 10%, #ff9cb3, transparent 40%), linear-gradient(135deg,#7b2346,#d94e75); }
.theme-midnight { background: radial-gradient(circle at 70% 20%, #355a8a, transparent 40%), linear-gradient(135deg,#090d22,#27214d); }
.theme-sunset { background: radial-gradient(circle at 30% 20%, #ffc870, transparent 34%), linear-gradient(135deg,#e85c59,#6d275d); }
.theme-scrapbook { background: linear-gradient(135deg,rgba(107,74,45,.18),transparent), repeating-linear-gradient(0deg,#e9dbc4,#e9dbc4 22px,#ddcbb0 23px); color: #3f2d2b; }

.memory-layout { display: grid; grid-template-columns: minmax(300px, .8fr) minmax(340px, 1.2fr); gap: 14px; align-items: start; }
.upload-panel, .library-panel { padding: clamp(18px, 3vw, 28px); }
.photo-picker { min-height: 120px; display: grid; place-items: center; align-content: center; gap: 4px; padding: 18px; border: 1px dashed rgba(241,198,106,.5); border-radius: 13px; text-align: center; cursor: pointer; background: rgba(241,198,106,.05); }
.photo-picker input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.photo-picker span { color: var(--gold); font-size: 1rem; }
.photo-picker small { color: var(--muted); }
.memory-preview { width: 100%; max-height: 320px; border-radius: 13px; object-fit: contain; background: #080608; }
.photo-progress { display: grid; gap: 6px; }
.photo-progress > span, .usage-track { height: 8px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.09); }
.photo-progress > span::after { content: ""; display: block; width: 58%; height: 100%; border-radius: inherit; background: linear-gradient(90deg,var(--rose),var(--gold)); animation: progress 1.1s ease-in-out infinite alternate; }
@keyframes progress { from { transform: translateX(-80%); } to { transform: translateX(155%); } }
.editor-map, .play-map { width: 100%; height: 300px; margin-top: 8px; border: 1px solid var(--line); border-radius: 13px; background: #151217; }
.map-status { margin: 8px 0 0; font-size: .78rem; }
.usage-track { margin: -8px 0 13px; }
.usage-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg,var(--teal),var(--gold),var(--rose)); transition: width .25s ease; }
.upgrade-hint { margin-bottom: 18px; font-size: .83rem; }
.memory-library { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.memory-card { overflow: hidden; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.045); }
.memory-card img { width: 100%; aspect-ratio: 4 / 3; display: block; object-fit: cover; background: #090709; }
.memory-card-copy { padding: 11px; }
.memory-card strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.memory-card span, .memory-card small { display: block; margin-top: 4px; color: var(--muted); font-size: .74rem; }
.memory-card-actions { display: flex; justify-content: flex-end; padding: 0 9px 9px; }
.memory-card-actions button { border: 0; color: #ff9ca1; background: transparent; font-size: .78rem; font-weight: 850; }
.library-empty { grid-column: 1/-1; padding: 44px 18px; border: 1px dashed var(--line); border-radius: 13px; text-align: center; }

.inline-form { display: grid; grid-template-columns: minmax(220px, 1fr) auto; gap: 10px; align-items: end; max-width: 700px; }
.share-result { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-top: 18px; }
.share-result label { flex: 1 1 320px; }
.gift-card { width: min(390px,100%); display: grid; grid-template-columns: 132px 1fr; gap: 18px; align-items: center; margin: 28px 0 0; padding: 18px; border: 1px solid var(--line); border-radius: 15px; background: linear-gradient(135deg,rgba(255,111,145,.1),rgba(241,198,106,.08)); }
.game-qr { width: 132px; height: 132px; overflow: hidden; border-radius: 8px; background: white; }
.game-qr svg { width: 100%; height: 100%; display: block; }
.gift-card figcaption strong, .gift-card figcaption span { display: block; }
.gift-card figcaption span { margin-top: 7px; color: var(--muted); font-size: .82rem; }
.gift-card figcaption .gift-heart { margin: 0 0 8px; color: var(--rose); font-size: 2.2rem; line-height: 1; }
hr { height: 1px; margin: 30px 0; border: 0; background: var(--line); }
.plan-card { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel-soft); }
.plan-card strong, .plan-card span { display: block; }
.plan-card span { margin-top: 5px; color: var(--muted); }
.plan-options { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 10px; margin-top: 14px; }
.plan-option { padding: 17px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.04); }
.plan-option strong, .plan-option span { display: block; }
.plan-option span { margin-top: 5px; color: var(--muted); font-size: .8rem; }
.manage-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }

.modal { width: min(560px, calc(100% - 24px)); padding: 0; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); background: #211722; box-shadow: 0 30px 100px rgba(0,0,0,.7); }
.modal::backdrop { background: rgba(3,2,4,.76); backdrop-filter: blur(8px); }
.modal form { padding: 25px; }
#editMemoryDialog form { max-height: min(820px,calc(100dvh - 40px)); overflow-y: auto; }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.toast { position: fixed; z-index: 2000; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: calc(100% - 30px); padding: 13px 18px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: #231923; box-shadow: var(--shadow); font-weight: 800; }

/* Partner play */
.play-body[data-theme="midnight"] { background: radial-gradient(circle at 70% 4%,rgba(71,112,173,.28),transparent 30rem),linear-gradient(145deg,#060919,#15132f 55%,#080c1b); }
.play-body[data-theme="sunset"] { background: radial-gradient(circle at 22% 5%,rgba(255,198,102,.28),transparent 30rem),linear-gradient(145deg,#321329,#79283f 55%,#2b1830); }
.play-body[data-theme="scrapbook"] { --ink:#382b2b; --muted:#705e59; --line:rgba(64,42,34,.2); --panel:rgba(247,237,219,.94); color-scheme:light; background: repeating-linear-gradient(0deg,#e9dcc5,#e9dcc5 26px,#decdb0 27px); }
.play-body[data-theme="scrapbook"] .site-header { background: rgba(235,221,198,.88); }
.play-body[data-theme="scrapbook"] .panel { background: rgba(248,239,223,.95); }
.play-shell { width: min(1180px, 100%); }
.welcome-screen { min-height: min(680px, calc(100dvh - 140px)); display: grid; place-items: center; align-content: center; padding: clamp(28px, 8vw, 90px); text-align: center; }
.welcome-screen h1 { max-width: 850px; }
.welcome-message { max-width: 680px; font-size: clamp(1.05rem,2.3vw,1.35rem); white-space: pre-line; }
.welcome-facts { display: flex; flex-wrap: wrap; justify-content: center; gap: 9px; margin: 10px 0 28px; }
.welcome-facts span { padding: 7px 11px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .78rem; font-weight: 800; background: var(--panel-soft); }
.round-screen { display: grid; gap: 14px; }
.round-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 17px 21px; }
.round-heading h1 { margin: 0; font-size: clamp(1.25rem,4vw,2rem); }
.round-heading .eyebrow { margin-bottom: 5px; }
.round-heading > strong { color: var(--gold); font-size: clamp(1.5rem,5vw,2.8rem); }
.round-layout { display: grid; grid-template-columns: minmax(0,1.05fr) minmax(340px,.95fr); gap: 14px; }
.photo-round-panel { min-height: 640px; display: grid; place-items: center; overflow: hidden; padding: 12px; }
.photo-round-panel img { width: 100%; height: 100%; max-height: 720px; object-fit: contain; border-radius: 12px; background: #070607; }
.guess-panel { display: grid; align-content: start; gap: 16px; padding: 20px; }
.play-map { height: 380px; }
.date-guess-label input { min-height: 58px; font-size: 1.05rem; color-scheme: dark; }
.play-body[data-theme="scrapbook"] .date-guess-label input { color-scheme: light; }
.reveal-screen, .completed-screen { width: min(820px,100%); margin: 0 auto; padding: clamp(25px,5vw,48px); text-align: center; }
.score-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 9px; margin: 25px 0; }
.score-grid div { padding: 14px 9px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-soft); }
.score-grid span, .score-grid strong { display: block; }
.score-grid span { color: var(--muted); font-size: .73rem; }
.score-grid strong { margin-top: 5px; }
.big-score, .final-play-score { display: block; margin: 10px 0 24px; color: var(--gold); font-size: clamp(2.4rem,8vw,5rem); line-height: 1; }
.completed-rounds { display: grid; gap: 8px; margin: 24px 0; text-align: left; }
.completed-round { display: grid; grid-template-columns: 38px minmax(0,1fr) auto; gap: 10px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-soft); }
.completed-round > span:first-child { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 50%; color: var(--rose); background: rgba(255,111,145,.1); font-weight: 900; }
.completed-round strong, .completed-round small { display: block; }
.completed-round small { margin-top: 3px; color: var(--muted); }

@media (max-width: 980px) {
  .auth-layout, .studio, .memory-layout, .round-layout { grid-template-columns: 1fr; }
  .game-sidebar { position: static; }
  .game-list { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .round-layout { display: flex; flex-direction: column; }
  .photo-round-panel { min-height: 420px; }
}

@media (max-width: 680px) {
  main { padding: 10px; }
  .site-header { min-height: 62px; padding: 8px 10px; }
  .brand-mark { width: 38px; height: 38px; }
  .signed-in { display: none; }
  .studio { gap: 10px; }
  .game-sidebar, .editor-header, .tab-panel.panel, .upload-panel, .library-panel { border-radius: 14px; }
  .game-list { grid-template-columns: 1fr; }
  .editor-header { display: block; padding: 18px; }
  .editor-actions { justify-content: flex-start; margin-top: 16px; }
  .editor-actions .button { flex: 1; }
  .settings-grid { grid-template-columns: 1fr; }
  .full-field { grid-column: auto; }
  .theme-options, .memory-library, .plan-options { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .inline-form { grid-template-columns: 1fr; }
  .photo-round-panel { min-height: 300px; }
  .play-map, .editor-map { height: 280px; }
  .score-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .two-fields { grid-template-columns: 1fr; }
}

@media print {
  body { color: #261820; background: white !important; }
  .site-header, .game-sidebar, .editor-tabs, .editor-header, [data-tab-panel]:not(#inviteTab), #partnerInviteForm, #partnerInviteResult, .button { display: none !important; }
  main, .studio, .studio-main { display: block; width: 100%; padding: 0; }
  #editor, #inviteTab { display: block !important; }
  #inviteTab { min-height: 90vh; display: grid !important; place-items: center; align-content: center; border: 4px double #b34c6c; box-shadow: none; text-align: center; }
  #inviteTab input { border: 0; color: #261820; background: white; text-align: center; }
  .gift-card { margin-inline: auto; color: #261820; background: white; break-inside: avoid; }
}
