.programmer-wrap {
  width: 100%;
  max-width: none;
  height: 100vh;
  margin: 0;
  padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right))
    max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
}

.notice {
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid #47422a;
  border-radius: var(--radius);
  background: #1c1a10;
  color: #fff4bd;
  line-height: 1.45;
}

.notice.error {
  border-color: #613031;
  background: #211313;
  color: #ffd2d2;
}

.programmer-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) minmax(150px, 0.28fr);
  gap: 6px;
  height: 100%;
  min-height: 0;
}

.toolbar,
.log-header,
.range-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar {
  justify-content: space-between;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #101412;
}

.toolbar-brand,
.toolbar-actions {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.toolbar-brand {
  color: var(--text);
  font-weight: 700;
}

.toolbar-brand .brand-mark {
  flex: 0 0 32px;
  margin-bottom: 0;
  text-decoration: none;
}

.toolbar-brand h1 {
  max-width: none;
  margin: 0;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.2;
}

.action-button {
  min-width: 112px;
  margin-top: 0;
  cursor: pointer;
  font-family: var(--font-mono);
}

.action-button.primary {
  color: #b8ffb8;
  border-color: #2b2b2b;
  background: linear-gradient(135deg, #26332a, #151a17);
  box-shadow: 0 6px 18px rgba(0, 255, 153, 0.08), inset 0 0 8px rgba(0, 0, 0, 0.5);
}

.action-button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.action-button.subtle {
  min-width: 74px;
  min-height: 34px;
  padding: 6px 10px;
}

.action-button.danger {
  color: #ffd1d1;
  border-color: #6f3838;
  background: linear-gradient(135deg, #3a1919, #170f0f);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid #2b2b2b;
  border-radius: var(--radius);
  background: #0d0d0d;
  color: var(--cyan);
  font-size: 0.86rem;
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.operation-card {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  min-height: 0;
  margin: 0;
  padding: 10px;
}

.operation-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #2b2b2b;
}

.operation-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid #2b2b2b;
  border-radius: var(--radius);
  background: #0b0d0c;
  color: #d8ddd8;
  cursor: pointer;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
}

.operation-tab.is-active {
  border-color: #00ffcc88;
  background: linear-gradient(135deg, #17252b, #101517);
  color: var(--cyan);
}

.tab-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.tab-icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.operation-panels {
  display: grid;
  min-height: 96px;
}

.operation-section {
  min-width: 0;
}

.operation-controls {
  display: grid;
  gap: 8px;
  align-items: center;
}

.range-controls {
  grid-template-columns: auto 132px auto 132px auto auto;
  justify-content: start;
}

.dump-controls {
  grid-template-columns: repeat(2, auto);
  justify-content: start;
}

.range-controls .action-button {
  width: auto;
}

.write-controls {
  grid-template-columns: minmax(300px, 420px) auto;
  justify-content: start;
}

.compact-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 10px;
  gap: 8px;
}

.compact-card .action-button {
  align-self: start;
  margin-top: 10px;
  width: auto;
}

.inline-select {
  width: min(100%, 180px);
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid #2b2b2b;
  border-radius: var(--radius);
  background: #0b0d0c;
  color: var(--text);
  font: inherit;
}

.inline-input {
  width: min(100%, 180px);
  min-height: 36px;
  margin-top: 6px;
  padding: 7px 10px;
  border: 1px solid #2b2b2b;
  border-radius: var(--radius);
  background: #0b0d0c;
  color: var(--text);
  font: inherit;
}

#spiFrequencyCustom {
  width: 9ch;
  max-width: 100%;
  text-align: right;
}

#spiFrequencyActual {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.78rem;
}

.info-list {
  display: grid;
  gap: 8px;
}

.info-list div {
  display: grid;
  grid-template-columns: minmax(120px, 0.65fr) minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
}

.info-list dt {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.info-list dd {
  min-width: 0;
  overflow-wrap: anywhere;
  color: #f2fff2;
  font-size: 0.9rem;
}

.range-row label,
.operation-controls label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.range-row input,
.operation-controls input,
.file-input {
  width: 132px;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid #2b2b2b;
  border-radius: var(--radius);
  background: #0b0d0c;
  color: var(--text);
  font: inherit;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.file-picker {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr);
  gap: 8px;
  align-items: center;
  min-width: 0;
  max-width: 420px;
}

.file-button {
  min-width: 104px;
  min-height: 40px;
}

.file-name {
  min-width: 0;
  overflow: hidden;
  color: #d8ddd8;
  font-size: 0.82rem;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-row {
  display: grid;
  grid-template-columns: minmax(120px, auto) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.84rem;
}

.progress-row progress {
  width: 100%;
  height: 16px;
  overflow: hidden;
  border: 1px solid #2b2b2b;
  border-radius: var(--radius);
  background: #080a09;
}

.progress-row progress::-webkit-progress-bar {
  background: #080a09;
}

.progress-row progress::-webkit-progress-value {
  background: linear-gradient(90deg, var(--green-dim), var(--cyan));
}

.progress-row progress::-moz-progress-bar {
  background: linear-gradient(90deg, var(--green-dim), var(--cyan));
}

.hex-preview,
.log-output {
  width: 100%;
  margin-top: 8px;
  overflow: auto;
  border: 1px solid #2b2b2b;
  border-radius: var(--radius);
  background: #080a09;
  color: #dfffe2;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre;
}

.hex-preview {
  min-height: 0;
  max-height: none;
  padding: 10px;
}

.log-output {
  min-height: 0;
  max-height: none;
  padding: 10px;
  color: #c7d4cf;
}

.log-header {
  justify-content: space-between;
}

.log-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  margin: 0;
}

@media (max-width: 760px) {
  .programmer-wrap {
    height: auto;
    min-height: 100vh;
  }

  .programmer-shell {
    grid-template-rows: none;
    height: auto;
  }

  .operation-card,
  .log-card {
    display: block;
  }

  .hex-preview {
    min-height: 260px;
  }

  .log-output {
    min-height: 220px;
  }

  .panel-grid {
    grid-template-columns: 1fr;
  }

  .operation-panels,
  .range-controls,
  .dump-controls,
  .write-controls {
    grid-template-columns: 1fr;
  }

  .toolbar,
  .range-row {
    align-items: stretch;
  }

  .toolbar-brand,
  .toolbar-actions {
    width: 100%;
  }

  .toolbar-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .action-button,
  .inline-input,
  .range-row input,
  .operation-controls input,
  .file-picker {
    width: 100%;
  }

  .compact-card .action-button {
    width: 100%;
  }

  .file-picker {
    grid-template-columns: 1fr;
  }

  .range-controls .action-button:first-of-type,
  .range-controls .action-button:last-of-type {
    grid-column: auto;
  }

  .progress-row {
    grid-template-columns: 1fr;
  }

  .info-list div {
    grid-template-columns: 1fr;
    gap: 3px;
  }
}

/* Small-screen layout: keep cards and logs in the normal page flow. */
@media (max-width: 760px) {
  html,
  body {
    height: auto;
    min-height: 100%;
  }

  body {
    overflow-y: auto;
  }

  .programmer-wrap {
    min-height: 100dvh;
    height: auto;
    overflow: visible;
  }

  .programmer-shell,
  .operation-card,
  .operation-panels,
  .log-card {
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .operation-card,
  .log-card {
    display: block;
  }

  .toolbar {
    position: relative;
  }

  .toolbar-brand {
    min-height: 32px;
    padding-right: 40px;
  }

  .toolbar > .toolbar-actions > .help-icon-button {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    width: 30px;
    height: 30px;
    margin: 0;
  }
}

/* Prevent horizontal clipping on narrow phones. */
@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  .programmer-wrap,
  .programmer-shell,
  .toolbar,
  .panel-grid,
  .tool-card,
  .content-card,
  .operation-card,
  .operation-tabs,
  .operation-panels,
  .operation-section,
  .operation-controls,
  .progress-row,
  .log-card,
  .log-header {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .programmer-shell > *,
  .panel-grid > *,
  .operation-card > *,
  .operation-panels > *,
  .operation-section > *,
  .log-card > * {
    max-width: 100%;
    min-width: 0;
  }

  .toolbar-brand,
  .toolbar-actions,
  .toolbar-brand h1,
  .status-pill {
    max-width: 100%;
    min-width: 0;
  }

  .toolbar-brand h1,
  .status-pill {
    overflow-wrap: anywhere;
  }

  .toolbar-actions > :not(.help-icon-button),
  .operation-controls > *,
  .file-picker > * {
    max-width: 100%;
    min-width: 0;
  }

  .operation-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .operation-tab {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    justify-content: center;
    padding-inline: 6px;
    overflow-wrap: anywhere;
    text-align: center;
    white-space: normal;
  }

  .operation-tab:last-child {
    grid-column: 1 / -1;
  }

  .inline-select,
  .inline-input,
  .range-row input,
  .operation-controls input,
  .action-button,
  .hex-preview,
  .log-output {
    max-width: 100%;
    min-width: 0;
  }
}

@media (max-width: 760px) {
  /* Keep the native file input visually hidden; generic mobile input sizing
     must not expand this absolutely positioned control past the card edge. */
  .file-input {
    width: 1px !important;
    max-width: 1px;
    height: 1px;
    min-width: 0;
  }
}
