/* Keep the home dice interface fluid when the browser window is narrow. */
html, body { min-width: 0; max-width: 100%; overflow-x: clip; }
.page-shell { width: 100%; min-width: 0; max-width: 1480px; padding-inline: clamp(8px, 2vw, 24px); }
.game-layout { display: block; width: min(100%, 720px); max-width: 720px; min-width: 0; margin: clamp(8px, 1.6vw, 18px) auto 0; }
.roller-card { width: 100%; min-width: 0; max-width: 100%; min-height: 0 !important; padding: clamp(12px, 2vw, 24px) clamp(10px, 2.5vw, 28px) clamp(14px, 2vw, 22px); }
.vip-panel { min-width: 0; min-height: 0 !important; }
.dice-toolbar, .dice-output-panel, .dice-stage { min-width: 0; max-width: 100%; }
.dice-output-panel { min-height: 0; }
.dice-stage { min-height: clamp(88px, 14vw, 132px) !important; gap: clamp(5px, 1.4vw, 14px) !important; }
.dice-stage > .die { width: clamp(52px, 8vw, 86px); height: clamp(52px, 8vw, 86px); }
.roll-button#roll-button { height: clamp(48px, 6vw, 66px); font-size: clamp(17px, 2.35vw, 23px); }
.dice-counter { min-width: 0; }
.dice-counter-controls { min-width: 0; }
.dice-counter-controls output { min-width: clamp(56px, 9vw, 80px); font-size: clamp(26px, 4vw, 34px); }
.history-section, .color-key { width: min(100%, 720px) !important; min-width: 0; max-width: 720px !important; margin-inline: auto !important; }
.history-item, .history-main, .history-side, .history-colors { min-width: 0; }
.site-banner { width: min(100%, 740px); }
.site-banner img { display: block; width: 100%; height: auto; }

@media (max-width: 700px) {
  .page-shell { padding: 8px 10px calc(66px + env(safe-area-inset-bottom)); }
  .topbar { position: relative; width: 100%; height: auto; min-height: 38px; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 0; }
  .topbar-actions { position: static; width: 100%; max-width: 100%; justify-content: center; flex-wrap: wrap; gap: 6px; }
  .vip-login-button { max-width: min(54vw, 260px); overflow: hidden; text-overflow: ellipsis; }
  .vip-login-button, .topbar-link { min-height: 34px; padding-inline: clamp(7px, 2.4vw, 11px); font-size: clamp(9px, 2.5vw, 11px); }
  .site-banner { width: min(100%, 520px); margin-top: 4px; }
  .game-layout { width: 100%; margin-top: 10px; }
  .roller-card { padding: clamp(12px, 3vw, 18px) clamp(8px, 2.5vw, 14px) 16px; }
  .game-title h1 { font-size: clamp(25px, 7vw, 36px); }
  .dice-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 7px; width: 100%; }
  .toolbar-count, .toolbar-mode, .toolbar-theme { width: 100%; min-width: 0; }
  .toolbar-theme { grid-column: 1 / -1; }
  .dice-toolbar .menu-select-trigger,
  .dice-toolbar .toolbar-count .menu-select-trigger,
  .dice-toolbar .toolbar-mode .menu-select-trigger,
  .dice-toolbar .toolbar-theme .menu-select-trigger { width: 100%; min-width: 0; min-height: 36px; gap: 7px; padding-inline: 8px; font-size: clamp(9px, 2.6vw, 11px); }
  .dice-output-panel { container-type: inline-size; padding: 8px clamp(6px, 2vw, 10px) 6px; }
  .dice-stage[data-dice-count] { display: grid; min-height: 0 !important; grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: center; justify-items: center; gap: clamp(4px, 1.8vw, 9px); padding: 8px 0 12px; }
  .dice-stage[data-dice-count="1"] { grid-template-columns: minmax(0, 1fr); }
  .dice-stage[data-dice-count="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dice-stage[data-dice-count="3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dice-stage[data-dice-count="5"], .dice-stage[data-dice-count="6"],
  .dice-stage[data-dice-count="7"], .dice-stage[data-dice-count="8"],
  .dice-stage[data-dice-count="9"], .dice-stage[data-dice-count="10"] { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .dice-stage[data-dice-count] > .die { width: min(100%, clamp(44px, 23cqw, 96px)); height: auto; aspect-ratio: 1; border-width: clamp(4px, 1.35vw, 6px); border-radius: clamp(10px, 3.2vw, 16px); }
  .dice-stage[data-dice-count] > .die::after { width: 22%; height: 22%; max-width: 22px; max-height: 22px; }
  .verify-id-strip { gap: 5px; padding: 8px 0 2px; font-size: clamp(8px, 2.3vw, 10px); }
  .verify-id-strip > span { min-width: 0; gap: 5px; }
  .verify-id-strip code { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
  .dice-quick-actions { width: 100%; gap: 6px; }
  .dice-quick-actions .toolbar-verify,
  .dice-quick-actions .sound-toggle,
  .dice-quick-actions .dice-blur-switch { min-height: 35px; padding-inline: clamp(7px, 2vw, 10px); font-size: clamp(8px, 2.4vw, 10px); }
  .history-section, .color-key { margin-top: 9px !important; }
  .pinned-color-legend { min-height: 48px; padding-inline: 8px; }
  .pinned-color-list { justify-content: flex-start; gap: clamp(7px, 2.5vw, 12px); overflow-x: auto; }
  .pinned-color-list span { gap: 4px; font-size: clamp(9px, 2.5vw, 10px); }
  .pinned-color-list .swatch { width: 11px; height: 11px; }
}

@media (max-width: 360px) {
  .page-shell { padding-inline: 7px; }
  .roller-card { padding-inline: 7px; }
  .brand { gap: 5px; font-size: 14px; }
  .brand-mark { width: 25px; height: 25px; }
  .dice-stage[data-dice-count] > .die { width: min(100%, clamp(40px, 21cqw, 78px)); }
  .dice-quick-actions { column-gap: 4px; }
  .history-item { gap: 5px; }
}

@media (max-height: 620px) and (min-width: 701px) {
  .page-shell { padding-top: 6px; }
  .site-banner { width: min(100%, 58vh, 560px); margin-top: 3px; }
  .game-layout { margin-top: 7px; }
  .roller-card { padding-block: 12px; }
  .game-title { margin-bottom: 7px; }
  .dice-toolbar { margin-bottom: 7px; }
  .dice-output-panel { min-height: 0; }
  .dice-stage { min-height: 88px !important; padding-block: 5px 8px; }
  .roll-button#roll-button { height: 48px; margin-top: 8px; }
  .dice-quick-actions { margin-top: 8px; }
  .dice-counter { margin-top: 8px; padding-block: 7px; }
}
