/* Media queries & viewport adaptations */

/* Optional framed stage only on large desktops */
@media (min-width: 1400px) and (min-height: 860px) {
  .game {
    padding: 16px;
  }

  .stage {
    inset: 16px;
    width: auto;
    height: auto;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 12px 40px var(--shadow);
    border: 3px solid var(--ink);
  }
}

/* Mouse = desktop hold glyph; touch keeps phone-shaped icon */
@media (pointer: fine) {
  .hold-icon {
    border-radius: 8px;
  }

  .hold-icon::after {
    left: 3px;
    margin-left: 0;
    top: 3px;
    width: 7px;
    height: 10px;
    border-radius: 3px 0 0 0;
    animation: none;
    opacity: 1;
  }
}

@media (min-width: 640px) {
  .mode-row {
    flex-direction: row;
    justify-content: center;
  }

  .mode-row .btn {
    width: auto;
    min-width: 10rem;
  }
}

/* —— Phone / narrow HUD denser —— */
@media (max-width: 820px), (orientation: portrait), (orientation: landscape) and (max-height: 520px) {
  .game {
    padding: 0;
  }

  .stage {
    inset: 0 !important;
    border-radius: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
  }

  .hud {
    z-index: 2;
  }

  :root {
    --hud-pad: max(0.4rem, env(safe-area-inset-left, 0px), 0.35rem);
    --touch: 44px;
  }

  .hud-top {
    top: max(var(--hud-pad), env(safe-area-inset-top, 0px));
    left: max(var(--hud-pad), env(safe-area-inset-left, 0px));
    right: max(var(--hud-pad), env(safe-area-inset-right, 0px));
    gap: 0.3rem !important;
    flex-wrap: wrap;
  }

  .hud-stats {
    max-width: calc(100% - 0.5rem);
    padding: 0.3rem 0.4rem !important;
    gap: 0.25rem !important;
    font-size: 0.78rem;
  }

  .hud-stats .stat {
    padding: 0.2rem 0.35rem;
    border-radius: 8px;
  }

  .hud-stats .stat-xp {
    min-width: 5.5rem;
  }

  .hud-top-actions.glass-bar {
    padding: 0.25rem 0.3rem !important;
    gap: 0.25rem;
  }

  .chum-btn [data-i18n='chum'] {
    display: none;
  }

  .chum-btn {
    min-width: 40px !important;
    padding: 0.35rem 0.45rem !important;
  }

  #btn-leave {
    min-width: 40px !important;
    padding: 0.35rem 0.5rem !important;
    font-size: 0.72rem;
  }

  .hud-side {
    top: auto;
    bottom: max(5.75rem, calc(env(safe-area-inset-bottom, 0px) + 5.25rem));
    right: max(var(--hud-pad), env(safe-area-inset-right, 0px));
    transform: none;
    gap: 0.35rem;
    max-width: 42%;
    align-items: flex-end;
  }

  .meter-frame {
    width: 26px;
    height: clamp(72px, 16vh, 120px);
  }

  .meter,
  .struggle-hud,
  .prompt {
    padding: 0.35rem !important;
  }

  .meter-label {
    max-width: 3.5rem;
    font-size: 0.55rem;
  }

  .prompt {
    padding: 0.35rem 0.5rem !important;
    font-size: 0.75rem;
  }

  .struggle-hud {
    width: min(132px, 40vw);
    gap: 0.35rem;
    padding: 0.35rem !important;
  }

  .struggle-arrow {
    min-height: 40px;
    font-size: 1.15rem;
  }

  .hud-left-dock {
    left: max(var(--hud-pad), env(safe-area-inset-left, 0px));
    bottom: max(var(--hud-pad), env(safe-area-inset-bottom, 0px));
    width: min(210px, calc(100vw - 5.5rem));
    gap: 0.35rem;
  }

  .hud-bottom .btn {
    min-height: 40px;
    padding: 0.4rem 0.5rem;
    font-size: 0.78rem;
  }

  .chat-form input {
    font-size: 16px;
    padding: 0.45rem 0.5rem;
  }

  .chat-toggle,
  .chat-send {
    width: 40px;
    min-width: 40px !important;
    min-height: 40px;
  }

  .chat.expanded .chat-log {
    max-height: min(28vh, 160px);
  }

  .catch-feed {
    top: 18%;
    font-size: 12px;
    padding: 0.35rem 0.65rem;
  }

  .tour-banner {
    top: 28%;
    font-size: 12px;
  }

  .leaderboard {
    top: calc(var(--hud-pad) + 3.2rem);
    font-size: 0.7rem;
    max-width: 42%;
  }
}

@media (max-width: 480px), (max-height: 520px) {
  .hud-stats .stat:not(.stat-cur):not(.stat-xp) .label {
    display: none;
  }
}

@media (orientation: landscape) and (max-height: 480px) {
  .meter-frame {
    height: clamp(70px, 42vh, 110px);
  }

  .hud-bottom .btn-touch {
    min-height: 36px;
    padding: 0.3rem 0.55rem;
  }

  .hud-side {
    bottom: max(4.5rem, calc(env(safe-area-inset-bottom, 0px) + 4rem));
  }

  .prompt {
    padding: 0.3rem 0.45rem !important;
  }

  .hud-left-dock {
    width: min(200px, 42vw);
  }
}

@media (max-width: 520px) {
  .settings-row {
    grid-template-columns: 1fr;
  }

  .logo {
    font-size: 2.4rem !important;
  }

  .mode-secondary {
    grid-template-columns: 1fr 1fr;
  }

  .hud-gear {
    display: none !important;
  }

  .btn-kicker {
    display: none;
  }

  .lobby-shell {
    padding:
      max(0.5rem, var(--safe-t))
      max(0.5rem, var(--safe-r))
      max(0.5rem, var(--safe-b))
      max(0.5rem, var(--safe-l));
  }

  .lobby-tile {
    font-size: 0.62rem !important;
    min-height: 48px !important;
  }

  .lobby-name-input {
    max-width: 7.5rem;
  }

  .lobby-xp-row {
    max-width: 7.5rem;
  }

  .lobby-cur {
    padding: 0.35rem 0.45rem;
    font-size: 0.78rem;
  }
}

/* —— Tablet / PC: real columns (no display:contents) —— */
@media (min-width: 692px) {
  :root {
    --lobby-rail: 300px;
    --lobby-gap: 1rem;
  }

  .lobby-shell {
    max-width: none;
    width: 100%;
    gap: 0.75rem;
    padding:
      max(0.75rem, var(--safe-t))
      max(1rem, var(--safe-r))
      max(0.75rem, var(--safe-b))
      max(1rem, var(--safe-l));
  }

  .lobby-body {
    display: grid;
    grid-template-columns: var(--lobby-rail) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "rail hero";
    gap: var(--lobby-gap);
    min-height: 0;
    flex: 1;
  }

  .lobby-rail,
  .lobby-hero {
    display: flex !important;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    gap: 0.65rem;
  }

  .lobby-rail {
    grid-area: rail;
  }

  .lobby-hero {
    grid-area: hero;
  }

  .lobby-daily-btn {
    display: none !important;
  }

  /* Quest HUD: no panel chrome — title + compact rows over the scene */
  .lobby-daily {
    display: flex !important;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    gap: 0.35rem;
    padding: 0;
    border: 0;
    border-radius: 0;
    overflow: hidden;
    pointer-events: auto;
    grid-area: unset;
    background: transparent !important;
    box-shadow: none !important;
    color: #eaf6f2;
  }

  .lobby-daily.has-claim {
    box-shadow: none !important;
  }

  .lobby-daily-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    flex-shrink: 0;
    padding: 0 0.1rem;
  }

  .lobby-daily-heading {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
  }

  .lobby-daily-title-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
  }

  .lobby-daily-heading h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.65);
  }

  .lobby-daily .daily-countdown {
    font-size: 0.7rem;
    opacity: 0.8;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.55);
  }

  .lobby-daily-reroll {
    flex-shrink: 0;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 0.28rem;
    width: auto !important;
    min-width: 0 !important;
    min-height: 32px !important;
    height: 32px !important;
    padding: 0 0.55rem !important;
    border-radius: 999px !important;
    border: 1px solid rgba(230, 195, 92, 0.4);
    background: rgba(0, 0, 0, 0.4) !important;
    box-shadow: none !important;
    color: #f0d56a !important;
    font-weight: 800;
    font-size: 0.78rem;
    cursor: pointer;
  }

  .lobby-daily-reroll:active {
    transform: scale(0.96);
  }

  .lobby-daily-reroll .daily-reroll-ico,
  .lobby-daily-reroll .daily-reroll-ico svg {
    width: 0.95rem;
    height: 0.95rem;
  }

  .lobby-daily-list,
  .lobby-daily .daily-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    gap: 0.2rem;
    padding: 0;
  }

  .lobby-daily .daily-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.35rem 0.55rem;
    padding: 0.4rem 0.5rem 0.4rem 0.55rem;
    border: 0;
    border-radius: 10px;
    /* per-row scrim only — not a shared panel */
    background: rgba(0, 0, 0, 0.42);
    box-shadow: none;
    border-left: 3px solid rgba(143, 211, 192, 0.55);
  }

  .lobby-daily .daily-row.diff-easy {
    border-left-color: #6dcfb0;
  }

  .lobby-daily .daily-row.diff-med {
    border-left-color: #e6c35c;
  }

  .lobby-daily .daily-row.diff-hard {
    border-left-color: #f4a261;
  }

  .lobby-daily .daily-row.ready {
    background: rgba(230, 195, 92, 0.14);
    box-shadow: none;
  }

  .lobby-daily .daily-row.claimed {
    opacity: 0.45;
  }

  .lobby-daily .daily-row-main {
    gap: 0.2rem;
  }

  .lobby-daily .chip-diff {
    display: none;
  }

  .lobby-daily .daily-title {
    font-size: 0.82rem;
    font-weight: 750;
    line-height: 1.2;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.55);
  }

  .lobby-daily .daily-bar {
    height: 0.28rem;
    background: rgba(0, 0, 0, 0.35);
  }

  .lobby-daily .daily-progress {
    font-size: 0.68rem;
    font-variant-numeric: tabular-nums;
  }

  .lobby-daily .daily-row-action {
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    gap: 0.2rem;
  }

  .lobby-daily .daily-reward {
    font-size: 0.85rem;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
  }

  .lobby-daily .daily-claim {
    min-height: 28px !important;
    padding: 0.2rem 0.55rem !important;
    font-size: 0.72rem !important;
    border-radius: 8px !important;
    width: auto !important;
  }

  .lobby-daily .daily-claimed {
    font-size: 0.68rem;
  }

  .lobby-mail-label {
    display: inline;
  }

  .lobby-cur-label {
    display: inline;
  }

  .lobby-currency {
    flex: 0 0 auto;
  }

  .lobby-cur {
    padding: 0.45rem 0.7rem;
    font-size: 0.88rem;
  }

  .lobby-mid-row {
    grid-area: unset;
    grid-template-columns: 1fr;
    gap: 0.35rem;
    margin-top: auto;
    flex-shrink: 0;
  }

  .lobby-tile {
    flex-direction: row !important;
    justify-content: flex-start !important;
    text-align: left;
    min-height: clamp(44px, 6vh, 56px) !important;
    padding: 0.45rem 0.8rem !important;
    font-size: clamp(0.88rem, 1.5vh, 1rem) !important;
    gap: 0.6rem !important;
    white-space: nowrap !important;
  }

  .lobby-tile-ico {
    width: 1.55rem;
    height: 1.55rem;
  }

  .lobby-tile-ico svg {
    width: 1.55rem;
    height: 1.55rem;
  }

  .lobby-stage-gap {
    grid-area: unset;
    flex: 1 1 auto;
    min-height: 0;
  }

  .lobby-bottom-row {
    grid-area: unset;
    display: flex;
    flex-direction: column;
    width: min(100%, 18rem);
    max-width: 18rem;
    margin-left: auto;
    margin-right: 0;
    gap: 0.45rem;
    flex-shrink: 0;
    align-self: flex-end;
  }

  .lobby-cta-play {
    min-height: clamp(48px, 7vh, 64px) !important;
    font-size: clamp(1.05rem, 1.6vh, 1.25rem) !important;
    border-radius: 16px !important;
  }

  .lobby-cta-tourney {
    min-height: clamp(40px, 5.5vh, 48px) !important;
    font-size: clamp(0.9rem, 1.4vh, 1rem) !important;
    opacity: 0.95;
  }

}

@media (min-width: 1200px) {
  :root {
    --lobby-rail: 340px;
    --lobby-gap: 1.25rem;
  }

  .lobby-bottom-row {
    width: min(100%, 20rem);
    max-width: 20rem;
  }

  .lobby-tile {
    min-height: clamp(48px, 6.5vh, 60px) !important;
    font-size: clamp(0.95rem, 1.6vh, 1.05rem) !important;
  }
}

@media (max-width: 700px) {
  .hud-gear {
    max-width: 140px;
  }

  .hud-gear-slot {
    width: 24px;
    height: 24px;
  }

  .bestiary-card {
    height: auto !important;
    max-height: 92vh !important;
    overflow: auto !important;
  }

  .bestiary-body {
    grid-template-columns: 1fr;
    overflow: visible;
    flex: none;
  }

  .bestiary-grid,
  .bestiary-detail {
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 800px) {
  .tackle-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .inv-body {
    grid-template-columns: 1fr !important;
  }

  .inv-grid {
    max-width: 100% !important;
    max-height: 40vh !important;
  }

  .inv-detail {
    max-height: 28vh;
  }

  .tackle-card {
    height: auto !important;
    max-height: 92vh !important;
    overflow: auto !important;
  }

  .tackle-layout {
    grid-template-columns: 1fr !important;
    overflow: visible !important;
    flex: none !important;
  }

  .tackle-grid,
  .shop-sims.tackle-grid {
    max-height: none !important;
    overflow: visible !important;
    flex: none !important;
  }

  .tackle-side {
    overflow: visible !important;
  }

  .tackle-equip {
    overflow: visible !important;
  }

  .tackle-slots {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  .mode-secondary {
    grid-template-columns: 1fr 1fr;
  }

  .tackle-side,
  .tackle-equip {
    overflow: visible !important;
  }

  .tackle-stats-list {
    grid-template-columns: 1fr 1fr;
  }

  .hud-stats {
    max-width: 100%;
  }

  .map-header.glass-bar {
    grid-template-columns: auto 1fr;
  }

  .map-hint {
    display: none;
  }

  .modal-card {
    max-height: min(92dvh, 920px);
  }
}

/* Coarse pointer: larger hit targets, never mouse glyph */
@media (pointer: coarse) {
  .hold-icon {
    border-radius: 10px 10px 12px 12px;
  }

  .hold-icon::after {
    left: 50%;
    margin-left: -3.5px;
    top: 5px;
    width: 7px;
    height: 10px;
    border-radius: 3px;
    animation: holdPulse 1.1s ease-in-out infinite;
    opacity: 1;
  }

  .btn-touch,
  .struggle-arrow {
    min-height: 44px;
  }
}

@media (max-width: 520px) {
  .bazaar-lot {
    flex-direction: column;
  }

  .bazaar-lot-actions {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    width: 100%;
  }

  .bazaar-body {
    max-height: min(48vh, 420px);
  }

  .bazaar-pager-label {
    font-size: 0.72rem;
  }
}
