@media (max-width: 600px) {
  .node {
    font-size: 14px;
    padding: 12px 20px;
    max-width: 70vw;
  }
  .node.root {
    font-size: 18px;
    padding: 16px 26px;
    max-width: 78vw;
  }
  /* Keyboard-shortcut hints aren't useful on a touch device */
  #hint {
    display: none;
  }
  #title {
    font-size: 11px;
    top: 14px;
    left: 16px;
  }
  #credit {
    font-size: 10px;
    bottom: 12px;
    left: 16px;
    max-width: 62vw;
    line-height: 1.6;
  }
  .credit-divider {
    display: none;
  }
  .coffee-link {
    display: block;
  }
  /* Toolbar collapses into a single round menu button that never competes
     with the THINKPAD logo for space - tapping it drops down a friendly,
     full-width stacked menu instead of a cramped inline row of icons. */
  #toolbar {
    top: 12px;
    right: 12px;
    height: auto;
    padding: 0;
    background: none;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
  }
  #menu-toggle {
    display: flex;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 50%;
    background-image: linear-gradient(var(--node-bg), var(--node-bg)), var(--border-grad);
    background-origin: border-box;
    background-clip: padding-box, border-box;
    color: var(--text);
    font-size: 15px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0,0,0,0.10);
  }

  #toolbar-content {
    display: none;
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    width: 210px;
    padding: 10px;
    border: 1px solid transparent;
    border-radius: 16px;
    background-image: linear-gradient(var(--node-bg), var(--node-bg)), var(--border-grad);
    background-origin: border-box;
    background-clip: padding-box, border-box;
    box-shadow: 0 14px 34px rgba(0,0,0,0.16);
  }
  #toolbar.open #toolbar-content {
    display: flex;
  }

  .toolbar-divider {
    display: none; /* stacked rows use spacing instead of dividers */
  }

  /* #history-group is display:flex (row) by default so its toggle button
     and dropdown panel would otherwise sit side by side - stack them. */
  #history-group {
    width: 100%;
    height: auto;
    flex-direction: column;
    align-items: stretch;
  }
  #history-toggle {
    width: 100%;
    height: 40px;
    max-width: none;
    justify-content: space-between;
    padding: 0 10px;
  }

  /* Every other control becomes a full-width, left-aligned, labeled row */
  #zoom-group, #new-btn, #recenter-btn, #theme-toggle {
    width: 100%;
    height: 40px;
  }
  #history-panel {
    position: static;
    width: 100%;
    max-height: 220px;
    box-shadow: none;
    margin-top: 4px;
  }
  #new-btn {
    text-align: left;
    padding: 0 10px;
    border-radius: 10px;
  }
  #zoom-group {
    justify-content: space-between;
    padding: 0 4px;
  }
  #recenter-btn, #theme-toggle {
    justify-content: flex-start;
    gap: 10px;
    padding: 0 10px;
    border-radius: 10px;
  }
  #recenter-btn:hover, #theme-toggle:hover {
    background: rgba(128,128,128,0.10);
  }
  .btn-label {
    display: inline;
    font-size: 13px;
  }
}
