:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --ink: #3e2a1c;
  --cream: #fff4d8;
  --cream-2: #f6e3b8;
  --wood: #7a4427;
  --blue: #276ca5;
  --green: #54a72d;
  --gold: #f4c34c;
  --shadow: 0 10px 24px rgba(31, 18, 10, .26);
  font-family: "Nunito", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #1c3f52; }
body { overscroll-behavior: none; touch-action: manipulation; }
button, input { font: inherit; }
button { user-select: none; }
img { user-select: none; -webkit-user-drag: none; }
[hidden] { display: none !important; }
body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after { animation: none !important; transition: none !important; }
body.compact-ui .resource-chip { min-width: 52px; font-size: .72rem; }
body.compact-ui .resource-chip img { width: 24px; height: 24px; }
body.compact-ui .game-footer { height: calc(74px + var(--safe-bottom)); }
body.compact-ui .nav-button { grid-template-rows: 36px auto; }
body.compact-ui .nav-button img { width: 34px; height: 34px; }

.app-shell { position: fixed; inset: 0; width: 100%; height: 100dvh; overflow: hidden; }
.screen { position: absolute; inset: 0; visibility: hidden; opacity: 0; pointer-events: none; transition: opacity .2s ease; }
.screen.is-active { visibility: visible; opacity: 1; pointer-events: auto; }

.start-screen {
  display: grid;
  place-items: end center;
  padding: calc(24px + var(--safe-top)) 20px calc(32px + var(--safe-bottom));
  background: center / cover no-repeat url('../assets/runtime/backgrounds/background_start_portrait.webp');
}
.start-shade { position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(17,35,45,.08) 0 42%, rgba(24,25,17,.34) 80%, rgba(20,21,16,.62)); }
.start-logo { position: absolute; top: calc(5vh + var(--safe-top)); left: 50%; width: min(80vw, 680px); transform: translateX(-50%); filter: drop-shadow(0 8px 16px rgba(0,0,0,.28)); }
.start-actions { position: relative; width: min(92vw, 430px); padding: 22px 22px 18px; display: grid; gap: 12px; justify-items: center; text-align: center; }
.glass-card { border: 1px solid rgba(255,255,255,.45); border-radius: 24px; background: rgba(255,244,216,.86); box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.start-kicker { font-size: .72rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; color: #8d5a34; }
.start-title { margin: -2px 0 0; font-family: "Baloo 2", "Nunito", sans-serif; font-size: clamp(1.8rem, 5vw, 2.35rem); line-height: .95; color: #6b3f23; }
.start-copy { margin: 0; max-width: 32ch; font-size: .95rem; line-height: 1.34; color: rgba(62,42,28,.86); }
.start-player-summary { width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 16px; background: rgba(255,255,255,.56); border: 1px solid rgba(122,68,39,.14); text-align: left; }
.start-player-summary .summary-text { min-width: 0; display: grid; gap: 2px; }
.start-player-summary strong { font-size: .96rem; }
.start-player-summary small { opacity: .72; }
.start-player-hint { text-align: center; font-weight: 900; color: #5a3923; }
.start-button-stack { width: 100%; display: grid; gap: 10px; justify-items: center; }
.version-label { text-align: center; font-size: .78rem; opacity: .65; margin-top: 2px; }
.text-button { border: 0; background: transparent; color: #6a4028; font-weight: 800; padding: 6px; cursor: pointer; }
.start-logout-button { margin-top: -6px; }

.ef-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: min(100%, var(--button-width, 230px));
  aspect-ratio: var(--button-ratio, 399 / 154);
  min-height: 0;
  border: 0;
  background-color: transparent;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  color: var(--button-ink, #fff);
  font-family: "Baloo 2", "Nunito", sans-serif;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.04;
  text-align: center;
  text-shadow: 0 2px 2px rgba(50,28,13,.38);
  cursor: pointer;
  padding: 0 30px 3px;
  filter: drop-shadow(0 5px 6px rgba(45,25,11,.22));
  transition: transform .08s ease, filter .08s ease;
  white-space: normal;
}
.ef-button:active { transform: translateY(2px) scale(.99); filter: drop-shadow(0 2px 3px rgba(45,25,11,.18)); }
.ef-button:disabled { opacity: .5; filter: grayscale(.5); pointer-events: none; }

/* Fixed artwork families. Ratios mirror the source assets so raster buttons are never stretched. */
.ef-button-green { background-image: url('../assets/runtime/content/ui/buttons/button_primary_medium_v2.webp'); --button-ratio: 399 / 154; }
.ef-button-blue { background-image: url('../assets/runtime/content/ui/buttons/button_action_blue_wide_v2.webp'); --button-ratio: 414 / 162; }
.ef-button-parchment { background-image: url('../assets/runtime/content/ui/buttons/button_secondary_medium_v2.webp'); --button-ratio: 326 / 154; --button-ink: #5b321c; text-shadow: none; }
.ef-button-gold { background-image: url('../assets/runtime/content/ui/buttons/button_purchase_coins_v2.webp'); --button-ratio: 358 / 173; --button-ink: #5b321c; text-shadow: 0 1px rgba(255,255,255,.55); }

.ef-button-small { --button-width: 168px; font-size: .82rem; padding-inline: 22px; }
.ef-button-medium { --button-width: 230px; font-size: .96rem; }
.ef-button-large { --button-width: 285px; font-size: 1.08rem; }

.ef-button-green.ef-button-small { background-image: url('../assets/runtime/content/ui/buttons/button_primary_small_v2.webp'); --button-ratio: 304 / 150; }
.ef-button-green.ef-button-medium { background-image: url('../assets/runtime/content/ui/buttons/button_primary_medium_v2.webp'); --button-ratio: 399 / 154; }
.ef-button-green.ef-button-large { background-image: url('../assets/runtime/content/ui/buttons/button_primary_large_v2.webp'); --button-ratio: 436 / 173; }
.ef-button-blue.ef-button-small { background-image: url('../assets/runtime/content/ui/buttons/button_action_blue_small_v2.webp'); --button-ratio: 351 / 147; }
.ef-button-parchment.ef-button-small { background-image: url('../assets/runtime/content/ui/buttons/button_secondary_small_v2.webp'); --button-ratio: 334 / 153; }
.ef-button-parchment.ef-button-medium { background-image: url('../assets/runtime/content/ui/buttons/button_secondary_medium_v2.webp'); --button-ratio: 326 / 154; }
.ef-button-parchment.ef-button-large { background-image: url('../assets/runtime/content/ui/buttons/button_secondary_large_v2.webp'); --button-ratio: 392 / 156; }

.ef-button-two-line {
  background-image: url('../assets/runtime/content/ui/buttons/button_upgrade_v2.webp');
  --button-ratio: 373 / 235;
  --button-width: 132px;
  --button-ink: #fff;
  flex-direction: column;
  gap: 1px;
  padding: 8px 18px 10px;
  line-height: 1;
}
.ef-button-two-line > span { display: block; }
.ef-button-wide {
  background-image: url('../assets/runtime/content/ui/buttons/button_action_blue_wide_v2.webp');
  --button-ratio: 414 / 162;
  --button-width: 220px;
}


.game-screen { background: #75b5d0; }
.game-backdrop { position: absolute; inset: 0; background: center / cover no-repeat url('../assets/runtime/backgrounds/background_gameplay_portrait.webp'); }
.game-backdrop::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(255,255,255,.02), rgba(255,255,255,.02) 48%, rgba(44,31,18,.12)); pointer-events: none; }
.game-topbar { position: absolute; z-index: 20; top: 0; left: 0; right: 0; height: calc(66px + var(--safe-top)); padding: calc(8px + var(--safe-top)) 10px 8px; display: grid; grid-template-columns: minmax(104px, 1fr) auto 44px; gap: 8px; align-items: center; background: linear-gradient(to bottom, rgba(26,52,57,.42), rgba(26,52,57,0)); }
.profile-chip { min-width: 0; border: 0; background: rgba(26,54,68,.74); border-radius: 24px; padding: 4px 8px 4px 4px; display: flex; align-items: center; color: white; box-shadow: 0 3px 8px rgba(0,0,0,.2); cursor: pointer; }
.avatar-stack { position: relative; display: inline-block; flex: 0 0 auto; overflow: hidden; border-radius: 50%; background: #e8d0a0; }
.avatar-stack-small { width: 46px; height: 46px; border: 2px solid #f3c44f; }
.avatar-image { width: 100%; height: 100%; object-fit: cover; object-position: center 20%; }
.hat-image { position: absolute; z-index: 2; width: 94%; left: 50%; top: -6%; transform: translateX(-50%); pointer-events: none; }
.profile-text { min-width: 0; display: grid; text-align: left; line-height: 1.05; margin-left: 5px; font-size: .72rem; }
.profile-text strong { font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 92px; }
.resource-strip { display: flex; gap: 5px; justify-content: center; }
.resource-chip { min-width: 54px; height: 34px; padding: 3px 8px 3px 4px; border-radius: 18px; background: rgba(30,56,69,.82); border: 2px solid rgba(244,195,76,.74); color: white; display: flex; align-items: center; gap: 4px; font-weight: 800; font-size: .78rem; box-shadow: 0 3px 7px rgba(0,0,0,.18); }
.resource-chip img { width: 27px; height: 27px; object-fit: contain; }
.icon-button { width: 42px; height: 42px; padding: 2px; border: 0; border-radius: 12px; background: rgba(33,78,105,.8); cursor: pointer; }
.icon-button img { width: 100%; height: 100%; object-fit: contain; }

.game-content { position: absolute; z-index: 5; top: calc(62px + var(--safe-top)); bottom: calc(76px + var(--safe-bottom)); left: 0; right: 0; overflow: hidden; }
.game-footer { position: absolute; z-index: 30; left: 0; right: 0; bottom: 0; height: calc(78px + var(--safe-bottom)); padding: 5px 5px calc(5px + var(--safe-bottom)); display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 3px; background: rgba(37,51,60,.92); border-top: 2px solid rgba(244,195,76,.78); box-shadow: 0 -5px 14px rgba(28,20,12,.22); }
.nav-button { min-width: 0; border: 0; border-radius: 13px; background: linear-gradient(#426d8b,#294b67); color: white; padding: 4px 1px 3px; display: grid; place-items: center; grid-template-rows: 42px auto; font-weight: 800; font-size: clamp(.58rem,2.6vw,.72rem); line-height: 1; cursor: pointer; }
.nav-button img { width: 40px; height: 40px; object-fit: contain; }
.nav-button.is-active { outline: 2px solid #f4cf64; background: linear-gradient(#3f8b79,#2d6a5d); box-shadow: inset 0 0 14px rgba(255,226,115,.28); }

.scene-panel { position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center; padding: 8px; }
.scene-card { width: min(94vw, 820px); max-height: 100%; overflow: auto; border-radius: 22px; background: rgba(255,244,216,.92); border: 3px solid rgba(111,65,35,.9); box-shadow: var(--shadow); padding: 16px; scrollbar-width: thin; }
.scene-title { font-family: "Baloo 2", sans-serif; font-size: 1.35rem; margin: 0 0 8px; }
.scene-subtitle { margin: 0 0 12px; opacity: .72; }
.scene-section { margin-top: 14px; }
.scene-section:first-of-type { margin-top: 0; }
.section-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.section-header h3 { margin: 0; }
.section-note { font-size: .78rem; opacity: .72; }
.kpi-strip { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; margin-bottom: 10px; }
.kpi-card { background: rgba(255,255,255,.72); border: 1px solid rgba(111,65,35,.12); border-radius: 14px; padding: 10px; }
.kpi-card strong { display: block; font-size: 1rem; }
.kpi-card small { opacity: .72; }
.card-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.content-card { background: rgba(255,255,255,.68); border: 1px solid rgba(111,65,35,.18); border-radius: 16px; padding: 10px; min-width: 0; }
.content-card img { width: 100%; max-height: 150px; object-fit: contain; }
.content-card h3 { margin: 5px 0 3px; font-size: 1rem; }
.content-card p { margin: 0; font-size: .86rem; }
.content-card .card-action { margin-top: 8px; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; padding: 5px 8px; border-radius: 999px; background: rgba(90,133,53,.12); color: #4f6d2f; font-size: .75rem; font-weight: 800; }
.status-pill.is-blue { background: rgba(49,111,179,.12); color: #2b5e99; }
.status-pill.is-gold { background: rgba(209,155,23,.15); color: #8b6110; }
.empty-note { margin: 0; padding: 14px; border-radius: 14px; background: rgba(255,255,255,.62); border: 1px dashed rgba(111,65,35,.26); font-size: .9rem; }
.character-preview { display: grid; grid-template-columns: 120px 1fr; gap: 14px; align-items: center; margin-bottom: 12px; }
.avatar-stack-large { width: 120px; height: 145px; border-radius: 20px; border: 3px solid #c49452; background: #ecd7ad; }
.avatar-stack-large .avatar-image { object-position: center top; }
.avatar-stack-large .hat-image { top: -3%; width: 90%; }

.merge-scene { position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center; padding: 3px 6px 5px; }
.merge-stage { width: min(96vw, 700px); display: grid; gap: 4px; justify-items: stretch; }
.merge-board-wrap { position: relative; width: 100%; aspect-ratio: 1322 / 1190; filter: drop-shadow(0 8px 10px rgba(28,20,12,.28)); touch-action: none; }
.merge-board-image { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.merge-cell { position: absolute; transform: translate(-50%, -50%); width: 8.85%; aspect-ratio: 1.07; border: 0; background: transparent; padding: 0; display: grid; place-items: center; cursor: pointer; touch-action: none; border-radius: 14%; }
.merge-cell.is-selected { outline: 3px solid rgba(255,215,73,.95); box-shadow: 0 0 14px rgba(255,219,73,.85); background: rgba(255,229,105,.16); }
.merge-cell.is-drop-target { outline: 2px dashed rgba(86,185,255,.9); }
.merge-item { width: 78%; height: 78%; object-fit: contain; filter: drop-shadow(0 3px 2px rgba(52,32,16,.23)); pointer-events: none; }
.merge-item.chest-ready { animation: chestPulse 1.1s ease-in-out infinite alternate; }
@keyframes chestPulse { from { filter: drop-shadow(0 2px 2px rgba(52,32,16,.2)); } to { filter: drop-shadow(0 0 9px rgba(255,207,75,.9)); transform: scale(1.04); } }
.merge-detail { min-height: 76px; border-radius: 17px; background: rgba(255,244,216,.95); border: 2px solid #8a5837; box-shadow: 0 5px 10px rgba(33,23,14,.2); padding: 7px 10px; display: grid; grid-template-columns: 52px 1fr auto; gap: 8px; align-items: center; }
.merge-detail .detail-icon { width: 52px; height: 52px; object-fit: contain; }
.merge-detail h3 { margin: 0; font-size: .92rem; }
.merge-detail p { margin: 2px 0 0; font-size: .72rem; line-height: 1.2; opacity: .75; }
.merge-detail-actions { display: flex; gap: 5px; flex-wrap: wrap; }
.merge-detail .ef-button { width: 150px; min-width: 0; font-size: .8rem; padding-inline: 24px; }
.merge-hint { text-align: center; font-size: .72rem; color: white; text-shadow: 0 1px 3px rgba(0,0,0,.7); font-weight: 800; }

.modal-root { position: absolute; z-index: 100; inset: 0; pointer-events: none; }
.modal-root.is-open { pointer-events: auto; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(16,25,27,.58); backdrop-filter: blur(4px); display: grid; place-items: center; padding: calc(14px + var(--safe-top)) 14px calc(14px + var(--safe-bottom)); }
.modal-panel { position: relative; width: min(92vw, 620px); max-height: min(88dvh, 760px); overflow: auto; border-radius: 24px; background: #fff3d6; border: 5px solid #7a4427; box-shadow: 0 16px 38px rgba(0,0,0,.42), inset 0 0 0 2px #e5b94b; padding: 22px 18px 18px; }
.modal-panel.modal-wide { width: min(96vw, 880px); }
.modal-panel h2 { margin: 0 34px 10px 0; font-family: "Baloo 2", sans-serif; font-size: 1.55rem; }
.modal-panel h3 { margin: 14px 0 6px; }
.modal-close { position: absolute; top: 8px; right: 9px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: #b84b37; color: white; font-weight: 900; cursor: pointer; }
.form-grid { display: grid; gap: 10px; }
.form-field { display: grid; gap: 4px; font-weight: 800; }
.form-field input { width: 100%; height: 48px; border-radius: 12px; border: 2px solid #c69a5a; background: #fffdf5; padding: 8px 12px; outline: none; color: var(--ink); }
.form-field input:focus { border-color: #4f8fbd; box-shadow: 0 0 0 3px rgba(79,143,189,.15); }
.pin-input { letter-spacing: .55em; text-align: center; font-size: 1.25rem; font-weight: 800; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; justify-content: flex-end; }
.modal-actions .ef-button { width: min(100%, var(--button-width, 185px)); min-width: 0; }
.avatar-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; }
.avatar-choice { position: relative; border: 2px solid #bd9357; border-radius: 16px; background: #f7e6c4; overflow: hidden; padding: 0; aspect-ratio: .82; cursor: pointer; }
.avatar-choice img { width: 100%; height: 100%; object-fit: cover; object-position: center top; }
.avatar-choice.is-selected { border-color: #eab73d; box-shadow: 0 0 0 3px rgba(234,183,61,.35), inset 0 0 22px rgba(255,218,91,.3); }
.option-list { display: grid; gap: 8px; }
.option-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; border-radius: 13px; background: rgba(255,255,255,.55); padding: 10px 12px; }
.option-row strong { display: block; }
.option-row small { opacity: .7; }
.option-group-title { margin-top: 10px; font-size: .9rem; font-weight: 900; color: #7c4928; letter-spacing: .02em; }
.changelog-entry { border-top: 1px solid rgba(110,72,40,.18); padding: 10px 0; }
.changelog-entry:first-child { border-top: 0; }
.changelog-entry h3 { margin: 0 0 2px; }
.changelog-entry ul { margin: 6px 0 0 20px; padding: 0; }
.dev-status { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; margin-bottom: 12px; }
.dev-kpi { background: rgba(255,255,255,.62); border-radius: 12px; padding: 9px; }
.file-input { display: grid; gap: 6px; border: 2px dashed #bd9357; border-radius: 14px; padding: 12px; background: rgba(255,255,255,.46); }
.backup-list { display: grid; gap: 7px; }
.backup-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; background: rgba(255,255,255,.52); padding: 8px 10px; border-radius: 12px; }

.toast-root { position: absolute; z-index: 150; left: 50%; bottom: calc(92px + var(--safe-bottom)); transform: translateX(-50%); display: grid; gap: 7px; width: min(88vw, 420px); pointer-events: none; }
.toast { border-radius: 15px; padding: 10px 14px; color: white; background: rgba(34,55,65,.94); border: 1px solid rgba(255,255,255,.22); box-shadow: 0 8px 18px rgba(0,0,0,.28); font-weight: 800; animation: toastIn .2s ease; text-align: center; }
.toast.error { background: rgba(150,53,43,.96); }
.toast.success { background: rgba(49,119,66,.96); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }
.loading-cover { position: absolute; z-index: 200; inset: 0; display: grid; place-items: center; align-content: center; gap: 12px; color: white; font-weight: 800; background: #24526a; transition: opacity .25s ease, visibility .25s ease; }
.loading-cover.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-orb { width: 42px; height: 42px; border-radius: 50%; border: 5px solid rgba(255,255,255,.25); border-top-color: #f2c84f; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 700px) {
  .game-topbar { grid-template-columns: 230px 1fr 50px; padding-inline: 18px; }
  .profile-text strong { max-width: 160px; }
  .resource-strip { justify-self: center; gap: 10px; }
  .resource-chip { min-width: 98px; font-size: .95rem; }
  .game-footer { left: 50%; right: auto; width: min(760px, 94vw); transform: translateX(-50%); border: 2px solid rgba(244,195,76,.78); border-bottom: 0; border-radius: 18px 18px 0 0; }
  .nav-button { font-size: .75rem; }
  .avatar-grid { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .card-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .kpi-strip { grid-template-columns: repeat(3,minmax(0,1fr)); }
}

@media (orientation: landscape), (min-width: 980px) {
  .start-screen { background-image: url('../assets/runtime/backgrounds/background_start_landscape.webp'); }
  .start-logo { top: calc(3vh + var(--safe-top)); width: min(48vw, 650px); }
  .start-actions { width: min(390px, 42vw); justify-self: end; margin-right: 8vw; margin-bottom: 6vh; }
  .game-backdrop { background-image: url('../assets/runtime/backgrounds/background_gameplay_landscape.webp'); }
  .game-content { top: calc(68px + var(--safe-top)); bottom: calc(80px + var(--safe-bottom)); }
  .merge-scene { justify-content: center; align-items: center; padding-top: 16px; }
  .merge-stage { width: min(58vw, 720px); grid-template-columns: minmax(0,1fr) 230px; grid-template-rows: auto 26px; gap: 10px; align-items: center; }
  .merge-board-wrap { grid-row: 1 / span 2; }
  .merge-detail { grid-column: 2; min-height: 180px; grid-template-columns: 72px 1fr; grid-template-rows: auto auto; align-content: center; }
  .merge-detail .detail-icon { width: 70px; height: 70px; }
  .merge-detail-actions { grid-column: 1 / -1; justify-content: center; }
  .merge-hint { grid-column: 2; }
  .scene-panel { align-items: center; }
  .scene-card { max-height: 90%; }
}

@media (max-width: 460px) {
  .start-actions { padding-inline: 16px; }
  .start-copy { font-size: .9rem; }
  .modal-actions .ef-button,
  .ef-button-large,
  .ef-button-medium { width: 100%; }
  .ef-button-small { width: min(100%, 220px); }
  .character-preview { grid-template-columns: 1fr; text-align: center; }
  .character-preview > *:first-child { justify-self: center; }
  .kpi-strip { grid-template-columns: 1fr; }
}

/* alpha.5 manually separated UI assets */
.inventory-grid { align-items: start; }
.inventory-entry { text-align: center; }
.inventory-slot-visual {
  position: relative;
  width: min(100%, 150px);
  aspect-ratio: 1 / 1;
  margin: 0 auto 4px;
  display: grid;
  place-items: center;
  background: center / 100% 100% no-repeat url('../assets/runtime/ui/components/inventory_slot_empty.webp');
}
.inventory-slot-visual.is-active { background-image: url('../assets/runtime/ui/components/inventory_slot_active.webp'); }
.inventory-slot-visual > img { width: 62%; height: 62%; object-fit: contain; filter: drop-shadow(0 3px 2px rgba(49,31,17,.18)); }
.inventory-slot-count { position: absolute; right: 11%; bottom: 10%; min-width: 32px; padding: 2px 7px; border-radius: 999px; color: white; background: rgba(43,61,72,.84); font-size: .72rem; font-weight: 900; box-shadow: 0 2px 4px rgba(0,0,0,.2); }
.inventory-entry.is-equipped { box-shadow: inset 0 0 0 2px rgba(244,195,76,.4); }
.profile-details { min-width: 0; }
.xp-progress { position: relative; width: min(100%, 250px); aspect-ratio: 3 / 1; margin: 5px 0 2px; }
.xp-progress img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; }
.xp-progress-value { z-index: 2; }

/* Beta 1: compact character creation and playtest guidance */
.avatar-modal {
  width: min(96vw, 960px) !important;
  max-height: min(94dvh, 760px) !important;
  overflow: hidden !important;
  padding: 14px 16px 12px !important;
}
.avatar-modal h2 { margin-bottom: 2px; font-size: 1.35rem; }
.avatar-modal > p { margin: 0 40px 9px 0; font-size: .88rem; line-height: 1.25; }
.avatar-modal .avatar-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 7px; }
.avatar-modal .avatar-choice { aspect-ratio: .86; min-height: 0; max-height: 28dvh; border-radius: 12px; }
.avatar-modal .modal-actions { margin-top: 9px; justify-content: center; }
.avatar-modal .modal-actions .ef-button { width: 230px; }

.playtest-goals {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin: 0 0 10px;
}
.playtest-goal {
  min-width: 0;
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 6px;
  align-items: center;
  padding: 7px 8px;
  border-radius: 12px;
  background: rgba(255,255,255,.62);
  border: 1px solid rgba(111,65,35,.14);
  font-size: .7rem;
  line-height: 1.15;
}
.playtest-goal > span {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #cba865;
  color: #fff;
  font-weight: 900;
}
.playtest-goal.is-done { background: rgba(94,157,69,.14); color: #486534; }
.playtest-goal.is-done > span { background: #5b9d49; }
.active-boost {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(77,143,210,.14);
  border: 1px solid rgba(47,111,178,.22);
  color: #2c5f93;
  font-weight: 800;
  font-size: .82rem;
}

@media (max-width: 640px) {
  .avatar-modal {
    width: min(97vw, 560px) !important;
    max-height: 96dvh !important;
    padding: 11px 10px 10px !important;
  }
  .avatar-modal h2 { font-size: 1.18rem; }
  .avatar-modal > p { margin-right: 34px; margin-bottom: 7px; font-size: .78rem; }
  .avatar-modal .avatar-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
  .avatar-modal .avatar-choice { max-height: 21dvh; border-radius: 9px; }
  .avatar-modal .modal-actions { margin-top: 7px; }
  .avatar-modal .modal-actions .ef-button { width: min(78vw, 230px); }
  .playtest-goals { grid-template-columns: 1fr 1fr; }
  .playtest-goal:last-child { grid-column: 1 / -1; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .avatar-modal { max-height: 96dvh !important; padding-block: 8px !important; }
  .avatar-modal h2 { font-size: 1.05rem; }
  .avatar-modal > p { display: none; }
  .avatar-modal .avatar-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
  .avatar-modal .avatar-choice { max-height: 31dvh; }
  .avatar-modal .modal-actions { margin-top: 4px; }
}

/* beta.2 desktop/mobile sizing pass, compact options and two-step character creation */
.options-modal {
  width: min(92vw, 640px) !important;
  max-height: min(94dvh, 720px) !important;
  overflow: hidden !important;
  padding: 16px 16px 14px !important;
}
.options-modal h2 { margin-bottom: 6px; font-size: 1.35rem; }
.compact-option-list { gap: 6px; }
.compact-option-list .option-group-title { margin-top: 4px; font-size: .82rem; }
.compact-option-list .option-row { min-height: 52px; padding: 8px 11px; }
.compact-option-list .option-row strong { font-size: .95rem; }
.compact-option-list .option-row small { display: block; margin-top: 1px; font-size: .76rem; line-height: 1.1; }
.option-build-row { min-height: 48px !important; }
.options-action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-top: 4px;
}
.options-action-grid .ef-button {
  width: 100%;
  max-width: none;
  aspect-ratio: 3.15 / 1;
  font-size: .8rem;
  padding-inline: 22px;
}
.option-logout { justify-self: center; margin-top: -2px; font-size: .86rem; }

.creator-step {
  margin: 0 42px 1px 0;
  color: #99633b;
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.creator-modal { overflow: hidden !important; }
.creator-actions { margin-top: 8px !important; justify-content: center !important; }
.creator-actions .ef-button { width: min(100%, 230px) !important; }
.creator-actions-split { display: grid !important; grid-template-columns: repeat(2, minmax(0, 230px)); justify-content: center !important; }

.avatar-modal {
  width: min(94vw, 920px) !important;
  max-height: min(92dvh, 680px) !important;
  padding: 12px 14px 10px !important;
}
.avatar-modal h2 { font-size: 1.25rem; line-height: 1; }
.avatar-modal > p { margin-bottom: 7px; font-size: .8rem; line-height: 1.18; }
.avatar-modal .avatar-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.avatar-modal .avatar-choice { aspect-ratio: .88; max-height: 24dvh; border-radius: 10px; }

.hat-modal {
  width: min(94vw, 880px) !important;
  max-height: min(92dvh, 650px) !important;
  overflow: hidden !important;
  padding: 13px 15px 11px !important;
}
.hat-modal h2 { margin-bottom: 3px; font-size: 1.28rem; }
.hat-modal > p { margin: 0 40px 9px 0; font-size: .82rem; line-height: 1.2; }
.starter-hat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.starter-hat-choice {
  min-width: 0;
  border: 2px solid #bd9357;
  border-radius: 14px;
  background: rgba(255,248,229,.86);
  padding: 7px;
  display: grid;
  grid-template-rows: minmax(118px, 1fr) auto;
  gap: 5px;
  color: var(--ink);
  cursor: pointer;
  text-align: center;
}
.starter-hat-choice.is-selected {
  border-color: #e6b634;
  box-shadow: 0 0 0 3px rgba(234,183,61,.3), inset 0 0 22px rgba(255,218,91,.2);
  background: rgba(255,249,218,.98);
}
.starter-hat-preview {
  position: relative;
  display: block;
  width: min(100%, 150px);
  aspect-ratio: .88;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 12px;
  background: #ecd7ad;
}
.starter-avatar { width: 100%; height: 100%; object-fit: cover; object-position: center top; }
.starter-hat { position: absolute; left: 50%; top: -4%; width: 92%; transform: translateX(-50%); pointer-events: none; }
.starter-hat-text { display: grid; gap: 2px; }
.starter-hat-text strong { font-size: .86rem; }
.starter-hat-text small { font-size: .68rem; line-height: 1.12; opacity: .72; }
.reset-actions { justify-content: center; }

.city-card { width: min(94vw, 980px); }
.city-card .content-card { padding: 8px; }
.city-card .content-card img { max-height: 92px; }
.city-card .content-card h3 { font-size: .92rem; }
.city-card .content-card p { font-size: .78rem; line-height: 1.2; }
.city-card .status-pill { font-size: .7rem; }

@media (orientation: landscape), (min-width: 980px) {
  .merge-scene { align-items: center; padding: 8px 16px; }
  .merge-stage {
    width: min(95vw, 1180px);
    grid-template-columns: auto minmax(250px, 300px);
    grid-template-rows: auto auto;
    justify-content: center;
    gap: 12px;
  }
  .merge-board-wrap {
    width: auto;
    height: min(74dvh, 760px);
    aspect-ratio: 1322 / 1190;
    grid-row: 1 / span 2;
    justify-self: end;
  }
  .merge-detail {
    grid-column: 2;
    min-height: 210px;
    grid-template-columns: 76px 1fr;
    grid-template-rows: auto auto;
    align-content: center;
  }
  .merge-detail .detail-icon { width: 74px; height: 74px; }
  .merge-detail-actions { grid-column: 1 / -1; justify-content: center; }
  .merge-hint { grid-column: 2; }
  .city-card .card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .city-card .kpi-strip { gap: 7px; }
  .city-card .scene-section { margin-top: 10px; }
}

@media (max-width: 640px) {
  .options-modal {
    width: min(96vw, 560px) !important;
    max-height: 96dvh !important;
    padding: 12px 10px 10px !important;
  }
  .options-modal h2 { font-size: 1.18rem; }
  .compact-option-list { gap: 5px; }
  .compact-option-list .option-row { min-height: 46px; padding: 7px 9px; }
  .compact-option-list .option-row strong { font-size: .88rem; }
  .compact-option-list .option-row small { font-size: .68rem; }
  .options-action-grid { gap: 5px; }
  .options-action-grid .ef-button { aspect-ratio: 2.75 / 1; font-size: .72rem; padding-inline: 16px; }

  .avatar-modal { width: 97vw !important; max-height: 95dvh !important; padding: 9px 8px 8px !important; }
  .avatar-modal h2 { font-size: 1.08rem; }
  .avatar-modal > p { font-size: .7rem; margin-bottom: 5px; }
  .avatar-modal .avatar-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
  .avatar-modal .avatar-choice { max-height: 19dvh; border-radius: 8px; }

  .hat-modal { width: 97vw !important; max-height: 95dvh !important; padding: 10px 8px 8px !important; }
  .hat-modal h2 { font-size: 1.08rem; }
  .hat-modal > p { font-size: .7rem; margin-bottom: 6px; }
  .starter-hat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
  .starter-hat-choice { grid-template-rows: minmax(84px, 13dvh) auto; padding: 5px; border-radius: 10px; }
  .starter-hat-preview { width: min(100%, 110px); }
  .starter-hat-text strong { font-size: .76rem; }
  .starter-hat-text small { font-size: .61rem; }
  .creator-actions-split { grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .creator-actions .ef-button { width: 100% !important; font-size: .72rem; }

  .city-card .content-card img { max-height: 78px; }
}

@media (max-height: 600px) and (orientation: landscape) {
  .options-modal { max-height: 97dvh !important; padding-block: 9px !important; }
  .compact-option-list .option-row { min-height: 40px; padding-block: 5px; }
  .compact-option-list .option-group-title { margin-top: 1px; }
  .avatar-modal, .hat-modal { max-height: 97dvh !important; }
  .avatar-modal > p, .hat-modal > p { display: none; }
  .avatar-modal .avatar-choice { max-height: 29dvh; }
  .starter-hat-choice { grid-template-rows: minmax(88px, 26dvh) auto; }
}

/* beta.3 compact fixed-screen city/inventory layouts */
.compact-screen-card {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.compact-screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
}
.compact-screen-header .scene-title { margin-bottom: 0; }
.compact-screen-header .scene-subtitle { margin: 1px 0 0; font-size: .78rem; }

.city-scene,
.inventory-scene { align-items: center; }
.city-card,
.inventory-card {
  width: min(96vw, 1100px);
  height: min(100%, 690px);
  max-height: 100%;
  padding: 12px;
}
.city-dashboard {
  min-height: 0;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(260px, .8fr) minmax(0, 1.45fr);
  gap: 10px;
  margin-top: 8px;
}
.city-overview {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(92px, 1fr);
  gap: 8px;
}
.city-goals {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  margin: 0;
}
.city-goals .playtest-goal {
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 5px 3px;
  text-align: center;
  border-radius: 10px;
}
.city-goals .playtest-goal span {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: .72rem;
}
.city-goals .playtest-goal strong {
  font-size: .62rem;
  line-height: 1.05;
  white-space: nowrap;
}
.city-kpis { gap: 5px; margin: 0; }
.city-kpis .kpi-card { padding: 7px 8px; border-radius: 11px; }
.city-kpis .kpi-card strong { font-size: .95rem; }
.city-kpis .kpi-card small { font-size: .64rem; }
.city-focus-card {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(70px, 105px) 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: rgba(255,255,255,.68);
  border: 1px solid rgba(111,65,35,.18);
  border-radius: 14px;
}
.city-focus-card img { width: 100%; height: 100%; max-height: 108px; object-fit: contain; }
.city-focus-copy { min-width: 0; display: grid; gap: 2px; }
.city-focus-copy strong { font-size: .92rem; }
.city-focus-copy small { font-size: .7rem; opacity: .7; }
.city-focus-card .ef-button { width: 120px; }
.city-building-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.compact-building-card {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(86px, 38%) 1fr;
  align-items: center;
  gap: 7px;
  padding: 8px;
  border-radius: 14px;
  background: rgba(255,255,255,.7);
  border: 1px solid rgba(111,65,35,.16);
  overflow: hidden;
}
.compact-building-card img { width: 100%; height: 100%; max-height: 150px; object-fit: contain; }
.compact-building-card > div { min-width: 0; display: grid; align-content: center; gap: 4px; }
.compact-building-card h3 { margin: 0; font-size: .9rem; }
.compact-building-card p { margin: 0; font-size: .7rem; line-height: 1.15; }
.compact-building-card .status-pill { margin: 0; width: fit-content; font-size: .65rem; }
.compact-building-card .ef-button { width: min(100%, 138px); font-size: .7rem; }

.inventory-card { max-width: 1040px; }
.inventory-tabs {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 6px;
  margin: 8px 0;
}
.inventory-tab {
  min-width: 0;
  border: 1px solid rgba(111,65,35,.22);
  border-radius: 12px;
  background: rgba(255,255,255,.56);
  color: var(--ink);
  padding: 7px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-weight: 900;
  cursor: pointer;
}
.inventory-tab small {
  min-width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(40,77,101,.12);
  font-size: .66rem;
}
.inventory-tab.is-active {
  background: linear-gradient(#4d86ac,#315d7d);
  color: #fff;
  border-color: #f1c860;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.inventory-tab.is-active small { background: rgba(255,255,255,.17); }
.inventory-tab-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: grid;
  align-content: start;
}
.inventory-compact-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(0,1fr));
  gap: 8px;
  align-content: start;
}
.inventory-compact-entry {
  min-width: 0;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 4px;
  padding: 6px;
  border-radius: 12px;
  background: rgba(255,255,255,.63);
  border: 1px solid rgba(111,65,35,.14);
  text-align: center;
}
.inventory-compact-entry .inventory-slot-visual { width: min(100%, 112px); }
.inventory-compact-entry strong { font-size: .69rem; line-height: 1.05; }
.inventory-empty { align-self: center; justify-self: stretch; }
.booster-compact-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.booster-compact-entry,
.hat-compact-entry {
  min-width: 0;
  display: grid;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 13px;
  background: rgba(255,255,255,.66);
  border: 1px solid rgba(111,65,35,.15);
}
.booster-compact-entry { grid-template-columns: 1fr auto; }
.booster-compact-entry > div { min-width: 0; display: grid; gap: 2px; }
.booster-compact-entry strong { font-size: .84rem; }
.booster-compact-entry small { font-size: .68rem; line-height: 1.15; opacity: .72; }
.booster-compact-entry .ef-button { width: 130px; }
.compact-active-boost { margin: 0 0 7px; font-size: .76rem; }
.hat-compact-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 8px; }
.hat-compact-entry {
  grid-template-columns: 70px 1fr;
  grid-template-rows: auto auto;
}
.hat-compact-entry .inventory-slot-visual { grid-row: 1 / span 2; width: 70px; }
.hat-compact-entry > div { min-width: 0; display: grid; gap: 2px; }
.hat-compact-entry strong { font-size: .76rem; line-height: 1.05; }
.hat-compact-entry small { font-size: .62rem; line-height: 1.05; opacity: .72; }
.hat-compact-entry .ef-button,
.hat-compact-entry .status-pill { grid-column: 2; margin: 0; width: min(100%, 130px); font-size: .66rem; justify-self: start; }

@media (max-width: 900px) {
  .city-card,
  .inventory-card { width: min(97vw, 760px); height: min(100%, 760px); padding: 9px; }
  .city-dashboard { grid-template-columns: 1fr; grid-template-rows: auto minmax(0,1fr); gap: 7px; }
  .city-overview { grid-template-columns: 1fr; grid-template-rows: auto auto auto; gap: 5px; }
  .city-focus-card { min-height: 78px; grid-template-columns: 76px 1fr auto; padding: 5px 7px; }
  .city-focus-card img { max-height: 72px; }
  .city-building-grid { gap: 5px; }
  .compact-building-card { grid-template-columns: 72px 1fr; padding: 5px; gap: 5px; }
  .compact-building-card img { max-height: 90px; }
  .compact-building-card h3 { font-size: .78rem; }
  .compact-building-card p { font-size: .62rem; }
  .compact-building-card .ef-button { font-size: .63rem; width: 120px; }
  .inventory-compact-grid { grid-template-columns: repeat(4, minmax(0,1fr)); gap: 6px; }
  .hat-compact-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 6px; }
}

@media (max-width: 560px) {
  .compact-screen-header .scene-subtitle { display: none; }
  .city-card,
  .inventory-card { height: 100%; max-height: 100%; border-radius: 18px; }
  .city-goals .playtest-goal { padding: 3px 1px; }
  .city-goals .playtest-goal span { width: 20px; height: 20px; font-size: .62rem; }
  .city-goals .playtest-goal strong { font-size: .53rem; }
  .city-kpis .kpi-card { padding: 5px; }
  .city-focus-card { grid-template-columns: 60px 1fr auto; }
  .city-focus-card .ef-button { width: 105px; font-size: .65rem; }
  .city-building-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .compact-building-card { grid-template-columns: 56px 1fr; }
  .compact-building-card img { max-height: 72px; }
  .compact-building-card p { display: none; }
  .compact-building-card h3 { font-size: .72rem; }
  .compact-building-card .ef-button { width: 100px; font-size: .58rem; padding-inline: 18px; }
  .inventory-tabs { gap: 4px; margin: 5px 0; }
  .inventory-tab { padding: 5px 3px; gap: 4px; font-size: .68rem; }
  .inventory-tab small { width: 18px; min-width: 18px; height: 18px; font-size: .55rem; }
  .inventory-compact-grid { grid-template-columns: repeat(3, minmax(0,1fr)); gap: 5px; }
  .inventory-compact-entry { padding: 4px; }
  .inventory-compact-entry .inventory-slot-visual { width: min(100%, 92px); }
  .inventory-compact-entry strong { font-size: .59rem; }
  .booster-compact-grid { grid-template-columns: 1fr; gap: 5px; }
  .booster-compact-entry { padding: 6px; }
  .booster-compact-entry .ef-button { width: 110px; font-size: .62rem; }
  .hat-compact-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 5px; }
  .hat-compact-entry { grid-template-columns: 54px 1fr; padding: 5px; gap: 5px; }
  .hat-compact-entry .inventory-slot-visual { width: 54px; }
  .hat-compact-entry strong { font-size: .65rem; }
  .hat-compact-entry small { font-size: .55rem; }
  .hat-compact-entry .ef-button { width: 100px; font-size: .58rem; }
}

@media (max-height: 680px) and (min-width: 901px) {
  .city-card,
  .inventory-card { height: 100%; }
  .compact-screen-header .scene-subtitle { display: none; }
  .city-dashboard { margin-top: 5px; }
  .city-goals .playtest-goal { padding-block: 3px; }
  .city-focus-card { min-height: 80px; }
  .compact-building-card img { max-height: 112px; }
  .inventory-compact-entry .inventory-slot-visual { width: min(100%, 90px); }
}

/* 0.3.0 beta gameplay expansion */
.avatar-stack .hat-image,
.avatar-stack-large .hat-image {
  left: var(--hat-left, 50%);
  top: var(--hat-top, -10%);
  width: var(--hat-width, 103%);
  transform: translateX(-50%);
  transform-origin: 50% 80%;
}
.starter-hat {
  left: var(--hat-left, 50%);
  top: var(--hat-top, -10%);
  width: var(--hat-width, 103%);
  transform: translateX(-50%);
  transform-origin: 50% 80%;
}
.starter-hat-preview .starter-avatar { object-position: center top; }
.no-mtx-note {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(85,145,66,.12);
  border: 1px solid rgba(75,126,57,.2);
  color: #416233;
  font-size: .72rem;
  line-height: 1.2;
}
.no-mtx-note strong { font-size: .78rem; }

.merge-stage-v2 { width: min(98vw, 760px); }
.merge-side-panel {
  min-width: 0;
  display: grid;
  gap: 6px;
  align-content: start;
}
.merge-status {
  display: grid;
  gap: 6px;
  padding: 8px;
  border-radius: 16px;
  background: rgba(255,244,216,.95);
  border: 2px solid #8a5837;
  box-shadow: 0 5px 10px rgba(33,23,14,.18);
}
.merge-level-row { display: grid; grid-template-columns: minmax(92px, auto) 1fr; gap: 8px; align-items: center; }
.merge-level-row > div:first-child { display: grid; line-height: 1.05; }
.merge-level-row strong { font-size: .82rem; }
.merge-level-row small { font-size: .62rem; opacity: .66; }
.merge-level-bar { height: 9px; border-radius: 999px; background: #d8c7a6; overflow: hidden; box-shadow: inset 0 1px 2px rgba(69,43,22,.2); }
.merge-level-bar span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(#56b9f6,#287bc4); transition: width .22s ease; }
.merge-stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 4px; }
.merge-stat-grid > div { display: grid; justify-items: center; padding: 4px 3px; border-radius: 9px; background: rgba(255,255,255,.55); }
.merge-stat-grid strong { font-size: .78rem; }
.merge-stat-grid small { font-size: .56rem; opacity: .7; }
.merge-supply-button {
  border: 1px solid rgba(92,64,35,.24);
  border-radius: 11px;
  background: linear-gradient(#f9efcf,#ead8ad);
  color: var(--ink);
  padding: 6px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 900;
}
.merge-supply-button small { font-size: .58rem; opacity: .7; font-weight: 800; }
.merge-supply-button:disabled { opacity: .62; cursor: default; }
.merge-side-panel .merge-detail {
  grid-column: auto;
  min-height: 0;
  grid-template-columns: 58px 1fr;
  grid-template-rows: auto auto;
  padding: 8px;
}
.merge-side-panel .merge-detail .detail-icon { width: 56px; height: 56px; }
.merge-side-panel .merge-detail-actions { grid-column: 1 / -1; justify-content: center; gap: 5px; }
.merge-side-panel .merge-detail-actions .ef-button { min-width: 0; width: auto; flex: 1 1 120px; }
.merge-task-list {
  display: grid;
  gap: 5px;
  padding: 8px;
  border-radius: 16px;
  background: rgba(255,244,216,.94);
  border: 2px solid #8a5837;
  box-shadow: 0 5px 10px rgba(33,23,14,.16);
}
.merge-task-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.merge-task-title strong { font-size: .78rem; }
.merge-task-title small { font-size: .55rem; opacity: .65; }
.merge-task {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto auto;
  gap: 6px;
  align-items: center;
  padding: 5px 6px;
  border-radius: 10px;
  background: rgba(255,255,255,.52);
  border: 1px solid rgba(111,65,35,.12);
}
.merge-task > div { min-width: 0; display: grid; line-height: 1.05; }
.merge-task strong { font-size: .66rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.merge-task small { font-size: .55rem; opacity: .65; }
.merge-task > span { font-size: .55rem; opacity: .72; white-space: nowrap; }
.merge-task button { min-width: 46px; border: 0; border-radius: 9px; padding: 5px 7px; background: #448f37; color: white; font-size: .58rem; font-weight: 900; cursor: pointer; }
.merge-task button:disabled { background: #b7aa91; cursor: default; }
.merge-task.is-done { background: rgba(105,169,72,.14); border-color: rgba(78,139,52,.28); }
.merge-drag-ghost {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  object-fit: contain;
  transform: translate(-50%, -58%) scale(1.06);
  filter: drop-shadow(0 10px 8px rgba(34,21,12,.34));
  opacity: .96;
}
.merge-cell.is-dragging .merge-item { opacity: .24; transform: scale(.9); }
.merge-cell.is-drop-target { outline: 3px solid rgba(61,164,241,.95); background: rgba(94,182,247,.18); box-shadow: 0 0 12px rgba(82,177,245,.55); }
.merge-cell.is-new .merge-item { animation: mergeSpawn .58s cubic-bezier(.18,.9,.25,1.2); }
.merge-cell.is-merged .merge-item { animation: mergePop .5s cubic-bezier(.2,.9,.3,1.25); }
@keyframes mergeSpawn { 0% { transform: scale(.1) translateY(-16%); opacity: .1; } 70% { transform: scale(1.14); opacity: 1; } 100% { transform: scale(1); } }
@keyframes mergePop { 0% { transform: scale(.78); } 45% { transform: scale(1.22); filter: drop-shadow(0 0 12px rgba(255,215,76,.95)); } 100% { transform: scale(1); } }

.screen-tabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0,1fr);
  gap: 6px;
  flex: 0 0 auto;
  margin: 7px 0;
}
.screen-tab {
  min-width: 0;
  min-height: 38px;
  border: 1px solid rgba(111,65,35,.2);
  border-radius: 11px;
  background: rgba(255,255,255,.56);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 900;
  cursor: pointer;
}
.screen-tab small { opacity: .66; font-size: .66rem; }
.screen-tab.is-active { background: linear-gradient(#4d86ac,#315d7d); color: white; border-color: #efc65c; }
.screen-tab-refresh { max-width: 46px; font-size: 1.1rem; }
.city-card-v2, .production-card { width: min(96vw, 1080px); height: min(100%, 690px); max-height: 100%; overflow: hidden; }
.city-header-v2 { flex: 0 0 auto; }
.city-header-kpis { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.city-header-kpis span { padding: 5px 7px; border-radius: 9px; background: rgba(255,255,255,.56); font-size: .62rem; white-space: nowrap; }
.city-tab-content { flex: 1 1 auto; min-height: 0; display: grid; align-content: stretch; overflow: hidden; }
.field-grid-v2 { min-height: 0; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; }
.field-card-v2 { min-width: 0; min-height: 0; display: grid; grid-template-rows: minmax(0,1fr) auto auto; gap: 5px; padding: 8px; border-radius: 14px; background: rgba(255,255,255,.67); border: 1px solid rgba(111,65,35,.15); }
.field-card-visual { position: relative; min-height: 0; display: grid; place-items: center; }
.field-card-visual img { width: min(88%,170px); height: min(100%,180px); object-fit: contain; }
.field-number { position: absolute; top: 2px; left: 2px; padding: 3px 6px; border-radius: 8px; background: rgba(62,42,28,.72); color: white; font-size: .58rem; font-weight: 900; }
.field-card-main { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 6px; }
.field-card-main > div { min-width: 0; display: grid; }
.field-card-main strong { font-size: .8rem; }
.field-card-main small { font-size: .62rem; opacity: .7; }
.field-card-main .ef-button { width: 105px; font-size: .66rem; min-height: 36px; }
.crop-choice-row { display: flex; flex-wrap: wrap; gap: 3px; }
.crop-choice { min-width: 0; flex: 1 1 64px; border: 1px solid rgba(111,65,35,.16); border-radius: 9px; background: rgba(255,255,255,.55); padding: 3px 4px; display: flex; align-items: center; justify-content: center; gap: 3px; color: var(--ink); cursor: pointer; }
.crop-choice img { width: 22px; height: 22px; object-fit: contain; }
.crop-choice span { font-size: .55rem; font-weight: 800; }
.crop-choice.is-active { border-color: #d8a83c; background: rgba(255,231,143,.5); box-shadow: inset 0 0 0 1px rgba(211,161,48,.24); }
.building-grid-v2 { min-height: 0; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; }
.building-card-v2 { min-width: 0; min-height: 0; display: grid; grid-template-rows: minmax(0,1fr) auto; gap: 4px; padding: 8px; border-radius: 14px; background: rgba(255,255,255,.68); border: 1px solid rgba(111,65,35,.15); }
.building-card-v2 > img { width: 100%; height: 100%; max-height: 250px; object-fit: contain; }
.building-card-copy { min-width: 0; display: grid; gap: 4px; }
.building-title-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.building-title-row h3 { margin: 0; font-size: .85rem; }
.building-title-row span { font-size: .58rem; opacity: .7; white-space: nowrap; }
.building-card-copy p { margin: 0; min-height: 30px; font-size: .63rem; line-height: 1.15; }
.building-actions { min-height: 38px; display: flex; align-items: center; }
.building-actions .ef-button { width: min(100%,150px); font-size: .64rem; min-height: 36px; }
.city-stock-strip, .production-stock-strip { flex: 0 0 auto; display: flex; justify-content: center; gap: 4px; margin-top: 6px; }
.city-stock-strip span, .production-stock-strip span { min-width: 48px; padding: 3px 6px; border-radius: 9px; background: rgba(255,255,255,.58); display: flex; align-items: center; justify-content: center; gap: 3px; font-size: .62rem; }
.city-stock-strip img, .production-stock-strip img { width: 24px; height: 24px; object-fit: contain; }

.production-scene { align-items: center; }
.production-focus-v2 { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(190px,.62fr) minmax(0,1.6fr); gap: 8px; overflow: hidden; }
.production-building-panel { min-height: 0; display: grid; grid-template-rows: minmax(0,1fr) auto auto auto; gap: 5px; padding: 8px; border-radius: 14px; background: rgba(255,255,255,.65); border: 1px solid rgba(111,65,35,.15); }
.production-building-panel > img { width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.production-building-panel h3 { margin: 0; font-size: .9rem; }
.production-building-panel p { margin: 0; font-size: .65rem; }
.production-building-panel .ef-button { width: 100%; min-height: 35px; font-size: .64rem; }
.production-job { display: grid; gap: 1px; padding: 6px 7px; border-radius: 10px; background: rgba(72,127,177,.12); color: #2c5f93; }
.production-job strong { font-size: .7rem; }
.production-job small { font-size: .6rem; }
.production-job.is-idle { background: rgba(88,151,63,.12); color: #4e6c37; }
.recipe-list-v2 { min-height: 0; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 6px; align-content: stretch; overflow: hidden; }
.recipe-card-v2 { min-width: 0; min-height: 0; display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 6px; padding: 6px; border-radius: 12px; background: rgba(255,255,255,.62); border: 1px solid rgba(111,65,35,.14); }
.recipe-card-v2 > img { width: 54px; height: 54px; object-fit: contain; }
.recipe-copy { min-width: 0; display: grid; gap: 1px; }
.recipe-copy strong { font-size: .7rem; }
.recipe-copy small { font-size: .55rem; line-height: 1.1; opacity: .68; }
.recipe-copy span { font-size: .57rem; font-weight: 800; color: #5b7b39; }
.recipe-card-v2 .ef-button { width: 88px; min-height: 34px; font-size: .6rem; }
.recipe-card-v2.is-ready { background: rgba(236,250,226,.72); border-color: rgba(88,151,63,.22); }

@media (orientation: landscape), (min-width: 980px) {
  .merge-stage-v2 {
    width: min(97vw, 1320px);
    grid-template-columns: minmax(0, 820px) minmax(300px, 350px);
    grid-template-rows: minmax(0,1fr) auto;
    gap: 10px;
    align-items: center;
  }
  .merge-stage-v2 .merge-board-wrap {
    width: auto;
    height: min(79dvh, 825px);
    grid-row: 1 / span 2;
    justify-self: end;
  }
  .merge-side-panel {
    grid-column: 2;
    grid-row: 1;
    align-self: stretch;
    max-height: min(79dvh,825px);
    grid-template-rows: auto auto 1fr;
  }
  .merge-stage-v2 .merge-hint { grid-column: 2; grid-row: 2; }
  .merge-side-panel .merge-detail { min-height: 155px; }
  .merge-task-list { align-content: start; }
}

@media (max-width: 900px) {
  .field-grid-v2, .building-grid-v2 { grid-template-columns: repeat(3,minmax(0,1fr)); gap: 5px; }
  .field-card-v2, .building-card-v2 { padding: 5px; }
  .crop-choice span { display: none; }
  .production-focus-v2 { grid-template-columns: 145px minmax(0,1fr); gap: 5px; }
  .recipe-list-v2 { gap: 4px; }
  .recipe-card-v2 { grid-template-columns: 44px 1fr; grid-template-rows: auto auto; gap: 3px; padding: 4px; }
  .recipe-card-v2 > img { width: 42px; height: 42px; grid-row: 1 / span 2; }
  .recipe-card-v2 .ef-button { grid-column: 2; width: 100%; min-height: 30px; }
}

@media (max-width: 640px) {
  .merge-stage-v2 { width: min(98vw, 560px); gap: 4px; }
  .merge-side-panel { gap: 4px; }
  .merge-status { padding: 6px; }
  .merge-side-panel .merge-detail { min-height: 0; grid-template-columns: 48px 1fr; padding: 6px; }
  .merge-side-panel .merge-detail .detail-icon { width: 46px; height: 46px; }
  .merge-side-panel .merge-detail p { font-size: .62rem; }
  .merge-task-list { padding: 6px; gap: 3px; }
  .merge-task-title small { display: none; }
  .merge-task { padding: 4px; gap: 4px; }
  .merge-task > span { display: none; }
  .merge-task { grid-template-columns: 1fr auto; }
  .merge-hint { font-size: .62rem; }
  .field-grid-v2, .building-grid-v2 { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .field-grid-v2 > :last-child:nth-child(odd), .building-grid-v2 > :last-child:nth-child(odd) { grid-column: 1 / -1; }
  .field-card-visual img { max-height: 88px; }
  .field-card-main { grid-template-columns: 1fr; }
  .field-card-main .ef-button { width: 100%; }
  .city-header-kpis span:nth-child(3) { display: none; }
  .production-focus-v2 { grid-template-columns: 110px minmax(0,1fr); }
  .recipe-list-v2 { grid-template-columns: 1fr; overflow: hidden; }
  .recipe-card-v2 { grid-template-columns: 38px 1fr 74px; grid-template-rows: auto; }
  .recipe-card-v2 > img { width: 38px; height: 38px; grid-row: auto; }
  .recipe-card-v2 .ef-button { grid-column: auto; width: 74px; }
  .production-building-panel { padding: 5px; }
  .production-building-panel p { display: none; }
  .city-stock-strip span:nth-child(n+5), .production-stock-strip span:nth-child(n+6) { display: none; }
}

/* 0.3.0-beta.2 complete mobile UI pass */
.merge-board-wrap { overflow: hidden; }
.merge-board-canvas {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
  transition: transform .18s ease;
}

.orders-scene,
.events-scene { align-items: center; }
.orders-card,
.events-card {
  width: min(96vw, 980px);
  height: min(100%, 690px);
  max-height: 100%;
  overflow: hidden;
}
.orders-card .card-grid,
.events-card .card-grid { min-height: 0; flex: 1 1 auto; }
.orders-refresh-top { display: none; }

@media (max-width: 700px) {
  :root {
    --mobile-topbar-h: 54px;
    --mobile-footer-h: 62px;
    --mobile-panel-radius: 16px;
  }

  /* Global game chrome */
  .game-topbar {
    height: calc(var(--mobile-topbar-h) + var(--safe-top));
    padding: calc(5px + var(--safe-top)) 6px 5px;
    grid-template-columns: minmax(84px, 106px) 1fr 36px;
    gap: 4px;
    background: linear-gradient(to bottom, rgba(25,49,58,.72), rgba(25,49,58,.18));
  }
  .profile-chip {
    height: 40px;
    border-radius: 20px;
    padding: 2px 6px 2px 2px;
  }
  .avatar-stack-small { width: 36px; height: 36px; border-width: 1.5px; }
  .profile-text { margin-left: 4px; font-size: .61rem; }
  .profile-text strong { max-width: 58px; font-size: .69rem; }
  .resource-strip { min-width: 0; gap: 3px; }
  .resource-chip {
    min-width: 0;
    width: clamp(45px, 14.5vw, 62px);
    height: 30px;
    padding: 2px 5px 2px 2px;
    gap: 1px;
    border-width: 1.5px;
    border-radius: 16px;
    font-size: .67rem;
  }
  .resource-chip img { width: 23px; height: 23px; }
  .icon-button { width: 34px; height: 34px; border-radius: 10px; padding: 1px; }

  .game-content {
    top: calc(var(--mobile-topbar-h) + var(--safe-top));
    bottom: calc(var(--mobile-footer-h) + var(--safe-bottom));
  }
  .game-footer {
    height: calc(var(--mobile-footer-h) + var(--safe-bottom));
    padding: 3px 3px calc(3px + var(--safe-bottom));
    gap: 2px;
    background: rgba(30,48,59,.96);
    border-top-width: 1px;
  }
  .nav-button {
    border-radius: 10px;
    padding: 2px 0 2px;
    grid-template-rows: 34px 13px;
    font-size: .54rem;
    line-height: 1;
    overflow: hidden;
  }
  .nav-button img { width: 32px; height: 32px; }
  .nav-button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav-button.is-active {
    outline-width: 1.5px;
    transform: translateY(-1px);
    box-shadow: inset 0 0 10px rgba(255,226,115,.24), 0 2px 4px rgba(0,0,0,.18);
  }

  /* Start screen */
  .start-screen { padding: calc(10px + var(--safe-top)) 8px calc(10px + var(--safe-bottom)); }
  .start-logo { top: calc(3.5vh + var(--safe-top)); width: min(78vw, 420px); }
  .start-actions {
    width: min(94vw, 410px);
    padding: 13px 14px 11px;
    gap: 7px;
    border-radius: 18px;
  }
  .start-kicker { font-size: .58rem; }
  .start-title { font-size: clamp(1.35rem, 7vw, 1.8rem); }
  .start-copy { max-width: 34ch; font-size: .78rem; line-height: 1.2; }
  .start-player-summary { padding: 6px 8px; border-radius: 12px; gap: 7px; }
  .start-player-summary .avatar-stack-small { width: 34px; height: 34px; }
  .start-player-summary strong { font-size: .82rem; }
  .start-player-summary small { font-size: .63rem; }
  .start-player-hint { font-size: .75rem; }
  .start-button-stack { gap: 5px; }
  .start-button-stack .ef-button { width: min(72vw, 235px); }
  .start-logout-button { font-size: .74rem; padding: 2px 6px; }
  .version-label { font-size: .64rem; }

  /* Mobile modal language: bottom sheet, not desktop dialog */
  .modal-backdrop {
    place-items: end center;
    padding: calc(6px + var(--safe-top)) 5px calc(5px + var(--safe-bottom));
    background: rgba(16,25,27,.52);
  }
  .modal-panel,
  .modal-panel.modal-wide,
  .options-modal,
  .avatar-modal,
  .hat-modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 10px) !important;
    border-radius: 20px 20px 8px 8px !important;
    border-width: 3px !important;
    padding: 13px 11px 10px !important;
    box-shadow: 0 -10px 28px rgba(0,0,0,.32), inset 0 0 0 1px #e5b94b;
  }
  .modal-panel h2 { font-size: 1.16rem; margin-bottom: 5px; }
  .modal-panel > p { font-size: .75rem; line-height: 1.18; }
  .modal-close { top: 7px; right: 7px; width: 30px; height: 30px; }
  .form-field { font-size: .78rem; }
  .form-field input { height: 42px; }
  .modal-actions { margin-top: 8px; gap: 5px; }
  .modal-actions .ef-button { min-width: 0; }

  /* Character creation fits fully on one portrait screen */
  .creator-step { margin-right: 34px; font-size: .58rem; }
  .avatar-modal { overflow: hidden !important; }
  .avatar-modal > p { margin: 0 32px 5px 0; font-size: .67rem; }
  .avatar-modal .avatar-grid {
    grid-template-columns: repeat(4, minmax(0,1fr));
    grid-template-rows: repeat(3, minmax(0,1fr));
    gap: 4px;
    min-height: 0;
    height: min(61dvh, 510px);
  }
  .avatar-modal .avatar-choice {
    width: 100%;
    height: 100%;
    max-height: none;
    aspect-ratio: auto;
    border-radius: 8px;
  }
  .avatar-modal .avatar-choice img { object-fit: cover; object-position: center 8%; }
  .creator-actions { margin-top: 5px !important; }
  .creator-actions .ef-button { width: min(100%, 230px) !important; }

  .hat-modal { overflow: hidden !important; }
  .hat-modal > p { margin: 0 32px 5px 0; font-size: .67rem; }
  .starter-hat-grid {
    grid-template-columns: repeat(2,minmax(0,1fr));
    grid-template-rows: repeat(2,minmax(0,1fr));
    gap: 5px;
    height: min(59dvh, 480px);
  }
  .starter-hat-choice {
    min-height: 0;
    padding: 4px;
    grid-template-rows: minmax(0,1fr) auto;
    gap: 2px;
    border-radius: 10px;
  }
  .starter-hat-preview { width: min(100%, 130px); height: 100%; aspect-ratio: auto; }
  .starter-hat-text strong { font-size: .69rem; }
  .starter-hat-text small { font-size: .54rem; line-height: 1.05; }
  .creator-actions-split { grid-template-columns: repeat(2,minmax(0,1fr)); }

  /* Options stay one-screen on mobile */
  .options-modal { overflow: hidden !important; }
  .options-modal h2 { margin-bottom: 3px; }
  .compact-option-list { gap: 4px; }
  .compact-option-list .option-group-title { margin-top: 1px; font-size: .68rem; }
  .compact-option-list .option-row { min-height: 39px; padding: 5px 7px; border-radius: 10px; }
  .compact-option-list .option-row strong { font-size: .78rem; }
  .compact-option-list .option-row small { font-size: .58rem; }
  .no-mtx-note { padding: 6px 7px; font-size: .61rem; }
  .no-mtx-note strong { font-size: .67rem; }
  .options-action-grid { gap: 4px; }
  .options-action-grid .ef-button { aspect-ratio: 3.25 / 1; font-size: .62rem; padding-inline: 15px; }
  .option-logout { font-size: .7rem; }

  /* Shared full-screen panels */
  .scene-panel {
    align-items: stretch;
    justify-content: stretch;
    padding: 3px;
  }
  .scene-card,
  .city-card-v2,
  .production-card,
  .inventory-card,
  .orders-card,
  .events-card {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    padding: 7px;
    border-width: 2px;
    border-radius: var(--mobile-panel-radius);
    overflow: hidden;
  }
  .compact-screen-header { min-height: 30px; gap: 5px; }
  .compact-screen-header .scene-title,
  .scene-title { font-size: 1.03rem; line-height: 1; margin: 0; }
  .compact-screen-header .scene-subtitle,
  .scene-subtitle { display: none; }
  .section-header { margin-bottom: 4px; }
  .section-header h3 { font-size: .78rem; }
  .screen-tabs { gap: 3px; margin: 4px 0; }
  .screen-tab { min-height: 30px; border-radius: 9px; gap: 3px; font-size: .65rem; }
  .screen-tab small { font-size: .52rem; }
  .screen-tab-refresh { max-width: 34px; }
  .status-pill { padding: 3px 5px; font-size: .55rem; }
  .kpi-strip { gap: 4px; margin-bottom: 4px; }
  .kpi-card { padding: 5px; border-radius: 9px; }
  .kpi-card strong { font-size: .79rem; }
  .kpi-card small { font-size: .53rem; }

  /* Merge: board always owns the screen, auxiliary UI is compact */
  .merge-scene {
    align-items: stretch;
    justify-content: stretch;
    padding: 2px 0 2px;
    overflow: hidden;
  }
  .merge-stage-v2 {
    width: 100%;
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0,1fr);
    grid-template-areas:
      "status"
      "board"
      "detail"
      "tasks";
    grid-template-rows: 40px minmax(0,1fr) 58px 54px;
    gap: 2px;
    align-items: center;
    justify-items: stretch;
    overflow: hidden;
  }
  .merge-side-panel { display: contents; }
  .merge-status {
    grid-area: status;
    min-width: 0;
    height: 40px;
    padding: 3px 5px;
    border-width: 1.5px;
    border-radius: 11px;
    grid-template-columns: minmax(0,1fr) auto;
    align-items: center;
    gap: 5px;
    box-shadow: 0 2px 5px rgba(33,23,14,.14);
  }
  .merge-level-row { min-width: 0; grid-template-columns: auto minmax(55px,1fr); gap: 5px; }
  .merge-level-row strong { font-size: .65rem; }
  .merge-level-row small { display: none; }
  .merge-level-bar { height: 7px; }
  .merge-stat-grid { display: none; }
  .merge-supply-button {
    width: 98px;
    height: 30px;
    padding: 3px 6px;
    border-radius: 9px;
    display: grid;
    justify-items: center;
    gap: 0;
    line-height: 1;
  }
  .merge-supply-button span { font-size: .64rem; }
  .merge-supply-button small { font-size: .49rem; }

  .merge-board-wrap {
    grid-area: board;
    align-self: center;
    justify-self: center;
    width: 100%;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1322 / 1190;
    border-radius: 14px;
    filter: drop-shadow(0 4px 6px rgba(28,20,12,.22));
  }
  .merge-board-canvas { transform: none; }
  .merge-cell { width: 9.4%; }
  .merge-item { width: 84%; height: 84%; }
  .merge-cell.is-selected { outline-width: 2px; box-shadow: 0 0 9px rgba(255,219,73,.72); }

  .merge-side-panel .merge-detail {
    grid-area: detail;
    width: 100%;
    height: 58px;
    min-height: 0;
    padding: 4px 6px;
    border-width: 1.5px;
    border-radius: 11px;
    grid-template-columns: 42px minmax(0,1fr) auto;
    grid-template-rows: 1fr;
    gap: 5px;
    align-items: center;
    box-shadow: 0 2px 5px rgba(33,23,14,.13);
  }
  .merge-side-panel .merge-detail .detail-icon { width: 40px; height: 40px; }
  .merge-side-panel .merge-detail h3 { font-size: .7rem; }
  .merge-side-panel .merge-detail p {
    max-width: 100%;
    font-size: .54rem;
    line-height: 1.05;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .merge-side-panel .merge-detail-actions {
    grid-column: 3;
    grid-row: 1;
    width: auto;
    flex-wrap: nowrap;
    gap: 3px;
  }
  .merge-side-panel .merge-detail-actions .ef-button {
    width: 82px;
    min-width: 0;
    max-width: 82px;
    aspect-ratio: 2.2 / 1;
    padding-inline: 8px;
    font-size: .55rem;
  }

  .merge-task-list {
    grid-area: tasks;
    width: 100%;
    height: 54px;
    min-height: 0;
    padding: 3px;
    border-width: 1.5px;
    border-radius: 11px;
    display: grid;
    grid-template-columns: repeat(3,minmax(0,1fr));
    gap: 3px;
    align-items: stretch;
    box-shadow: 0 2px 5px rgba(33,23,14,.12);
  }
  .merge-task-title { display: none; }
  .merge-task {
    min-width: 0;
    min-height: 0;
    padding: 3px 4px;
    border-radius: 8px;
    grid-template-columns: minmax(0,1fr) auto;
    grid-template-rows: auto auto;
    gap: 1px 3px;
    align-content: center;
  }
  .merge-task > div { grid-column: 1; grid-row: 1 / span 2; }
  .merge-task strong { font-size: .52rem; }
  .merge-task small { font-size: .45rem; }
  .merge-task > span { display: none; }
  .merge-task button {
    grid-column: 2;
    grid-row: 1 / span 2;
    min-width: 36px;
    padding: 3px 4px;
    border-radius: 7px;
    font-size: .48rem;
  }
  .merge-hint { display: none; }
  .merge-drag-ghost { transform: translate(-50%, -68%) scale(1.08); }

  /* City */
  .city-card-v2 { display: flex; flex-direction: column; }
  .city-header-v2 { min-height: 31px; }
  .city-header-kpis { gap: 2px; flex-wrap: nowrap; }
  .city-header-kpis span { padding: 3px 4px; border-radius: 7px; font-size: .49rem; }
  .city-header-kpis span:nth-child(3) { display: none; }
  .city-tab-content { flex: 1 1 auto; min-height: 0; }
  .field-grid-v2,
  .building-grid-v2 {
    width: 100%;
    height: 100%;
    min-height: 0;
    grid-template-columns: repeat(3,minmax(0,1fr));
    grid-template-rows: minmax(0,1fr);
    gap: 4px;
  }
  .field-grid-v2 > :last-child:nth-child(odd),
  .building-grid-v2 > :last-child:nth-child(odd) { grid-column: auto; }
  .field-card-v2 {
    padding: 4px;
    gap: 2px;
    border-radius: 10px;
    grid-template-rows: minmax(0,1fr) auto auto;
  }
  .field-card-visual img { width: 94%; height: 100%; max-height: none; }
  .field-number { top: 1px; left: 1px; padding: 2px 4px; font-size: .45rem; }
  .field-card-main { grid-template-columns: 1fr; gap: 2px; }
  .field-card-main strong { font-size: .61rem; }
  .field-card-main small { font-size: .49rem; }
  .field-card-main .ef-button { width: 100%; min-height: 29px; font-size: .5rem; }
  .crop-choice-row { gap: 1px; flex-wrap: nowrap; }
  .crop-choice { flex: 1 1 0; padding: 1px; border-radius: 6px; }
  .crop-choice img { width: 18px; height: 18px; }
  .crop-choice span { display: none; }
  .building-card-v2 {
    padding: 4px;
    gap: 2px;
    border-radius: 10px;
    grid-template-rows: minmax(0,1fr) auto;
  }
  .building-card-v2 > img { max-height: none; }
  .building-title-row { gap: 2px; }
  .building-title-row h3 { font-size: .62rem; }
  .building-title-row span { font-size: .46rem; }
  .building-card-copy p { display: none; }
  .building-actions { min-height: 28px; }
  .building-actions .ef-button { width: 100%; min-height: 28px; font-size: .48rem; }
  .city-stock-strip { height: 34px; margin-top: 3px; gap: 2px; }
  .city-stock-strip span { min-width: 0; flex: 1 1 0; padding: 1px 3px; font-size: .5rem; border-radius: 7px; }
  .city-stock-strip img { width: 20px; height: 20px; }

  /* Production */
  .production-card { display: flex; flex-direction: column; }
  .production-focus-v2 {
    flex: 1 1 auto;
    min-height: 0;
    grid-template-columns: 92px minmax(0,1fr);
    gap: 4px;
  }
  .production-building-panel {
    padding: 4px;
    gap: 2px;
    border-radius: 10px;
    grid-template-rows: minmax(0,1fr) auto auto auto;
  }
  .production-building-panel h3 { font-size: .64rem; }
  .production-building-panel p { display: none; }
  .production-job { padding: 3px; border-radius: 7px; }
  .production-job strong { font-size: .53rem; }
  .production-job small { font-size: .45rem; }
  .production-building-panel .ef-button { min-height: 27px; font-size: .47rem; padding-inline: 8px; }
  .recipe-list-v2 {
    min-height: 0;
    grid-template-columns: repeat(2,minmax(0,1fr));
    grid-auto-rows: minmax(0,1fr);
    gap: 3px;
    overflow: hidden;
  }
  .recipe-card-v2 {
    min-height: 0;
    grid-template-columns: 36px minmax(0,1fr);
    grid-template-rows: auto auto;
    gap: 2px;
    padding: 3px;
    border-radius: 9px;
  }
  .recipe-card-v2 > img { width: 34px; height: 34px; grid-row: 1 / span 2; }
  .recipe-copy strong { font-size: .52rem; }
  .recipe-copy small { font-size: .43rem; line-height: 1.02; }
  .recipe-copy span { font-size: .44rem; }
  .recipe-card-v2 .ef-button { grid-column: 2; width: 100%; min-height: 26px; font-size: .46rem; padding-inline: 6px; }
  .production-stock-strip { height: 32px; margin-top: 3px; gap: 2px; }
  .production-stock-strip span { min-width: 0; flex: 1 1 0; padding: 1px 2px; font-size: .48rem; border-radius: 7px; }
  .production-stock-strip img { width: 19px; height: 19px; }
  .production-stock-strip span:nth-child(n+7) { display: none; }

  /* Orders */
  .orders-card { display: flex; flex-direction: column; }
  .orders-header { min-height: 30px; }
  .orders-refresh-top { display: inline-flex; width: 30px; height: 28px; padding: 0; align-items: center; justify-content: center; font-size: 1rem; }
  .orders-card > .scene-subtitle { display: none; }
  .orders-card .kpi-strip { flex: 0 0 auto; }
  .orders-section-header { margin: 2px 0 3px; }
  .orders-refresh-inline { display: none; }
  .orders-card .card-grid {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: repeat(3,minmax(0,1fr));
    gap: 4px;
  }
  .orders-card .content-card {
    min-height: 0;
    padding: 4px 5px;
    border-radius: 10px;
    display: grid;
    grid-template-columns: 62px minmax(0,1fr) auto;
    grid-template-rows: auto auto auto;
    gap: 1px 5px;
    align-items: center;
  }
  .orders-card .content-card img {
    grid-column: 1;
    grid-row: 1 / span 3;
    width: 58px;
    height: 100%;
    max-height: 92px;
    object-fit: contain;
  }
  .orders-card .content-card h3 { grid-column: 2; margin: 0; font-size: .62rem; }
  .orders-card .content-card p { grid-column: 2; margin: 0; font-size: .5rem; line-height: 1.05; }
  .orders-card .content-card .status-pill { grid-column: 2; margin: 0; width: fit-content; }
  .orders-card .content-card .card-action { grid-column: 3; grid-row: 1 / span 3; }
  .orders-card .content-card .ef-button { width: 74px; font-size: .49rem; padding-inline: 8px; }

  /* Inventory */
  .inventory-card { display: flex; flex-direction: column; }
  .inventory-tabs { margin: 4px 0; gap: 3px; }
  .inventory-tab { min-height: 30px; padding: 3px 2px; gap: 2px; border-radius: 8px; font-size: .58rem; }
  .inventory-tab small { min-width: 16px; width: 16px; height: 16px; font-size: .48rem; }
  .inventory-tab-content { flex: 1 1 auto; min-height: 0; overflow: hidden; }
  .inventory-compact-grid {
    height: 100%;
    grid-template-columns: repeat(4,minmax(0,1fr));
    grid-auto-rows: minmax(0,1fr);
    gap: 3px;
  }
  .inventory-compact-entry { min-height: 0; padding: 3px; gap: 1px; border-radius: 8px; }
  .inventory-compact-entry .inventory-slot-visual { width: min(100%, 78px); margin-bottom: 0; }
  .inventory-slot-count { right: 6%; bottom: 6%; min-width: 22px; padding: 1px 4px; font-size: .5rem; }
  .inventory-compact-entry strong { font-size: .49rem; line-height: 1; }
  .booster-compact-grid {
    height: 100%;
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(0,1fr);
    gap: 3px;
  }
  .booster-compact-entry { padding: 5px; border-radius: 9px; }
  .booster-compact-entry strong { font-size: .66rem; }
  .booster-compact-entry small { font-size: .52rem; }
  .booster-compact-entry .ef-button { width: 90px; font-size: .5rem; }
  .compact-active-boost { margin-bottom: 3px; padding: 4px 6px; font-size: .56rem; }
  .hat-compact-grid {
    height: 100%;
    grid-template-columns: repeat(4,minmax(0,1fr));
    grid-auto-rows: minmax(0,1fr);
    gap: 3px;
  }
  .hat-compact-entry {
    min-height: 0;
    padding: 3px;
    gap: 1px;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0,1fr) auto auto;
    justify-items: center;
    text-align: center;
    border-radius: 8px;
  }
  .hat-compact-entry .inventory-slot-visual { grid-column: 1; grid-row: 1; width: min(100%, 70px); }
  .hat-compact-entry > div { grid-column: 1; grid-row: 2; }
  .hat-compact-entry strong { font-size: .47rem; }
  .hat-compact-entry small { display: none; }
  .hat-compact-entry .ef-button,
  .hat-compact-entry .status-pill {
    grid-column: 1;
    grid-row: 3;
    width: 100%;
    min-height: 24px;
    font-size: .45rem;
    justify-self: stretch;
  }

  /* Events */
  .events-card { display: flex; flex-direction: column; }
  .events-card .character-preview {
    flex: 0 0 82px;
    min-height: 0;
    margin: 2px 0 4px;
    grid-template-columns: 72px 1fr;
    gap: 7px;
    text-align: left;
  }
  .events-card .character-preview > img { width: 70px !important; max-height: 78px !important; }
  .events-card .character-preview h3 { margin: 0; font-size: .75rem; }
  .events-card .character-preview p { margin: 2px 0 0; font-size: .56rem; line-height: 1.1; }
  .events-card .card-grid {
    flex: 1 1 auto;
    min-height: 0;
    grid-template-columns: repeat(3,minmax(0,1fr));
    grid-template-rows: minmax(0,1fr);
    gap: 4px;
  }
  .events-card .content-card { padding: 4px; border-radius: 9px; text-align: center; }
  .events-card .content-card img { max-height: 76px; }
  .events-card .content-card h3 { margin: 2px 0; font-size: .59rem; }
  .events-card .content-card p { font-size: .49rem; line-height: 1.05; }
}

@media (max-width: 360px) {
  .game-topbar { grid-template-columns: 42px 1fr 34px; }
  .profile-chip { width: 40px; padding-right: 2px; }
  .profile-text { display: none; }
  .resource-chip { width: clamp(42px, 18vw, 54px); font-size: .6rem; }
  .resource-chip img { width: 21px; height: 21px; }
  .nav-button { font-size: .48rem; }
  .merge-stage-v2 { grid-template-rows: 38px minmax(0,1fr) 54px 48px; }
  .merge-board-canvas { transform: none; }
  .merge-side-panel .merge-detail { height: 54px; grid-template-columns: 38px minmax(0,1fr) auto; }
  .merge-side-panel .merge-detail .detail-icon { width: 36px; height: 36px; }
  .merge-side-panel .merge-detail-actions .ef-button { width: 70px; max-width: 70px; font-size: .49rem; }
  .merge-task-list { height: 48px; }
  .orders-card .content-card { grid-template-columns: 52px minmax(0,1fr) auto; }
  .orders-card .content-card img { width: 50px; }
  .orders-card .content-card .ef-button { width: 66px; }
}

@media (max-height: 650px) and (max-width: 700px) {
  :root { --mobile-topbar-h: 50px; --mobile-footer-h: 56px; }
  .game-topbar { grid-template-columns: minmax(72px,96px) 1fr 32px; }
  .profile-chip { height: 36px; }
  .avatar-stack-small { width: 32px; height: 32px; }
  .icon-button { width: 31px; height: 31px; }
  .resource-chip { height: 27px; }
  .resource-chip img { width: 21px; height: 21px; }
  .game-footer { padding-top: 2px; }
  .nav-button { grid-template-rows: 29px 11px; font-size: .48rem; }
  .nav-button img { width: 27px; height: 27px; }
  .merge-stage-v2 { grid-template-rows: 36px minmax(0,1fr) 50px 44px; }
  .merge-status { height: 36px; }
  .merge-side-panel .merge-detail { height: 50px; }
  .merge-task-list { height: 44px; }
  .merge-board-canvas { transform: none; }
  .city-stock-strip, .production-stock-strip { height: 28px; }
  .city-stock-strip img, .production-stock-strip img { width: 17px; height: 17px; }
  .events-card .character-preview { flex-basis: 66px; }
  .events-card .character-preview > img { max-height: 62px !important; }
}

@media (max-width: 700px) {
  .merge-board-canvas,
  .merge-board-image { transform: none; }
  .merge-cell {
    width: 9.4%;
    aspect-ratio: 1.07;
  }
  .merge-item { width: 84%; height: 84%; object-fit: contain; }
}

@media (max-width: 700px) {
  body.compact-ui .game-footer { height: calc(var(--mobile-footer-h) + var(--safe-bottom)); }
  body.compact-ui .nav-button { grid-template-rows: 31px 12px; }
  body.compact-ui .nav-button img { width: 29px; height: 29px; }
  body.compact-ui .resource-chip { min-width: 0; width: clamp(43px, 14vw, 58px); font-size: .62rem; }
  body.compact-ui .resource-chip img { width: 21px; height: 21px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  :root { --mobile-topbar-h: 44px; --mobile-footer-h: 48px; }
  .game-topbar {
    height: calc(var(--mobile-topbar-h) + var(--safe-top));
    padding: calc(3px + var(--safe-top)) 6px 3px;
    grid-template-columns: 110px 1fr 34px;
  }
  .profile-chip { height: 34px; }
  .avatar-stack-small { width: 30px; height: 30px; }
  .profile-text strong { font-size: .65rem; }
  .resource-chip { height: 27px; width: 68px; font-size: .64rem; }
  .resource-chip img { width: 21px; height: 21px; }
  .icon-button { width: 31px; height: 31px; }
  .game-content { top: calc(var(--mobile-topbar-h) + var(--safe-top)); bottom: calc(var(--mobile-footer-h) + var(--safe-bottom)); }
  .game-footer {
    height: calc(var(--mobile-footer-h) + var(--safe-bottom));
    padding: 2px 5px calc(2px + var(--safe-bottom));
  }
  .nav-button { grid-template-rows: 26px 10px; font-size: .46rem; }
  .nav-button img { width: 25px; height: 25px; }

  .scene-panel { padding: 2px; }
  .scene-card,
  .city-card-v2,
  .production-card,
  .inventory-card,
  .orders-card,
  .events-card { border-radius: 12px; padding: 5px; }

  .merge-stage-v2 {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: minmax(0,1fr) 230px;
    grid-template-rows: minmax(0,1fr);
    grid-template-areas: "board side";
    gap: 4px;
    align-items: stretch;
  }
  .merge-board-wrap {
    grid-area: board;
    width: auto;
    height: 100%;
    max-width: 100%;
    justify-self: end;
    border-radius: 10px;
  }
  .merge-board-image { transform: none; }
  .merge-cell {
    width: 8.85%;
    aspect-ratio: 1.07;
  }
  .merge-side-panel {
    grid-area: side;
    display: grid;
    grid-template-rows: 58px 72px minmax(0,1fr);
    gap: 3px;
    min-height: 0;
    overflow: hidden;
  }
  .merge-status {
    grid-area: auto;
    height: 58px;
    padding: 4px;
    grid-template-columns: 1fr 82px;
  }
  .merge-level-row { grid-template-columns: 1fr; gap: 2px; }
  .merge-level-row small { display: none; }
  .merge-stat-grid { display: none; }
  .merge-supply-button { width: 82px; height: 40px; }
  .merge-side-panel .merge-detail {
    grid-area: auto;
    height: 72px;
    grid-template-columns: 40px 1fr;
    grid-template-rows: auto auto;
    padding: 4px;
  }
  .merge-side-panel .merge-detail .detail-icon { width: 38px; height: 38px; }
  .merge-side-panel .merge-detail p { font-size: .49rem; -webkit-line-clamp: 1; }
  .merge-side-panel .merge-detail-actions {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: center;
  }
  .merge-side-panel .merge-detail-actions .ef-button { width: 76px; max-width: 76px; }
  .merge-task-list {
    grid-area: auto;
    width: auto;
    height: auto;
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: repeat(3,minmax(0,1fr));
    gap: 2px;
    padding: 3px;
    overflow: hidden;
  }
  .merge-task { grid-template-columns: 1fr auto; grid-template-rows: 1fr; }
  .merge-task > div { grid-row: 1; }
  .merge-task button { grid-row: 1; }
  .merge-hint { display: none; }

  .city-card-v2 .screen-tabs,
  .production-card .screen-tabs { margin: 2px 0; }
  .screen-tab { min-height: 25px; }
  .city-stock-strip, .production-stock-strip { height: 25px; margin-top: 2px; }
  .city-stock-strip img, .production-stock-strip img { width: 16px; height: 16px; }
  .field-grid-v2, .building-grid-v2 { grid-template-columns: repeat(3,minmax(0,1fr)); grid-template-rows: minmax(0,1fr); }
  .production-focus-v2 { grid-template-columns: 100px minmax(0,1fr); }
  .recipe-list-v2 { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .orders-card .kpi-strip { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .orders-card .card-grid { grid-template-columns: repeat(3,minmax(0,1fr)); grid-template-rows: minmax(0,1fr); }
  .orders-card .content-card { grid-template-columns: 46px minmax(0,1fr); grid-template-rows: auto auto auto auto; text-align: left; }
  .orders-card .content-card img { width: 44px; grid-row: 1 / span 4; }
  .orders-card .content-card .card-action { grid-column: 2; grid-row: 4; }
  .orders-card .content-card .ef-button { width: 100%; }
  .inventory-compact-grid { grid-template-columns: repeat(6,minmax(0,1fr)); }
  .hat-compact-grid { grid-template-columns: repeat(8,minmax(0,1fr)); }
  .events-card .character-preview { display: none; }
  .events-card .card-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
}

@media (orientation: landscape) and (max-height: 520px) {
  .merge-board-canvas,
  .merge-board-image { transform: none; }
  .merge-cell { width: 8.85%; aspect-ratio: 1.07; }
  .merge-item { width: 84%; height: 84%; object-fit: contain; }
}

/* Runtime performance and soft-keyboard viewport handling. */
:root {
  --visual-viewport-height: 100dvh;
  --visual-viewport-offset-top: 0px;
}

.merge-board-canvas {
  contain: layout paint style;
}

body.soft-keyboard-open .modal-root {
  top: var(--visual-viewport-offset-top);
  bottom: auto;
  height: var(--visual-viewport-height);
}

body.soft-keyboard-open .modal-backdrop {
  inset: 0;
  height: 100%;
  place-items: start center;
  padding-top: max(8px, var(--safe-top));
  padding-bottom: 8px;
}

body.soft-keyboard-open .modal-panel,
body.soft-keyboard-open .modal-panel.modal-wide {
  max-height: calc(var(--visual-viewport-height) - 16px) !important;
  overflow: auto !important;
  overscroll-behavior: contain;
  scroll-padding-block: 72px;
}

@media (max-width: 700px) {
  body.soft-keyboard-open .player-modal {
    width: min(96vw, 560px) !important;
    padding: 10px 12px 12px !important;
    border-width: 3px;
    border-radius: 18px;
  }

  body.soft-keyboard-open .player-modal h2 {
    margin-bottom: 4px;
    font-size: 1.18rem;
  }

  body.soft-keyboard-open .player-modal > p {
    margin: 0 34px 6px 0;
    font-size: .76rem;
    line-height: 1.2;
  }

  body.soft-keyboard-open .player-modal .form-grid {
    gap: 7px;
  }

  body.soft-keyboard-open .player-modal .form-field {
    gap: 2px;
    font-size: .76rem;
  }

  body.soft-keyboard-open .player-modal .form-field input {
    height: 43px;
  }

  body.soft-keyboard-open .player-modal .ef-button {
    min-height: 40px;
    aspect-ratio: auto;
  }
}

@media (hover: none) and (pointer: coarse) {
  .merge-board-wrap,
  .merge-item,
  .start-logo,
  .ef-button {
    filter: none;
  }

  .modal-backdrop,
  .glass-card {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .merge-item.chest-ready {
    animation: mobileChestPulse 1.25s ease-in-out infinite alternate;
  }

  @keyframes mobileChestPulse {
    from { transform: scale(1); }
    to { transform: scale(1.035); }
  }
}

.leaderboard-intro,
.leaderboard-footnote {
  margin: 0 0 12px;
}

.dev-player-row small,
.dev-session-row small,
.dev-player-meta-grid span {
  display: block;
  opacity: 0.8;
}

.dev-tab-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.dev-tab {
  border: 1px solid rgba(76, 53, 30, 0.2);
  background: rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  cursor: pointer;
}

.dev-tab.is-active {
  background: rgba(74, 138, 194, 0.16);
  border-color: rgba(74, 138, 194, 0.45);
}

.dev-tab-panel {
  display: none;
}

.dev-tab-panel.is-active {
  display: block;
}

.dev-status-tight {
  margin-bottom: 12px;
}

.dev-players-layout {
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.dev-player-list,
.dev-player-detail,
.dev-player-detail-card {
  background: rgba(255, 250, 240, 0.92);
  border: 1px solid rgba(76, 53, 30, 0.14);
  border-radius: 18px;
}

.dev-player-list {
  max-height: 62vh;
  overflow: auto;
  padding: 8px;
}

.dev-player-detail {
  min-height: 220px;
  padding: 14px;
}

.dev-player-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 10px 12px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
}

.dev-player-row:hover,
.dev-player-row:focus-visible {
  background: rgba(74, 138, 194, 0.12);
}

.dev-player-primary,
.dev-player-secondary {
  display: flex;
  flex-direction: column;
}

.dev-player-secondary {
  text-align: right;
  white-space: nowrap;
}

.dev-player-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
  margin: 14px 0;
}

.dev-player-meta-grid > div {
  background: rgba(255,255,255,0.65);
  border-radius: 12px;
  padding: 10px 12px;
}

.dev-player-meta-grid strong,
.dev-session-row strong {
  display: block;
}

.dev-session-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dev-session-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255,255,255,0.65);
  border-radius: 12px;
  padding: 10px 12px;
}

.dev-ua {
  word-break: break-word;
}

@media (max-width: 820px) {
  .dev-players-layout {
    grid-template-columns: 1fr;
  }

  .dev-player-list {
    max-height: 38vh;
  }

  .dev-player-row,
  .dev-session-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .dev-player-secondary {
    text-align: left;
    white-space: normal;
  }

  .dev-player-meta-grid {
    grid-template-columns: 1fr;
  }
}

/* Public leaderboard */
.leaderboard-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 6px;
}

.leaderboard-heading h2 { margin: 0; }

.leaderboard-eyebrow {
  display: block;
  margin-bottom: 2px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.66;
}

.leaderboard-my-rank {
  display: flex;
  min-width: 92px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 9px 13px;
  border-radius: 18px;
  background: rgba(255, 244, 194, 0.88);
  border: 1px solid rgba(139, 91, 36, 0.18);
}

.leaderboard-my-rank small { font-size: 0.68rem; opacity: 0.72; }
.leaderboard-my-rank strong { font-size: 1.1rem; }
.leaderboard-intro { margin-bottom: 14px; }

.leaderboard-card-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-height: min(61vh, 620px);
  overflow: auto;
  padding: 2px 4px 2px 2px;
}

.leaderboard-card {
  display: grid;
  grid-template-columns: 48px 68px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 82px;
  padding: 9px 12px;
  border-radius: 20px;
  border: 1px solid rgba(76, 53, 30, 0.12);
  background: rgba(255, 250, 240, 0.9);
  box-shadow: 0 3px 10px rgba(51, 39, 25, 0.06);
}

.leaderboard-card.rank-one,
.leaderboard-card.rank-two,
.leaderboard-card.rank-three { border-width: 2px; }

.leaderboard-card.rank-one {
  background: linear-gradient(90deg, rgba(255, 239, 167, 0.92), rgba(255, 250, 240, 0.92));
  border-color: rgba(184, 128, 28, 0.45);
}

.leaderboard-card.rank-two {
  background: linear-gradient(90deg, rgba(233, 239, 243, 0.95), rgba(255, 250, 240, 0.92));
  border-color: rgba(111, 126, 137, 0.34);
}

.leaderboard-card.rank-three {
  background: linear-gradient(90deg, rgba(240, 213, 186, 0.94), rgba(255, 250, 240, 0.92));
  border-color: rgba(143, 86, 43, 0.32);
}

.leaderboard-card.is-current {
  box-shadow: 0 0 0 2px rgba(55, 132, 185, 0.28), 0 3px 12px rgba(51, 39, 25, 0.08);
}

.leaderboard-rank {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.25rem;
  font-weight: 800;
  text-align: center;
}

.leaderboard-avatar-frame {
  position: relative;
  place-self: center;
  align-self: center;
  justify-self: center;
  width: 64px;
  height: 70px;
  overflow: hidden;
  border-radius: 16px;
  border: 2px solid rgba(196, 148, 82, 0.72);
  background: radial-gradient(circle at 50% 27%, #f9ebcf 0%, #f1d9ac 48%, #e6c58f 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.62), 0 3px 8px rgba(74,47,28,.1);
}

.leaderboard-portrait-rig {
  width: 48px;
  bottom: 3px;
}

.leaderboard-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}

.leaderboard-player {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.leaderboard-player strong {
  overflow: hidden;
  font-size: 1.08rem;
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-player span {
  font-size: 0.8rem;
  opacity: 0.74;
}

.leaderboard-meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 14px;
  font-size: 0.76rem;
  opacity: 0.76;
}

.leaderboard-meta-line strong {
  font-size: 0.88rem;
  opacity: 1;
}

@media (max-width: 620px) {
  .leaderboard-heading {
    align-items: flex-start;
    padding-right: 34px;
  }

  .leaderboard-card-list { max-height: 68vh; }

  .leaderboard-card {
    grid-template-columns: 38px 60px minmax(0, 1fr);
    gap: 9px;
    min-height: 76px;
    padding: 8px 9px;
  }

  .leaderboard-rank { font-size: 1.06rem; }

  .leaderboard-avatar-frame {
    place-self: center;
    width: 56px;
    height: 64px;
    border-radius: 14px;
  }

  .leaderboard-portrait-rig {
    width: 43px;
    bottom: 3px;
  }

  .leaderboard-player strong { font-size: 0.98rem; }
  .leaderboard-player span { font-size: 0.76rem; }
  .leaderboard-meta-line { gap: 5px 11px; font-size: 0.72rem; }
  .leaderboard-meta-line strong { font-size: 0.8rem; }
}

/* Player-facing changelog */
.changelog-public-intro {
  margin: -4px 0 12px;
  opacity: 0.78;
}

.changelog-public-list {
  display: flex;
  max-height: min(66vh, 640px);
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding-right: 3px;
}

.changelog-public-entry {
  margin: 0;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(76, 53, 30, 0.12);
  background: rgba(255, 250, 240, 0.88);
}

.changelog-public-entry.is-latest {
  border-color: rgba(63, 130, 174, 0.34);
  background: rgba(237, 248, 255, 0.9);
}

.changelog-public-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.changelog-public-head h3 {
  margin: 0;
}

.changelog-public-head > span {
  flex: 0 0 auto;
  font-size: 0.72rem;
  font-weight: 800;
  opacity: 0.66;
}

.changelog-public-entry > small {
  opacity: 0.62;
}

.changelog-public-entry ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

/* Internal technical changelog */
.dev-tab-bar {
  flex-wrap: wrap;
}

.dev-technical-note {
  margin: 0 0 12px;
  opacity: 0.78;
}

.dev-technical-changelog-list {
  display: flex;
  max-height: 65vh;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
  padding-right: 4px;
}

.dev-technical-changelog-entry {
  padding: 12px 14px;
  border: 1px solid rgba(76, 53, 30, 0.14);
  border-radius: 16px;
  background: rgba(255, 250, 240, 0.92);
}

.dev-technical-changelog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.dev-technical-changelog-head > div {
  display: flex;
  flex-direction: column;
}

.dev-technical-changelog-head span,
.dev-technical-changelog-head small {
  opacity: 0.72;
}

.dev-change-group {
  margin-top: 10px;
}

.dev-change-group > strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.72;
}

.dev-change-group ul {
  margin: 0;
  padding-left: 20px;
}

@media (max-width: 620px) {
  .leaderboard-heading {
    padding-right: 34px;
  }

  .leaderboard-card-list {
    max-height: 68vh;
  }

  .leaderboard-card {
    grid-template-columns: 34px 50px minmax(0, 1fr);
    gap: 8px;
    min-height: 62px;
    padding: 7px 9px;
  }

  .leaderboard-avatar {
    width: 48px;
    height: 48px;
    flex-basis: 48px;
    border-radius: 14px;
  }

  .leaderboard-rank {
    font-size: 1rem;
  }

  .leaderboard-stats {
    grid-column: 3;
    gap: 6px;
  }

  .leaderboard-stats > span {
    min-width: 54px;
    padding: 4px 7px;
  }

  .leaderboard-player strong {
    font-size: 0.94rem;
  }

  .leaderboard-player span {
    font-size: 0.72rem;
  }

  .changelog-public-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 1px;
  }

  .dev-tab {
    padding: 7px 10px;
    font-size: 0.78rem;
  }
}


/* Leaderboard hotfix beta.13 */
.leaderboard-card {
  grid-template-columns: 46px 64px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 88px;
  padding: 10px 12px;
  overflow: hidden;
}

.leaderboard-avatar-frame {
  width: 58px;
  height: 64px;
  border-radius: 15px;
}

.leaderboard-portrait-rig {
  width: 42px;
  bottom: 3px;
}

.leaderboard-main {
  min-width: 0;
  gap: 5px;
}

.leaderboard-player strong {
  font-size: 1rem;
  line-height: 1.08;
}

.leaderboard-player span {
  font-size: 0.78rem;
}

.leaderboard-meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  line-height: 1.1;
}

.leaderboard-meta-line span {
  white-space: nowrap;
}

@media (max-width: 620px) {
  .leaderboard-card {
    grid-template-columns: 40px 56px minmax(0, 1fr);
    gap: 8px;
    min-height: 84px;
    padding: 9px 10px;
  }

  .leaderboard-rank {
    font-size: 1.02rem;
  }

  .leaderboard-avatar-frame {
    width: 52px;
    height: 58px;
    border-radius: 14px;
  }

  .leaderboard-portrait-rig {
    width: 38px;
    bottom: 2px;
  }

  .leaderboard-main {
    gap: 4px;
  }

  .leaderboard-player strong {
    font-size: 0.95rem;
  }

  .leaderboard-player span {
    font-size: 0.73rem;
  }

  .leaderboard-meta-line {
    gap: 4px 10px;
    font-size: 0.7rem;
  }

  .leaderboard-meta-line strong {
    font-size: 0.78rem;
  }
}
