.notranslate,
html,
body {
  height: 100%;
}

body {
  overflow: hidden;
}

.avr-wrap {
  width: 100%;
  max-width: none;
  height: 100dvh;
  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: 8px;
  padding: 10px 12px;
  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) auto auto;
  gap: 6px;
  height: 100%;
  min-height: 0;
}

.toolbar,
.toolbar-brand,
.toolbar-actions,
.mode-tabs,
.primary-area,
.mode-actions,
.log-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

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

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

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

.status-pill {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid #2b2b2b;
  border-radius: var(--radius);
  background: #0d0d0d;
  color: var(--cyan);
  white-space: nowrap;
}

.mode-tabs {
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #101412;
}

.mode-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 92px;
  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.82rem;
  font-weight: 700;
}

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

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

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

.mode-tab.danger-tab.is-active {
  border-color: #854040;
  background: linear-gradient(135deg, #321717, #130d0d);
  color: #ffd1d1;
}

.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);
}

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

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

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(330px, 0.42fr);
  gap: 6px;
  min-height: 0;
}

.work-panel,
.side-panel {
  min-height: 0;
}

.work-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(145deg, var(--panel-bg), var(--panel-bg-deep));
  box-shadow: inset 0 0 5px #000;
  overflow: hidden;
}

.mode-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  height: 100%;
  min-height: 0;
  padding: 10px;
  overflow: auto;
}

.side-panel {
  display: grid;
  grid-template-rows: auto minmax(180px, 1fr);
  gap: 6px;
}

.compact-card {
  display: grid;
  min-height: 0;
  padding: 10px;
}

.device-card {
  align-content: start;
  gap: 10px;
}

.output-card {
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.output-card .eyebrow {
  margin: 0;
}

.drop-zone {
  display: grid;
  gap: 5px;
  min-height: 132px;
  padding: 20px;
  place-items: center;
  box-sizing: border-box;
  border: 1px dashed #3a4a42;
  border-radius: var(--radius);
  background: #0b0d0c;
  color: #d8ddd8;
  text-align: center;
  cursor: pointer;
}

.drop-zone:hover,
.drop-zone:focus-within {
  border-color: var(--green);
  background: #0d1511;
}

.drop-zone strong {
  color: var(--green);
  font-size: 0.92rem;
}

.drop-zone span {
  max-width: 720px;
  color: var(--muted);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.memory-operation-info,
.device-status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.memory-operation-info div,
.device-status-grid div {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 10px;
  border: 1px solid #2b2b2b;
  border-radius: var(--radius);
  background: #0b0d0c;
}

.memory-operation-info span,
.device-status-grid span {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.memory-operation-info strong,
.device-status-grid strong {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--cyan);
  font-size: 0.86rem;
}

.device-status-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.operation-note,
.target-help,
.danger-message {
  align-self: end;
  padding: 12px;
  border: 1px solid #2b2b2b;
  border-radius: var(--radius);
  background: #0b0d0c;
  color: #d8ddd8;
  font-size: 0.82rem;
  line-height: 1.5;
}

.target-help,
.danger-message {
  display: grid;
  gap: 5px;
  align-self: start;
}

.target-help strong {
  color: var(--green);
}

.danger-message {
  border-color: #6f3838;
  background: #180f0f;
}

.danger-message strong {
  color: #ffd1d1;
}

.danger-message span {
  color: #dcbcbc;
}

.form-grid {
  display: grid;
  grid-template-columns: 150px minmax(180px, 420px);
  gap: 10px;
  align-content: start;
  align-items: center;
}

.form-grid label,
.info-list dt {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}

.form-grid input,
.form-grid select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid #2b2b2b;
  border-radius: var(--radius);
  background: #0b0d0c;
  color: var(--text);
  font: inherit;
}

.erase-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  height: 100%;
}

.erase-info {
  align-content: start;
  padding: 12px;
  border: 1px solid #3a2b2b;
  border-radius: var(--radius);
  background: #100c0c;
}

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

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

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

.device-info-list {
  padding-top: 2px;
}

.wiring-panel {
  align-self: start;
  padding: 10px;
  border: 1px solid #2b2b2b;
  border-radius: var(--radius);
  background: #0b0d0c;
}

.wiring-panel summary {
  cursor: pointer;
  color: var(--cyan);
  font-weight: 700;
}

.wiring-panel ul {
  display: grid;
  gap: 4px;
  margin: 10px 0;
  padding-left: 18px;
  color: #dfffe2;
}

.wiring-panel p {
  color: #d8ddd8;
  font-size: 0.84rem;
  line-height: 1.45;
}

.action-strip {
  display: grid;
  grid-template-columns: auto minmax(260px, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 58px;
  margin: 0;
  padding: 8px 10px;
}

.primary-area {
  flex-wrap: wrap;
}

.mode-actions {
  flex-wrap: wrap;
}

#operationStatus {
  color: var(--cyan);
  font-size: 0.82rem;
}

.action-hint {
  max-width: 540px;
  color: #d8ddd8;
  font-size: 0.76rem;
  line-height: 1.35;
}

.progress-stack {
  display: grid;
  gap: 6px;
  min-width: 0;
}

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

.progress-track {
  height: 14px;
  overflow: hidden;
  border: 1px solid #2b2b2b;
  border-radius: var(--radius);
  background: #080a09;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--green-dim), var(--cyan));
  transition: width 0.18s ease;
}

.log-card {
  position: relative;
  min-height: 0;
  margin: 0;
  padding: 8px 10px;
  overflow: hidden;
}

.log-card[open] {
  max-height: min(42vh, 340px);
}

.log-card summary {
  min-height: 34px;
  padding-right: 260px;
  cursor: pointer;
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 34px;
}

.log-header {
  position: absolute;
  top: 8px;
  right: 10px;
  justify-content: flex-end;
}

.log-card:not([open]) .log-header {
  display: none;
}

.log-output {
  width: 100%;
  min-height: 120px;
  max-height: 180px;
  margin-top: 8px;
  overflow: auto;
  border: 1px solid #2b2b2b;
  border-radius: var(--radius);
  background: #080a09;
  color: #c7d4cf;
  padding: 10px;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.user-output {
  min-height: 0;
  max-height: none;
  height: 100%;
  margin-top: 8px;
  color: #dfffe2;
}

[hidden] {
  display: none !important;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .avr-wrap {
    height: auto;
    min-height: 100dvh;
  }

  .programmer-shell,
  .workspace,
  .side-panel,
  .action-strip {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    height: auto;
  }

  .toolbar,
  .toolbar-actions,
  .mode-tabs,
  .primary-area {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .toolbar-brand,
  .toolbar-actions,
  .mode-tab,
  .action-button {
    width: 100%;
  }

  .memory-operation-info,
  .device-status-grid,
  .form-grid,
  .info-list div,
  .progress-row {
    grid-template-columns: 1fr;
  }

  .mode-panel {
    min-height: 430px;
  }

  .output-card {
    min-height: 300px;
  }

  .log-card summary {
    min-height: 0;
    padding-right: 0;
    line-height: normal;
  }

  .log-header {
    position: static;
    margin-top: 8px;
  }

  .log-header .action-button {
    width: auto;
  }
}

/* Small-screen layout: use a normal document flow instead of a viewport-sized app. */
@media (max-width: 760px) {
  html,
  body,
  .notranslate {
    height: auto;
    min-height: 100%;
  }

  body {
    overflow-y: auto;
  }

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

  .programmer-shell,
  .workspace,
  .work-panel,
  .side-panel,
  .mode-panel,
  .output-card,
  .action-strip {
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .mode-panel {
    grid-template-rows: auto;
  }

  .output-card {
    display: block;
  }

  .user-output {
    height: auto;
    min-height: 260px;
    max-height: 420px;
    overflow: auto;
  }

  .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;
  }
}
