/* ============================================================
     ESTILS COMPLETS AMB MILLORES UI/UX
     ============================================================ */

  :root {
    --museum-accent:#b9c0c7;
    --museum-accent-rgb:185,192,199;
    --museum-ink:#0b0d10;
    --museum-text:#eef1f4;
    --museum-muted:#9aa4b0;
  }

  /* Reset i base */
  * { margin:0; padding:0; box-sizing:border-box; }
  html, body {
    width:100%; height:100%; overflow:hidden;
    background:var(--museum-ink);
    font-family:'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color:var(--museum-text);
    user-select:none;
    -webkit-tap-highlight-color:transparent;
  }

  #canvas-container { width:100vw; height:100vh; display:block; touch-action:none; }

  /* ====== MENÚ SUPERIOR ====== */
  #topNav {
    position:fixed; top:0; left:0; right:0;
    padding:12px 20px;
    background:rgba(10,10,10,0.75);
    backdrop-filter:blur(16px);
    -webkit-backdrop-filter:blur(16px);
    border-bottom:1px solid rgba(var(--museum-accent-rgb),0.15);
    display:flex; justify-content:space-between; align-items:center;
    z-index:100;
    transition:transform 0.4s cubic-bezier(0.34,1.56,0.64,1);
  }
  #topNav.hidden { transform:translateY(-100%); }
  #topNav .logo {
    font-size:clamp(14px,2vw,22px);
    letter-spacing:0.1em;
    color:#f2f4f6;
    display:flex; align-items:center; gap:8px;
  }
  #topNav .logo span { color:var(--museum-accent); }
  #topNav .nav-controls {
    display:flex; gap:8px; align-items:center;
  }
  #topNav .nav-controls button {
    background:rgba(255,255,255,0.06);
    border:1px solid rgba(var(--museum-accent-rgb),0.2);
    color:#e6e9ec;
    padding:6px 12px;
    border-radius:20px;
    font-size:14px;
    cursor:pointer;
    transition:all 0.2s;
    font-family:inherit;
    min-width:36px;
    display:flex; align-items:center; justify-content:center;
  }
  #topNav .nav-controls button:hover {
    background:rgba(var(--museum-accent-rgb),0.15);
    border-color:rgba(var(--museum-accent-rgb),0.5);
    transform:scale(1.05);
  }
  #topNav .nav-controls button:active { transform:scale(0.95); }
  #topNav .nav-controls button.active {
    background:rgba(var(--museum-accent-rgb),0.2);
    border-color:var(--museum-accent);
  }
  #topNav .nav-controls .btn-label {
    font-size:10px;
    letter-spacing:0.05em;
    margin-left:4px;
    display:none;
  }
  @media (min-width:600px) {
    #topNav .nav-controls .btn-label { display:inline; }
  }

  /* ====== PUNTER ====== */
  #crosshair {
    position:fixed; top:50%; left:50%;
    width:8px; height:8px;
    margin:-4px 0 0 -4px;
    border-radius:50%;
    background:rgba(255,255,255,0.5);
    box-shadow:0 0 12px rgba(0,0,0,0.5), inset 0 0 4px rgba(255,255,255,0.2);
    pointer-events:none; z-index:10;
    transition:transform 0.2s, background 0.2s;
  }
  #crosshair.hover {
    transform:scale(1.8);
    background:rgba(var(--museum-accent-rgb),0.8);
    box-shadow:0 0 24px rgba(var(--museum-accent-rgb),0.3);
  }

  /* ====== HINT ====== */
  #hint {
    position:fixed; left:50%; bottom:34px; transform:translateX(-50%);
    color:#e6e9ec; background:rgba(10,10,10,0.5);
    backdrop-filter:blur(8px);
    padding:10px 24px; border-radius:24px;
    border:1px solid rgba(var(--museum-accent-rgb),0.25);
    font-size:13px; letter-spacing:0.06em;
    pointer-events:none; z-index:10;
    text-align:center; transition:opacity 0.8s, transform 0.8s;
    white-space:nowrap;
  }
  #hint.hidden { opacity:0; transform:translateX(-50%) translateY(20px); }
  #hint kbd {
    background:rgba(255,255,255,0.1);
    padding:2px 8px; border-radius:4px;
    font-size:11px;
    border:1px solid rgba(255,255,255,0.1);
  }

  /* ====== PANTALLA D'INICI ====== */
  #startScreen {
    position:fixed; inset:0; z-index:1200;
    display:flex; flex-direction:column; align-items:center; justify-content:center;
    background:linear-gradient(180deg, rgba(8,8,8,0.96), rgba(12,12,12,0.96));
    text-align:center; padding:28px;
  }
  #startScreen.hidden { display:none; pointer-events:none; opacity:0; transition:opacity 0.32s ease; }
  #startScreen h1 { font-size:clamp(28px,6vw,56px); margin:8px 0; color:#f2f4f6; letter-spacing:0.12em; }
  #startScreen .subtitle { color:var(--museum-accent); font-size:14px; margin-bottom:6px; opacity:0.95; }
  #startScreen .start-name { display:flex; flex-direction:column; align-items:center; gap:6px; margin:18px 0 4px; color:#aab1b8; font-size:13px; letter-spacing:0.04em; }
  #startScreen .start-name input {
    font-family:inherit;
    width:min(280px, 80vw); padding:10px 14px; font-size:16px; text-align:center; color:#f2f4f6;
    background:rgba(255,255,255,0.07); border:1px solid rgba(255,255,255,0.22); border-radius:12px; outline:none;
  }
  #startScreen .start-name input:focus { border-color:var(--museum-accent); box-shadow:0 0 0 2px rgba(var(--museum-accent-rgb),0.25); }
  #startScreen .version { left:50%; transform:translateX(-50%); }
  #startScreen .rule { width:80px; height:1px; background:linear-gradient(90deg,transparent,var(--museum-accent),transparent); margin:18px 0; opacity:0.6; }
  #startScreen p {
    font-size:clamp(13px,1vw,16px);
    color:#a9b0b8;
    max-width:480px;
    line-height:1.8;
    margin:2px 0;
    letter-spacing:0.03em;
  }
  #startScreen .go {
    margin-top:28px;
    padding:14px 40px;
    border:1px solid var(--museum-accent);
    color:var(--museum-accent);
    font-size:13px;
    letter-spacing:0.15em;
    text-transform:uppercase;
    border-radius:30px;
    transition:all 0.3s;
    position:relative;
    overflow:hidden;
    cursor:pointer; z-index:1220;
  }
  #startScreen .go:hover {
    background:rgba(var(--museum-accent-rgb),0.1);
    transform:scale(1.05);
    box-shadow:0 0 30px rgba(var(--museum-accent-rgb),0.1);
  }
  #startScreen .version {
    position:absolute; bottom:20px;
    font-size:11px; color:#4a4f56;
    letter-spacing:0.1em;
  }


  /* ====== XAT MULTIJUGADOR ====== */
  .chat-btn-count { font-size:11px; color:var(--museum-muted); }
  .chat-btn-count:empty { display:none; }
  #toggleChat { position:relative; }
  .chat-unread {
    position:absolute; top:-4px; right:-4px;
    min-width:16px; height:16px; padding:0 4px;
    border-radius:8px; background:#c14a3a; color:#fff;
    font-size:10px; line-height:16px; text-align:center;
  }
  #chatPanel {
    position:fixed; left:16px; bottom:16px;
    width:min(340px, calc(100vw - 32px));
    max-height:50vh;
    display:none; flex-direction:column; gap:8px;
    padding:12px 14px;
    background:rgba(16,14,11,0.92);
    backdrop-filter:blur(18px);
    -webkit-backdrop-filter:blur(18px);
    border:1px solid rgba(var(--museum-accent-rgb),0.4);
    border-radius:14px;
    color:#f2f4f6;
    z-index:60;
    box-shadow:0 16px 48px rgba(0,0,0,0.6);
  }
  #chatPanel.open { display:flex; }
  #chatPanel .chat-header { display:flex; justify-content:space-between; align-items:center; }
  #chatPanel .chat-title { font-size:14px; }
  #chatPanel .chat-title span { margin-left:8px; font-size:11px; color:var(--museum-muted); }
  #chatPanel .chat-close { background:none; border:none; color:#838a92; font-size:16px; cursor:pointer; padding:0 4px; }
  #chatPanel .chat-close:hover { color:var(--museum-accent); }
  #chatPanel .chat-name-row { display:flex; align-items:center; gap:8px; font-size:12px; color:var(--museum-muted); }
  #chatPanel input {
    flex:1; min-width:0;
    background:rgba(255,255,255,0.06);
    border:1px solid rgba(var(--museum-accent-rgb),0.25);
    border-radius:8px; color:#f2f4f6;
    padding:7px 10px; font:inherit; font-size:13px;
  }
  #chatPanel input:focus { outline:none; border-color:var(--museum-accent); }
  #chatPanel .chat-log {
    flex:1; min-height:90px; max-height:28vh; overflow-y:auto;
    display:flex; flex-direction:column; gap:5px;
    font-size:13px; line-height:1.4;
  }
  #chatPanel .chat-line { word-break:break-word; }
  #chatPanel .chat-author { color:var(--museum-accent); margin-right:6px; font-weight:600; }
  #chatPanel .chat-line.self .chat-author { color:#e0b64c; }
  #chatPanel .chat-line.system { color:var(--museum-muted); font-style:italic; font-size:12px; }
  #chatPanel .chat-form { display:flex; gap:6px; }
  #chatPanel .chat-form button {
    background:rgba(var(--museum-accent-rgb),0.15);
    border:1px solid rgba(var(--museum-accent-rgb),0.35);
    border-radius:8px; color:#f2f4f6; padding:0 12px; cursor:pointer; font-size:13px;
  }
  #chatPanel .chat-form button:hover { background:rgba(var(--museum-accent-rgb),0.28); }

  /* ====== LABEL / TARGETA D'OBRA ====== */
  #label {
    position:fixed; left:50%; bottom:100px;
    transform:translateX(-50%) translateY(16px) scale(0.95);
    min-width:220px; max-width:400px;
    padding:18px 24px;
    background:rgba(16,14,11,0.92);
    backdrop-filter:blur(24px);
    -webkit-backdrop-filter:blur(24px);
    border:1px solid rgba(var(--museum-accent-rgb),0.4);
    border-radius:16px;
    color:#f2f4f6;
    opacity:0;
    pointer-events:none;
    z-index:50;
    transition:all 0.35s cubic-bezier(0.34,1.56,0.64,1);
    box-shadow:0 20px 60px rgba(0,0,0,0.7);
  }
  #label.visible {
    opacity:1;
    transform:translateX(-50%) translateY(0) scale(1);
    pointer-events:auto;
  }
  #label [hidden] { display:none !important; }
  #label .label-header {
    display:flex; justify-content:space-between; align-items:center;
    margin-bottom:6px;
  }
  #label .label-number {
    font-size:11px; color:#838a92;
    letter-spacing:0.08em;
  }
  #label .label-close {
    color:#838a92; cursor:pointer;
    font-size:18px; line-height:1;
    transition:color 0.2s;
    background:none; border:none;
    padding:0 4px;
  }
  #label .label-close:hover { color:var(--museum-accent); }
  #label .t {
    font-size:18px;
    letter-spacing:0.02em;
    margin-bottom:2px;
    font-weight:400;
  }
  #label .a {
    font-size:13px;
    color:var(--museum-accent);
    letter-spacing:0.06em;
    margin-bottom:2px;
  }
  #label .y {
    font-size:12px;
    color:#838a92;
    font-style:italic;
  }
  #detailComment {
    margin:14px 0 0;
    font-size:13px;
    line-height:1.5;
    color:#d5d9de;
  }
  #detailComment p { margin:0 0 8px; }
  #detailComment p:last-child { margin-bottom:0; }
  #detailComment a { color:var(--museum-accent); }
  #detailComment ul, #detailComment ol { margin:0 0 8px; padding-left:20px; }
  #detailComment h1, #detailComment h2, #detailComment h3,
  #detailComment h4, #detailComment h5, #detailComment h6 { margin:0 0 6px; font-size:14px; font-weight:600; }
  #detailComment blockquote { margin:0 0 8px; padding-left:10px; border-left:2px solid rgba(var(--museum-accent-rgb),0.4); font-style:italic; }
  #label .media-type {
    display:inline-block;
    margin-top:8px;
    padding:3px 8px;
    border:1px solid rgba(var(--museum-accent-rgb),0.28);
    border-radius:4px;
    color:var(--museum-accent);
    font-size:11px;
  }
  #label .label-actions {
    display:flex; gap:8px;
    margin-top:10px;
    flex-wrap:wrap;
  }
  #label .label-actions button,
  #label .label-actions a {
    background:rgba(var(--museum-accent-rgb),0.1);
    border:1px solid rgba(var(--museum-accent-rgb),0.25);
    color:#e6e9ec;
    padding:4px 14px;
    border-radius:20px;
    font-size:11px;
    cursor:pointer;
    transition:all 0.2s;
    text-decoration:none;
    font-family:inherit;
    letter-spacing:0.05em;
  }
  #label .label-actions button:hover,
  #label .label-actions a:hover {
    background:rgba(var(--museum-accent-rgb),0.2);
    border-color:var(--museum-accent);
    transform:scale(1.05);
  }

  /* ====== MINIMAPA ====== */
  #minimapWrap {
    position:fixed; bottom:20px; left:20px; z-index:30;
    background:rgba(10,9,7,0.6);
    backdrop-filter:blur(12px);
    border:1px solid rgba(var(--museum-accent-rgb),0.2);
    border-radius:12px;
    padding:10px;
    transition:all 0.3s;
    box-shadow:0 8px 32px rgba(0,0,0,0.4);
  }
  #minimapWrap.hidden {
    transform:scale(0.8);
    opacity:0;
    pointer-events:none;
  }
  #minimapWrap .mm-title {
    font-size:9px;
    letter-spacing:0.15em;
    text-transform:uppercase;
    color:#838a92;
    margin-bottom:4px;
    text-align:center;
  }
  #minimap { display:block; border-radius:4px; width:120px; height:200px; }
  @media (max-width:600px) {
    #minimapWrap { bottom:12px; left:12px; padding:6px; }
    #minimap { width:80px; height:140px; }
  }

  /* ====== PEFORMANCE OVERLAY ====== */
  #perfOverlay {
    position:fixed; bottom:20px; right:20px; z-index:30;
    color:#9aa4b0;
    background:rgba(0,0,0,0.4);
    backdrop-filter:blur(8px);
    padding:6px 12px;
    border-radius:20px;
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size:11px;
    letter-spacing:0.05em;
    border:1px solid rgba(255,255,255,0.04);
    pointer-events:none;
    transition:opacity 0.3s;
  }
  #perfOverlay.hidden { opacity:0; }

  /* ====== BOTÓ SORTIR ====== */
  #exitBtn {
    position:fixed; top:70px; left:50%; transform:translateX(-50%);
    z-index:90;
    background:rgba(10,9,7,0.6);
    backdrop-filter:blur(12px);
    color:#e6e9ec;
    border:1px solid rgba(var(--museum-accent-rgb),0.3);
    padding:8px 20px;
    border-radius:24px;
    font-size:12px;
    letter-spacing:0.08em;
    text-transform:uppercase;
    font-family:inherit;
    cursor:pointer;
    transition:all 0.3s;
    display:none;
  }
  #exitBtn:hover {
    background:rgba(var(--museum-accent-rgb),0.1);
    border-color:var(--museum-accent);
    transform:translateX(-50%) scale(1.05);
  }

  /* ====== JOYSTICK ====== */
  .joystick-base {
    position:fixed; width:120px; height:120px; border-radius:50%;
    border:2px solid rgba(var(--museum-accent-rgb),0.4);
    background:rgba(20,17,12,0.3);
    backdrop-filter:blur(8px);
    pointer-events:none; z-index:60;
    margin:-60px 0 0 -60px;
    display:none;
  }
  .joystick-stick {
    position:fixed; width:52px; height:52px; border-radius:50%;
    background:radial-gradient(circle at 40% 35%, rgba(var(--museum-accent-rgb),0.8), rgba(var(--museum-accent-rgb),0.3));
    border:1px solid rgba(241,233,214,0.5);
    pointer-events:none; z-index:61;
    margin:-26px 0 0 -26px;
    display:none;
    box-shadow:0 4px 20px rgba(0,0,0,0.3);
  }

  /* ====== OVERLAY DE DETALL D'OBRA ====== */
  .artwork-detail-overlay {
    position:fixed; inset:0; z-index:300;
    display:flex; align-items:center; justify-content:center;
    background:rgba(0,0,0,0.7);
    backdrop-filter:blur(20px);
    -webkit-backdrop-filter:blur(20px);
    padding:20px;
    animation: fadeIn 0.4s ease;
  }
  .artwork-detail-overlay .content {
    max-width:520px; width:100%;
    background:rgba(20,18,15,0.95);
    border:1px solid rgba(var(--museum-accent-rgb),0.3);
    border-radius:24px;
    padding:32px 36px;
    box-shadow:0 40px 80px rgba(0,0,0,0.8);
    animation: slideUp 0.4s cubic-bezier(0.34,1.56,0.64,1);
    max-height:calc(100vh - 40px); max-height:calc(100dvh - 40px); overflow-y:auto;
    -webkit-overflow-scrolling:touch; overscroll-behavior:contain;
  }
  .artwork-detail-overlay .content h2 {
    font-size:clamp(22px,3vw,32px);
    font-weight:400;
    margin-bottom:4px;
    color:#f2f4f6;
  }
  .artwork-detail-overlay .content .artist {
    font-size:clamp(14px,1.2vw,18px);
    color:var(--museum-accent);
    letter-spacing:0.06em;
    margin-bottom:2px;
  }
  .artwork-detail-overlay .content .year {
    font-size:14px;
    color:#838a92;
    margin-bottom:16px;
  }
  .artwork-detail-overlay .content .description {
    font-size:15px;
    line-height:1.8;
    color:#ccd2d8;
    margin-bottom:20px;
  }
  .artwork-detail-overlay .content .actions {
    display:flex; gap:10px;
    flex-wrap:wrap;
  }
  .artwork-detail-overlay .content .actions button,
  .artwork-detail-overlay .content .actions a {
    padding:10px 24px;
    border-radius:30px;
    border:1px solid rgba(var(--museum-accent-rgb),0.3);
    background:rgba(var(--museum-accent-rgb),0.05);
    color:#e6e9ec;
    cursor:pointer;
    font-family:inherit;
    font-size:13px;
    text-decoration:none;
    transition:all 0.2s;
    letter-spacing:0.04em;
  }
  .artwork-detail-overlay .content .actions button:hover,
  .artwork-detail-overlay .content .actions a:hover {
    background:rgba(var(--museum-accent-rgb),0.15);
    border-color:var(--museum-accent);
    transform:scale(1.03);
  }
  .artwork-detail-overlay .content .actions .btn-close {
    background:rgba(255,255,255,0.05);
    border-color:rgba(255,255,255,0.1);
    margin-left:auto;
  }
  .artwork-detail-overlay .content .actions .btn-close:hover {
    background:rgba(255,255,255,0.1);
  }

  @keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
  @keyframes slideUp { from { opacity:0; transform:translateY(30px); } to { opacity:1; transform:translateY(0); } }

  /* ====== HELP OVERLAY ====== */
  #helpOverlay {
    position:fixed; inset:0; z-index:250;
    display:none;
    align-items:center; justify-content:center;
    background:rgba(0,0,0,0.65);
    backdrop-filter:blur(16px);
    padding:20px;
  }
  #helpOverlay.visible { display:flex; }
  #helpOverlay .content {
    max-width:480px; width:100%;
    background:rgba(20,18,15,0.95);
    border:1px solid rgba(var(--museum-accent-rgb),0.25);
    border-radius:24px;
    padding:32px 36px;
    animation: slideUp 0.4s cubic-bezier(0.34,1.56,0.64,1);
    max-height:calc(100vh - 40px); max-height:calc(100dvh - 40px); overflow-y:auto;
    -webkit-overflow-scrolling:touch; overscroll-behavior:contain;
  }
  #helpOverlay .content .shortcut.touch-only { display:none; }
  #helpOverlay .content h2 {
    font-size:24px; font-weight:400;
    margin-bottom:16px;
    color:#f2f4f6;
  }
  #helpOverlay .content .shortcut {
    display:flex; justify-content:space-between;
    padding:8px 0;
    border-bottom:1px solid rgba(255,255,255,0.04);
    font-size:14px;
    color:#ccd2d8;
  }
  #helpOverlay .content .shortcut kbd {
    background:rgba(255,255,255,0.08);
    padding:2px 12px;
    border-radius:6px;
    font-size:12px;
    color:var(--museum-accent);
    border:1px solid rgba(255,255,255,0.05);
  }
  #helpOverlay .content .close-help {
    margin-top:20px;
    padding:10px 30px;
    border-radius:30px;
    border:1px solid rgba(var(--museum-accent-rgb),0.3);
    background:rgba(var(--museum-accent-rgb),0.05);
    color:#e6e9ec;
    cursor:pointer;
    font-family:inherit;
    font-size:13px;
    transition:all 0.2s;
    width:100%;
  }
  #helpOverlay .content .close-help:hover {
    background:rgba(var(--museum-accent-rgb),0.15);
  }

  .artProgress {
    position:fixed;
    width:120px;
    height:8px;
    overflow:hidden;
    transform:translate(-50%,-50%);
    display:none;
    z-index:40;
    pointer-events:none;
    border:1px solid rgba(255,255,255,0.18);
    border-radius:4px;
    background:rgba(8,10,14,0.82);
    box-shadow:0 2px 8px rgba(0,0,0,0.45);
  }
  .artProgress .bar {
    width:0;
    height:100%;
    border-radius:inherit;
    background:linear-gradient(90deg,#9aa4b0,#eaf1fb);
    transition:width 0.12s linear;
  }
  .artProgress.indeterminate .bar {
    width:35%;
    animation:progressSweep 1.1s ease-in-out infinite alternate;
  }
  @keyframes progressSweep { from { transform:translateX(0); } to { transform:translateX(185%); } }

  /* ====== ERROR OVERLAY ====== */
  #errorOverlay {
    position:fixed; left:12px; right:12px; top:50px; max-height:60vh;
    overflow:hidden; z-index:500;
    color:#fff; background:rgba(64,12,12,0.95);
    padding:18px; border-radius:12px;
    display:none; font-family:monospace; font-size:13px;
    border:1px solid rgba(255,80,80,0.2);
  }
  #errorOverlay .title{ font-weight:700; color:#ffd2d2; margin-bottom:8px; }
  #errorOverlay #errorText{ max-height:calc(60vh - 110px); max-height:calc(60dvh - 110px); overflow:auto; white-space:pre-wrap; word-break:break-word; }
  #errorOverlay .controls{ margin-top:10px; display:flex; gap:8px; flex-wrap:wrap; }
  #errorOverlay .controls button{
    padding:6px 16px; border-radius:6px; border:none;
    background:rgba(255,255,255,0.1); color:#fff; cursor:pointer;
  }
  #errorOverlay .controls button:hover{ background:rgba(255,255,255,0.2); }

  /* ====== RESPONSIVE ====== */
  @media (max-width:720px), (pointer:coarse) {
    #label { bottom:140px; min-width:180px; max-width:88vw; padding:14px 18px; }
    #label .t { font-size:16px; }
    #hint { font-size:11px; padding:6px 14px; bottom:16px; white-space:normal; }
    /* progress bars removed */
    #topNav { padding:8px 12px; }
    #topNav .nav-controls button { padding:4px 10px; font-size:12px; min-width:30px; }
    #perfOverlay { bottom:12px; right:12px; font-size:10px; padding:4px 10px; }
    .artwork-detail-overlay .content { padding:24px 20px; margin:12px; }
    #helpOverlay .content { padding:24px 20px; margin:12px; }
    #exitBtn { top:60px; font-size:11px; padding:6px 16px; }
    #helpOverlay, .artwork-detail-overlay { padding:12px; }
    #helpOverlay .content { padding:20px 18px; border-radius:20px; }
    #helpOverlay .content h2 { font-size:20px; margin-bottom:8px; }
    #helpOverlay .content .shortcut { flex-wrap:wrap; gap:6px 10px; align-items:center; font-size:13px; }
    #helpOverlay .content .shortcut.kbd-only { display:none; }
    #helpOverlay .content .shortcut.touch-only { display:flex; }
    #helpOverlay .content .close-help { padding:14px; font-size:14px; }
    .artwork-detail-overlay .content { border-radius:20px; }
    .artwork-detail-overlay .content .actions button,
    .artwork-detail-overlay .content .actions a { flex:1 1 40%; padding:13px 16px; text-align:center; }
    .artwork-detail-overlay .content .actions .btn-close { margin-left:0; flex-basis:100%; }
    .artwork-detail-overlay .content .actions {
      position:sticky; bottom:-24px; margin:0 -20px -24px; padding:12px 20px 24px;
      background:linear-gradient(180deg, rgba(20,18,15,0.85), rgba(20,18,15,1) 22%);
    }

    /* Targeta d'obra: ample complet, ancorada a baix i amb scroll intern */
    #label {
      left:50%;
      bottom:calc(12px + env(safe-area-inset-bottom, 0px));
      width:calc(100vw - 24px); max-width:440px; min-width:0;
      max-height:calc(100vh - 128px); max-height:calc(100dvh - 128px);
      padding:14px 16px;
      display:flex; flex-direction:column;
      z-index:95;
    }
    #label > * { flex-shrink:0; }
    #label .media-type { align-self:flex-start; }
    #label .label-close { font-size:22px; padding:4px 10px; margin:-6px -10px -6px 0; }
    #label .label-actions { flex-wrap:wrap; }
    #label .label-actions button,
    #label .label-actions a { flex:1 1 auto; padding:10px 14px; font-size:13px; text-align:center; }

    /* Xat: sota la barra superior, per sobre de tot i sense sortir de pantalla */
    #chatPanel {
      top:calc(54px + env(safe-area-inset-top, 0px)); bottom:auto;
      left:8px; right:8px; width:auto; max-width:460px;
      max-height:calc(100vh - 70px); max-height:calc(100dvh - 70px);
      z-index:95;
    }
    #chatPanel .chat-log { min-height:60px; max-height:none; flex:1 1 auto; -webkit-overflow-scrolling:touch; overscroll-behavior:contain; }
    #chatPanel input { font-size:16px; padding:10px 12px; }
    #chatPanel .chat-form button { padding:0 16px; font-size:14px; }
    #chatPanel .chat-close { font-size:22px; padding:4px 10px; margin:-4px -8px -4px 0; }
    #startScreen .version { display:none; }

    #errorOverlay { top:calc(54px + env(safe-area-inset-top, 0px)); font-size:12px; padding:14px; }
    #errorOverlay .controls button { padding:10px 16px; flex:1 1 auto; }
  }
  @media (max-width:420px) {
    #topNav { padding-left:calc(10px + env(safe-area-inset-left, 0px)); padding-right:calc(10px + env(safe-area-inset-right, 0px)); }
    #topNav .logo span { display:none; }
    #topNav .nav-controls { gap:5px; }
    #topNav .nav-controls button { padding:4px 8px; }
  }
  /* Mòbil en horitzontal: poca alçada */
  @media (max-height:500px) {
    #topNav { padding-top:6px; padding-bottom:6px; }
    #exitBtn { top:50px; }
    #minimapWrap { bottom:8px; left:8px; padding:5px; }
    #minimapWrap .mm-title { display:none; }
    #minimap { width:72px; height:120px; }
    #label {
      max-height:calc(100vh - 100px); max-height:calc(100dvh - 100px);
      width:min(440px, calc(100vw - 24px)); bottom:8px;
      padding:10px 14px;
    }
    #label .label-header { margin-bottom:0; }
    #label .t { font-size:15px; }
    #label .media-type { margin-top:6px; }
    #label .label-actions { margin-top:8px; gap:6px; }
    #label .label-actions button, #label .label-actions a { padding:7px 12px; font-size:12px; }
    #chatPanel {
      left:8px; right:auto; width:min(360px, 50vw);
      top:46px; max-height:calc(100vh - 54px); max-height:calc(100dvh - 54px);
      padding:8px 10px; gap:6px;
    }
    #chatPanel .chat-name-row { display:none; }
    #helpOverlay .content, .artwork-detail-overlay .content { max-height:calc(100vh - 24px); max-height:calc(100dvh - 24px); }
    #errorOverlay { top:46px; max-height:calc(100vh - 58px); }
    #errorOverlay #errorText { max-height:calc(100vh - 170px); }
  }

/* ====== PDF BOOK OVERLAY ====== */
.pdf-book-overlay {
  position:fixed; inset:0; z-index:600; display:flex; align-items:center; justify-content:center;
  padding:20px; background:rgba(6,6,6,0.88); backdrop-filter:blur(10px);
}
.pdf-reader {
  width:min(1180px, 96vw); height:min(820px, 92vh); display:flex; flex-direction:column;
  gap:14px; padding:22px; background:#f4f1e8; color:#25251f; border-radius:10px;
  box-shadow:0 32px 100px rgba(0,0,0,0.65);
}
.pdf-reader-header, .pdf-reader-footer, .pdf-page-controls { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.pdf-reader-heading h2 { margin:0; font-size:20px; color:#25251f; }
.pdf-reader-heading p { margin:4px 0 0; color:#706b5f; font-size:13px; }
.pdf-close-btn, .pdf-page-controls button, .pdf-open-link {
  border:1px solid #d5cdbb; border-radius:5px; background:#fffdf7; color:#25251f;
  padding:9px 13px; font:inherit; text-decoration:none; cursor:pointer;
}
.pdf-page-controls button:disabled { opacity:.45; cursor:not-allowed; }
.pdf-open-link { background:#795c31; border-color:#795c31; color:#fff; }
.pdf-reader-status { min-height:20px; color:#686356; font-size:13px; }
.pdf-reader-body { min-height:0; flex:1; display:flex; }
.pdf-page-wrap { min-height:0; flex:1; display:flex; align-items:center; justify-content:center; overflow:auto; background:#d8d5cc; border-radius:5px; padding:14px; }
.pdf-page-canvas { display:block; max-width:100%; height:auto; background:#fff; box-shadow:0 4px 16px rgba(0,0,0,.2); }
.pdf-reader-footer { flex-wrap:wrap; }
.pdf-page-indicator { min-width:118px; text-align:center; color:#454238; font-size:14px; }
.pdf-reader button:focus-visible, .pdf-reader a:focus-visible { outline:3px solid #a87b35; outline-offset:2px; }

@media (max-width:720px) {
  .pdf-book-overlay { padding:8px; }
  .pdf-reader { width:100%; height:96vh; padding:14px; gap:10px; }
  .pdf-reader-body { min-height:180px; }
  .pdf-reader-footer { justify-content:center; }
}

/* ====== BOOK VISUAL ====== */
.book-visual { width:44%; height:100%; display:flex; align-items:center; justify-content:center; }
.book { width:92%; height:92%; background:linear-gradient(180deg,#f8f5ee,#eef1f4); border-radius:8px; box-shadow:inset 0 0 0 6px #e6dcc8; display:flex; overflow:hidden; }
.book .spine { width:28px; background:#d7c8a4; box-shadow:inset 0 0 8px rgba(0,0,0,0.06); }
.book .pages { flex:1; display:flex; }
.book .page { width:50%; padding:18px; box-sizing:border-box; font-family: Georgia, serif; color:#2b2b2b; overflow:auto; }
.book .page h3 { margin-top:0; color:#1b1b1b; }
.book .page p { line-height:1.6; color:#2f2f2f; }
.book .page .meta { margin-top:8px; font-size:13px; color:#6b5b3a; }
.book .page .open-link { display:inline-block; margin-top:12px; padding:6px 10px; background:#b9c0c7; color:#fff; border-radius:8px; text-decoration:none; }

/* Tauletes (iPad): panell d'obra més ample i xat sense tapar el botó de sortida */
@media (min-width:721px) and (pointer:coarse) and (min-height:501px) {
  #label { width:min(560px, calc(100vw - 48px)); max-width:560px; }
  #chatPanel { left:16px; right:auto; width:min(420px, calc(100vw - 32px)); }
  #topNav .nav-controls button { padding:8px 16px; font-size:14px; }
  #hint { font-size:13px; padding:10px 22px; bottom:34px; }
}
