* { box-sizing: border-box; margin: 0; padding: 0; }

  html, body {
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Custom scrollbar (Win95-styled) for anything that needs to scroll */
  * {
    scrollbar-width: thin;
    scrollbar-color: #a0a0a0 #ECE9D8;
  }
  *::-webkit-scrollbar { width: 8px; height: 8px; }
  *::-webkit-scrollbar-track { background: #ECE9D8; }
  *::-webkit-scrollbar-thumb {
    background: #BDBDBD;
    border: 1px solid #808080;
  }
  *::-webkit-scrollbar-thumb:hover { background: #a0a0a0; }

  body {
    background: #ECE9D8;
    font-family: "Microsoft Sans Serif", "MS Sans Serif", Tahoma, Arial, sans-serif;
    display: flex;
    justify-content: center;
    padding: 20px 10px 40px;
    min-height: 100vh;
    width: 100%;
    color: #000;
  }

  /* ============================================================
     Layout: mobile-first.
     Default (narrow / not enough room) = everything lives behind
     a row of buttons at the top; click one, it drops open as a
     small dialog, click outside (or another button) and it closes.
     A min-width media query further down turns the SAME markup
     into always-visible side panels once there's room for them.
     ============================================================ */

  .page {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    width: 100%;
    max-width: 100%;
  }

  .center-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }

  .topmenu {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    width: 100%;
    max-width: 100%;
  }

  .menu-item { position: relative; }

  .menu-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #BDBDBD;
    border: 2px solid;
    border-color: #fff #808080 #808080 #fff;
    padding: 7px 12px;
    font-family: inherit;
    font-weight: bold;
    font-size: 14px;
    color: #000;
    cursor: pointer;
    white-space: nowrap;
  }
  .level-menu-btn { font-size: 14.5px; }
  .menu-btn:active,
  .menu-item.open .menu-btn { border-color: #808080 #fff #fff #808080; }
  .menu-caret { font-size: 10px; opacity: 0.7; }

  .menu-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    width: max-content;
    min-width: 220px;
    max-width: min(320px, calc(100vw - 20px));
    max-height: min(70vh, 480px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #ECE9D8;
    border: 2px solid;
    border-color: #fff #404040 #404040 #fff;
    box-shadow: 3px 3px 0 rgba(0,0,0,0.35);
    padding: 10px;
    font-size: 13px;
    text-align: left;
  }
  .menu-item.open .menu-dropdown { display: block; }

  .panel-section { margin-bottom: 14px; }
  .panel-section:last-child { margin-bottom: 0; }

  .panel-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: bold;
    font-size: 14.5px;
    border-bottom: 1px solid #808080;
    padding-bottom: 4px;
    margin-bottom: 6px;
  }
  .panel-title svg { width: 15px; height: 15px; flex-shrink: 0; }

  .leaderboard-list, .records-list {
    list-style: none;
    font-size: 14px;
    max-height: 240px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .leaderboard-list li, .records-list li {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 0;
    border-bottom: 1px dotted #c8c2ab;
  }
  .leaderboard-list li:last-child, .records-list li:last-child { border-bottom: none; }
  .records-list li { justify-content: space-between; }
  .lb-rank { font-weight: bold; width: 16px; color: #163f8c; }
  .lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lb-value { font-weight: bold; }
  .lb-empty, .records-hint {
    font-size: 11.5px;
    color: #555;
    padding: 4px 0;
    border-bottom: none !important;
  }

  .social-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
  .social-row svg { width: 16px; height: 16px; flex-shrink: 0; }
  .social-link { display: flex; align-items: center; gap: 8px; text-decoration: none; color: #000; }
  .social-link:hover .social-handle { text-decoration: underline; }
  .social-handle { color: #163f8c; }

  .lb-you { background: #fff7d6; }
  .lb-local-tag { font-size: 10.5px; color: #840000; font-weight: normal; }

  /* Custom-field popup dialog */
  .modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 300;
    padding: 12px;
  }
  .modal-overlay.open { display: flex; }

  .modal-box {
    background: #ECE9D8;
    border: 3px solid;
    border-color: #fff #404040 #404040 #fff;
    box-shadow: 4px 4px 0 rgba(0,0,0,0.35);
    padding: 12px;
    width: min(300px, 100%);
  }

  .modal-title {
    font-weight: bold;
    font-size: 14px;
    border-bottom: 1px solid #808080;
    padding-bottom: 6px;
    margin-bottom: 10px;
  }

  .modal-msg {
    font-size: 11.5px;
    color: #840000;
    min-height: 14px;
    margin: 4px 0 8px;
  }

  .modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
  }
  .modal-actions .btn-95 { width: auto; flex: 1; }

  .auth-page { box-sizing: border-box; padding: 2px; }

  .field { display: flex; flex-direction: column; gap: 2px; margin-bottom: 6px; font-size: 12px; }
  .field input {
    width: 100%;
    max-width: 100%;
    border: 2px solid; border-color: #808080 #fff #fff #808080;
    background: #fff; padding: 3px 5px; font-family: inherit; font-size: 13px;
  }
  .field input:focus { outline: 1px dotted #163f8c; }

  .btn-95 {
    background: #BDBDBD;
    border: 2px solid;
    border-color: #fff #808080 #808080 #fff;
    padding: 3px 10px;
    font-family: inherit; font-weight: bold; font-size: 12.5px;
    cursor: pointer; width: 100%;
  }
  .btn-95:active { border-color: #808080 #fff #fff #808080; }
  .btn-95:disabled { color: #808080; cursor: default; }

  .btn-95.secondary { margin-top: 6px; }

  .auth-msg { font-size: 11.5px; color: #840000; min-height: 14px; margin-top: 4px; }

  .auth-switch { font-size: 11.5px; color: #555; margin-top: 8px; text-align: center; }
  .auth-switch a { color: #163f8c; text-decoration: none; }
  .auth-switch a:hover { text-decoration: underline; }

  .guest-row { text-align: center; margin-top: 8px; padding-top: 8px; border-top: 1px dotted #c8c2ab; }
  .guest-row .guest-label { font-size: 11.5px; color: #555; margin-bottom: 6px; }

  .account-box { text-align: center; }
  .account-user {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    font-weight: bold; font-size: 15px; margin-bottom: 10px;
  }
  .account-user svg { width: 16px; height: 16px; }
  .account-status {
    font-size: 12px; margin-top: 10px; padding: 6px;
    border: 1px solid #808080; background: #fff;
  }
  .account-status.eligible { color: #000; }
  .account-status.not-eligible { color: #840000; }

  .guest-box { text-align: center; }
  .guest-box .guest-title {
    font-weight: bold; font-size: 15px; margin-bottom: 8px;
  }
  .guest-box .guest-note {
    font-size: 12px; color: #555; margin-bottom: 10px;
  }

  .frame {
    display: inline-block;
    max-width: 100%;
    border: 3px solid;
    border-color: #808080 #fff #fff #808080;
    padding: 6px;
    background: #BDBDBD;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #BDBDBD;
    border: 2px solid;
    border-color: #808080 #fff #fff #808080;
    padding: 4px;
    margin-bottom: 6px;
  }

  .counter {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #BDBDBD;
    color: #000;
    font-family: "Consolas", "Courier New", monospace;
    font-weight: bold;
    font-size: 22px;
    padding: 3px 8px;
    border: 2px solid;
    border-color: #7a7a7a #fff #fff #7a7a7a;
    min-width: 70px;
    line-height: 1.1;
  }
  .counter-icon { display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
  .counter-icon svg { width: 18px; height: 18px; }
  .counter-value { flex: 1; text-align: right; }

  #faceBtn {
    width: 36px; height: 36px;
    background: #BDBDBD;
    border: 2px solid;
    border-color: #fff #808080 #808080 #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
  }
  #faceBtn:active { border-color: #808080 #fff #fff #808080; }
  #faceBtn svg { width: 22px; height: 22px; }

  .level-dropdown { min-width: 260px; }

  .level-groups {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .level-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
  }

  .level-group-title {
    font-weight: bold;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #163f8c;
    border-bottom: 1px solid #808080;
    padding-bottom: 4px;
    margin-bottom: 3px;
  }

  .level-option {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 6px 8px;
    border: 1px solid transparent;
  }
  .level-option:hover { background: #d8d4c0; }
  .level-option input {
    accent-color: #163f8c;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
  }
  .level-option-name {
    flex: 1;
    font-size: 14px;
    font-weight: bold;
  }
  .level-option-dims {
    font-size: 12.5px;
    color: #555;
    font-family: "Consolas", "Courier New", monospace;
  }
  .level-option.checked {
    background: #163f8c;
    border-color: #0b2c66;
  }
  .level-option.checked .level-option-name,
  .level-option.checked .level-option-dims { color: #fff; }

  #board {
    display: grid;
    gap: 0;
    width: max-content;
    background: #BDBDBD;
    --cell-size: 24px;
  }

  #board.hex-board {
    display: block;
    width: auto;
    position: relative;
    background: transparent;
  }

  .cell {
    width: var(--cell-size, 24px); height: var(--cell-size, 24px);
    display: flex; align-items: center; justify-content: center;
    font-family: "Microsoft Sans Serif", "MS Sans Serif", Tahoma, sans-serif;
    font-weight: bold;
    font-size: calc(var(--cell-size, 24px) * 0.62);
    cursor: default;
    background: #BDBDBD;
    border: 2px solid;
    border-color: #fff #808080 #808080 #fff;
    user-select: none;
    position: relative;
    color: #000;
  }
  .cell:active:not(.revealed):not(.exploded) {
    border-color: #808080 #808080 #808080 #808080;
  }

  .cell.revealed {
    border: 1px solid #a0a0a0;
    background: #BDBDBD;
  }

  .cell.exploded { background: #ff3b3b; }
  .cell.mine-reveal { background: #BDBDBD; }
  .cell.wrong-flag { background: #BDBDBD; }

  .cell svg { width: calc(var(--cell-size, 24px) * 0.68); height: calc(var(--cell-size, 24px) * 0.68); }

  .cell:not(.revealed):hover {
    background: #d6d2c2;
  }

  /* Hex/circle cell styles live in circle.css (loaded only in circle mode) */

  .n1 { color: #0000FF; }
  .n2 { color: #008200; }
  .n3 { color: #FF0000; }
  .n4 { color: #000084; }
  .n5 { color: #840000; }
  .n6 { color: #008284; }
  .n7 { color: #000000; }
  .n8 { color: #808080; }

  .status-bar {
    background: #ECE9D8;
    font-size: 16px;
    padding: 3px 8px;
    color: #333;
    text-align: center;
    max-width: 90vw;
  }

  /* circle-mode overrides are in circle.css */

  @media (max-width: 460px) {
    body { padding: 14px 8px 30px; }
    .menu-btn { padding: 5px 8px; font-size: 12px; }
  }

  /* ============================================================
     Wide screen (plenty of room): the exact same elements above
     lock open as permanent side panels, Win95-desktop style —
     left column (leaderboard/records/find us), center (levels +
     board), right column (account). Buttons are hidden; nothing
     to click, nothing to close.
     ============================================================ */
  @media (min-width: 901px) {
    .page {
      display: grid;
      grid-template-columns: 220px minmax(0, 1fr) 220px;
      grid-template-areas:
        "lb    level  acct"
        "rec   center acct"
        "soc   center acct";
      align-items: start;
      gap: 16px;
      width: auto;
    }

    .topmenu { display: contents; }
    .menu-item { position: static; }
    .menu-btn { display: none; }

    .menu-dropdown {
      display: block;
      position: static;
      transform: none;
      width: 100%;
      min-width: 0;
      max-width: 100%;
      max-height: none;
      box-shadow: none;
      border-color: #fff #808080 #808080 #fff;
    }

    .menu-item[data-menu="leaderboard"] { grid-area: lb; }
    .menu-item[data-menu="records"]     { grid-area: rec; }
    .menu-item[data-menu="social"]      { grid-area: soc; }
    .menu-item[data-menu="account"]     { grid-area: acct; }
    .menu-item[data-menu="level"]       { grid-area: level; }
    .center-column                      { grid-area: center; }

    .menu-item[data-menu="level"] .menu-dropdown {
      background: transparent;
      border: none;
      padding: 0;
      text-align: center;
    }
    .menu-item[data-menu="level"] .level-groups {
      flex-direction: row;
      justify-content: center;
      gap: 0;
    }
    .menu-item[data-menu="level"] .level-group {
      padding: 0 22px;
      min-width: 180px;
    }
    .menu-item[data-menu="level"] .level-group + .level-group {
      border-left: 1px solid #808080;
      box-shadow: 1px 0 0 #fff;
    }
    .menu-item[data-menu="level"] .level-group-title {
      text-align: center;
      font-size: 14px;
    }
    .menu-item[data-menu="level"] .level-option-name { font-size: 14.5px; }
  }
