:root {
  --mvp-toolbar-h: 62px;
  --mvp-paper: #fffaf0;
  --mvp-ink: #241a12;
  --mvp-muted: #7a6654;
  --mvp-line: rgba(36, 26, 18, 0.14);
  --mvp-amber: #c47a22;
}

html.mvp-tool-page {
  max-width: 100%;
  overflow-x: hidden;
  scroll-padding-top: calc(var(--mvp-toolbar-h) + env(safe-area-inset-top));
}

html.mvp-tool-page body {
  max-width: 100%;
  min-height: 100dvh;
  padding-top: calc(var(--mvp-toolbar-h) + env(safe-area-inset-top));
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

html.mvp-tool-page *,
html.mvp-tool-page *::before,
html.mvp-tool-page *::after {
  box-sizing: border-box;
}

.mvp-toolbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 2147483000;
  min-height: calc(var(--mvp-toolbar-h) + env(safe-area-inset-top));
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  border-bottom: 1px solid var(--mvp-line);
  background: rgba(255, 250, 240, 0.94);
  color: var(--mvp-ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: 0 12px 30px rgba(36, 26, 18, 0.08);
}

.mvp-toolbar__inner {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: min(1180px, 100%);
  margin: 0 auto;
}

.mvp-toolbar a,
.mvp-toolbar button,
.mvp-toolbar select {
  min-height: 44px;
  border-radius: 999px;
  font: inherit;
}

.mvp-toolbar a,
.mvp-toolbar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--mvp-line);
  background: #fffefd;
  color: var(--mvp-ink);
  padding: 0 14px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.mvp-toolbar a:hover,
.mvp-toolbar button:hover,
.mvp-toolbar select:hover {
  border-color: rgba(196, 122, 34, 0.42);
}

.mvp-toolbar__title {
  min-width: 0;
}

.mvp-toolbar__title strong {
  display: block;
  overflow: hidden;
  color: var(--mvp-ink);
  font-size: 14px;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mvp-toolbar__title span {
  display: block;
  margin-top: 2px;
  color: var(--mvp-muted);
  font-size: 11px;
  line-height: 1.1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.mvp-toolbar__actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.mvp-toolbar select {
  width: min(260px, 32vw);
  border: 1px solid var(--mvp-line);
  background: #fffefd;
  color: var(--mvp-ink);
  padding: 0 40px 0 14px;
}

.mvp-toolbar__switch {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.mvp-toolbar__switch > span {
  display: none;
}

html.mvp-tool-page input,
html.mvp-tool-page select,
html.mvp-tool-page textarea {
  font-size: max(16px, 1em);
}

html.mvp-tool-page button,
html.mvp-tool-page [role="button"],
html.mvp-tool-page a,
html.mvp-tool-page input,
html.mvp-tool-page select,
html.mvp-tool-page textarea {
  touch-action: manipulation;
}

html.mvp-tool-page img,
html.mvp-tool-page svg,
html.mvp-tool-page canvas,
html.mvp-tool-page video {
  max-width: 100%;
}

@media (max-width: 700px) {
  :root { --mvp-toolbar-h: 58px; }

  .mvp-toolbar {
    padding-inline: 8px;
  }

  .mvp-toolbar__inner {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 7px;
  }

  .mvp-toolbar a,
  .mvp-toolbar button {
    width: 44px;
    padding: 0;
  }

  .mvp-toolbar__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .mvp-toolbar select {
    width: 44px;
    max-width: 44px;
    padding: 0;
    color: transparent;
    appearance: none;
    -webkit-appearance: none;
  }

  .mvp-toolbar__switch > span {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: grid;
    place-items: center;
    pointer-events: none;
    color: var(--mvp-ink);
    font-size: 20px;
    font-weight: 800;
  }

  html.mvp-tool-page .header,
  html.mvp-tool-page .topbar,
  html.mvp-tool-page .toolbar:not(.mvp-toolbar),
  html.mvp-tool-page .header-right,
  html.mvp-tool-page .topbar-actions,
  html.mvp-tool-page .transport,
  html.mvp-tool-page .pattern-bar,
  html.mvp-tool-page .fx-panel,
  html.mvp-tool-page .request-bar,
  html.mvp-tool-page .panel-tabs,
  html.mvp-tool-page .canvas-toolbar {
    max-width: 100vw;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
  }

  html.mvp-tool-beat-lab .sequencer,
  html.mvp-tool-api-playground .panels,
  html.mvp-tool-api-playground .panel-split,
  html.mvp-tool-api-playground .workspace {
    width: 100vw !important;
    max-width: 100vw !important;
    overflow-x: auto !important;
  }

  html.mvp-tool-beat-lab .seq-row {
    min-width: 760px;
  }

  html.mvp-tool-pixel-forge .main,
  html.mvp-tool-api-playground .main {
    display: block !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: auto !important;
    min-height: calc(100dvh - var(--mvp-toolbar-h)) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  html.mvp-tool-pixel-forge .sidebar,
  html.mvp-tool-pixel-forge .canvas-area,
  html.mvp-tool-pixel-forge .right-panel,
  html.mvp-tool-api-playground .sidebar,
  html.mvp-tool-api-playground .workspace {
    width: 100vw !important;
    max-width: 100vw !important;
    min-width: 0 !important;
  }

  html.mvp-tool-pixel-forge .canvas-area,
  html.mvp-tool-pixel-forge .right-panel {
    min-height: 420px;
  }

  html.mvp-tool-arcade-cabinet #menu {
    width: 100vw !important;
    height: auto !important;
    min-height: calc(100dvh - var(--mvp-toolbar-h)) !important;
    justify-content: flex-start !important;
    overflow-x: hidden !important;
    padding: 34px 14px 28px !important;
  }

  html.mvp-tool-arcade-cabinet #menu h1 {
    max-width: 100%;
    font-size: clamp(34px, 13vw, 48px) !important;
    letter-spacing: 1px !important;
  }

  html.mvp-tool-arcade-cabinet #menu .sub {
    max-width: 320px;
    text-align: center;
  }

  html.mvp-tool-arcade-cabinet .game-grid {
    width: 100% !important;
    max-width: 360px !important;
    grid-template-columns: 1fr !important;
    padding: 0 !important;
  }

  html.mvp-tool-arcade-cabinet .game-card {
    min-width: 0 !important;
  }

  html.mvp-tool-offer-compass .content,
  html.mvp-tool-offer-compass .offers-grid,
  html.mvp-tool-offer-compass .compare-grid,
  html.mvp-tool-offer-compass .form-row,
  html.mvp-tool-offer-compass .score-input-group,
  html.mvp-tool-sprint-board .content,
  html.mvp-tool-sprint-board .search-bar,
  html.mvp-tool-sprint-board .filters,
  html.mvp-tool-sprint-board .board,
  html.mvp-tool-sprint-board .sprint-header,
  html.mvp-tool-sprint-board .sprint-progress,
  html.mvp-tool-focus-flow main,
  html.mvp-tool-focus-flow .timer-ring-wrapper,
  html.mvp-tool-focus-flow .chart-grid,
  html.mvp-tool-focus-flow .goal-setting,
  html.mvp-tool-focus-flow .cat-row,
  html.mvp-tool-draft-studio .app,
  html.mvp-tool-draft-studio .main,
  html.mvp-tool-draft-studio .toolbar,
  html.mvp-tool-draft-studio .editor,
  html.mvp-tool-draft-studio .status-bar {
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
  }

  html.mvp-tool-offer-compass .offers-grid,
  html.mvp-tool-offer-compass .compare-grid,
  html.mvp-tool-offer-compass .form-row,
  html.mvp-tool-sprint-board .board,
  html.mvp-tool-focus-flow .chart-grid,
  html.mvp-tool-draft-studio .dash-grid {
    grid-template-columns: 1fr !important;
  }

  html.mvp-tool-offer-compass .content,
  html.mvp-tool-sprint-board .content,
  html.mvp-tool-focus-flow main {
    padding-inline: 14px !important;
  }

  html.mvp-tool-draft-studio .app {
    height: auto !important;
    min-height: calc(100dvh - var(--mvp-toolbar-h)) !important;
    overflow-x: hidden !important;
  }

  html.mvp-tool-draft-studio .sidebar {
    position: fixed !important;
    inset: var(--mvp-toolbar-h) auto 0 0 !important;
    z-index: 1000 !important;
    width: min(82vw, 280px) !important;
    transform: translateX(-100%);
  }

  html.mvp-tool-draft-studio .sidebar:not(.hidden) {
    transform: translateX(0);
  }

  html.mvp-tool-draft-studio .toolbar {
    overflow-x: auto !important;
  }

  html.mvp-tool-draft-studio .editor {
    padding: 24px 16px !important;
  }

  html.mvp-tool-focus-flow .timer-ring-wrapper {
    width: min(320px, calc(100vw - 32px)) !important;
    height: min(320px, calc(100vw - 32px)) !important;
  }

  html.mvp-tool-offer-compass .app-header,
  html.mvp-tool-focus-flow .header {
    flex-wrap: wrap !important;
    gap: 12px !important;
    padding-inline: 14px !important;
  }

  html.mvp-tool-offer-compass .header-actions,
  html.mvp-tool-focus-flow .header-actions {
    width: 100% !important;
    max-width: 100% !important;
    justify-content: flex-start !important;
    flex-wrap: wrap !important;
    overflow-x: visible !important;
  }

  html.mvp-tool-offer-compass .tabs,
  html.mvp-tool-sprint-board .tabs,
  html.mvp-tool-focus-flow .nav {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: auto !important;
    overscroll-behavior-inline: contain;
    padding-inline: 14px !important;
  }

  html.mvp-tool-offer-compass .tab,
  html.mvp-tool-sprint-board .tab,
  html.mvp-tool-focus-flow .nav button {
    flex: 0 0 auto !important;
  }

  /* P0 manual pass: complex tools should stack or reveal the work area first on phones. */
  html.mvp-tool-code-playground body,
  html.mvp-tool-api-playground body,
  html.mvp-tool-data-forge body,
  html.mvp-tool-org-chart-forge body {
    height: 100dvh !important;
  }

  html.mvp-tool-code-playground .topbar,
  html.mvp-tool-api-playground .topbar,
  html.mvp-tool-data-forge .topbar,
  html.mvp-tool-org-chart-forge .toolbar,
  html.mvp-tool-mind-map #toolbar {
    flex-wrap: nowrap !important;
    max-width: 100vw !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  html.mvp-tool-code-playground .topbar,
  html.mvp-tool-api-playground .topbar,
  html.mvp-tool-data-forge .topbar {
    height: auto !important;
    min-height: 46px !important;
    padding: 6px 8px !important;
  }

  html.mvp-tool-code-playground .topbar > *,
  html.mvp-tool-api-playground .topbar > *,
  html.mvp-tool-data-forge .topbar > *,
  html.mvp-tool-org-chart-forge .toolbar > *,
  html.mvp-tool-mind-map #toolbar > * {
    flex: 0 0 auto !important;
  }

  html.mvp-tool-code-playground .project-name {
    width: 128px !important;
    min-width: 128px !important;
  }

  html.mvp-tool-code-playground .sidebar {
    display: none !important;
  }

  html.mvp-tool-code-playground .main-area,
  html.mvp-tool-code-playground .workspace,
  html.mvp-tool-code-playground .editor-area {
    width: 100vw !important;
    max-width: 100vw !important;
    min-width: 0 !important;
  }

  html.mvp-tool-code-playground .editor-area {
    flex-direction: column !important;
  }

  html.mvp-tool-code-playground .resizer,
  html.mvp-tool-code-playground .resizer-h {
    display: none !important;
  }

  html.mvp-tool-code-playground .code-panel,
  html.mvp-tool-code-playground .preview-panel {
    width: 100% !important;
    min-width: 0 !important;
    flex: 1 1 50% !important;
  }

  html.mvp-tool-code-playground .preview-panel {
    min-height: 330px !important;
    border-left: 0 !important;
    border-top: 1px solid var(--border) !important;
  }

  html.mvp-tool-code-playground .status-bar {
    overflow-x: auto !important;
    gap: 16px !important;
  }

  html.mvp-tool-api-playground .main {
    display: flex !important;
    flex-direction: column !important;
    width: 100vw !important;
    max-width: 100vw !important;
  }

  html.mvp-tool-api-playground .sidebar {
    position: static !important;
    inset: auto !important;
    width: 100% !important;
    max-height: 170px !important;
    transform: none !important;
    border-right: 0 !important;
    border-bottom: 1px solid var(--border) !important;
  }

  html.mvp-tool-api-playground .sidebar.collapsed {
    width: 100% !important;
    max-height: 38px !important;
  }

  html.mvp-tool-api-playground .workspace,
  html.mvp-tool-api-playground .panels,
  html.mvp-tool-api-playground .panel-split {
    min-width: 0 !important;
    overflow: visible !important;
  }

  html.mvp-tool-api-playground .request-bar {
    flex-wrap: wrap !important;
    padding: 10px !important;
    gap: 8px !important;
  }

  html.mvp-tool-api-playground .method-select {
    width: 96px !important;
    border-radius: var(--radius) !important;
    border-right: 1px solid var(--border) !important;
  }

  html.mvp-tool-api-playground .url-input {
    flex: 1 1 190px !important;
    min-width: 0 !important;
    border-radius: var(--radius) !important;
  }

  html.mvp-tool-api-playground .send-btn,
  html.mvp-tool-api-playground .save-btn {
    border-radius: var(--radius) !important;
  }

  html.mvp-tool-api-playground .panel-split {
    flex-direction: column !important;
    gap: 10px !important;
  }

  html.mvp-tool-api-playground .panel {
    min-height: 300px !important;
  }

  html.mvp-tool-data-forge body,
  html.mvp-tool-org-chart-forge body {
    flex-direction: column !important;
    overflow: hidden !important;
  }

  html.mvp-tool-data-forge .sidebar,
  html.mvp-tool-org-chart-forge .sidebar {
    width: 100% !important;
    max-width: 100vw !important;
    max-height: 174px !important;
    min-height: 0 !important;
    border-right: 0 !important;
    border-bottom: 1px solid var(--border) !important;
  }

  html.mvp-tool-data-forge .sidebar-header,
  html.mvp-tool-org-chart-forge .sidebar-header {
    padding: 10px 12px !important;
  }

  html.mvp-tool-data-forge .schema-list,
  html.mvp-tool-org-chart-forge .org-list {
    max-height: 78px !important;
  }

  html.mvp-tool-data-forge .main,
  html.mvp-tool-org-chart-forge .main {
    flex: 1 1 auto !important;
    width: 100vw !important;
    max-width: 100vw !important;
    min-height: 0 !important;
  }

  html.mvp-tool-data-forge .content {
    padding: 12px !important;
  }

  html.mvp-tool-data-forge .topbar-right {
    margin-left: 0 !important;
  }

  html.mvp-tool-data-forge .schema-name,
  html.mvp-tool-data-forge .generate-bar,
  html.mvp-tool-data-forge .preview-toolbar {
    flex-wrap: wrap !important;
  }

  html.mvp-tool-data-forge .field-header {
    display: none !important;
  }

  html.mvp-tool-data-forge .field-row,
  html.mvp-tool-data-forge .rel-row {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
    gap: 8px !important;
    padding: 10px 0 !important;
  }

  html.mvp-tool-data-forge .field-row input,
  html.mvp-tool-data-forge .field-row select,
  html.mvp-tool-data-forge .rel-row input,
  html.mvp-tool-data-forge .rel-row select {
    width: 100% !important;
    min-width: 0 !important;
  }

  html.mvp-tool-data-forge .field-row .del-btn,
  html.mvp-tool-data-forge .req-toggle {
    min-width: 40px !important;
    min-height: 36px !important;
  }

  html.mvp-tool-org-chart-forge .toolbar {
    padding: 8px !important;
    gap: 8px !important;
  }

  html.mvp-tool-org-chart-forge .toolbar .search-box {
    flex: 0 0 180px !important;
  }

  html.mvp-tool-org-chart-forge .canvas-wrap {
    min-height: 420px !important;
  }

  html.mvp-tool-org-chart-forge .node-actions {
    opacity: 1 !important;
  }

  html.mvp-tool-org-chart-forge .node-actions button,
  html.mvp-tool-org-chart-forge .org-actions button,
  html.mvp-tool-org-chart-forge .zoom-controls button {
    min-width: 32px !important;
    min-height: 32px !important;
  }

  html.mvp-tool-mind-map #app,
  html.mvp-tool-mind-map #main,
  html.mvp-tool-mind-map #canvas-wrapper {
    width: 100vw !important;
    max-width: 100vw !important;
    min-width: 0 !important;
  }

  html.mvp-tool-mind-map #sidebar {
    position: fixed !important;
    inset: calc(var(--mvp-toolbar-h) + env(safe-area-inset-top)) auto 0 0 !important;
    width: min(84vw, 280px) !important;
    min-width: 0 !important;
    max-width: 84vw !important;
    height: auto !important;
    z-index: 1000 !important;
    box-shadow: 16px 0 38px rgba(0, 0, 0, 0.32);
  }

  html.mvp-tool-mind-map #sidebar.collapsed {
    margin-left: 0 !important;
    transform: translateX(-100%) !important;
  }

  html.mvp-tool-mind-map #sidebar:not(.collapsed) {
    transform: translateX(0) !important;
  }

  html.mvp-tool-mind-map #sidebar-toggle {
    left: 0 !important;
    z-index: 1001 !important;
  }

  html.mvp-tool-mind-map #detail-panel {
    width: min(92vw, 320px) !important;
  }
}

@media print {
  html.mvp-tool-page body {
    padding-top: 0;
  }

  .mvp-toolbar {
    display: none;
  }
}
