:root {
  color-scheme: light;
  --paper: #fffdf9;
  --cream: #f8f0ea;
  --ink: #2f2b29;
  --muted: #6b625d;
  --line: #dfd3ca;
  --forest: #32675d;
  --forest-dark: #214940;
  --forest-soft: #e4f0ec;
  --orange: #a94f0f;
}

* { box-sizing: border-box; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font: 17px/1.6 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button { font: inherit; }
a { color: var(--forest-dark); text-underline-offset: 4px; }
a:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 4px;
}
[hidden] { display: none !important; }
.shell { width: min(calc(100% - 40px), 1180px); margin-inline: auto; }
.skip-link {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 2;
  transform: translateY(-160%);
  padding: 12px 18px;
  color: white;
  background: var(--forest-dark);
  border-radius: 8px;
}
.skip-link:focus { transform: none; }

.app-header { border-bottom: 1px solid var(--line); }
.app-header > .shell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 24px;
  padding-block: 12px;
}
.brand { display: block; width: 164px; height: auto; }
.app-nav { display: flex; align-items: center; flex-wrap: wrap; gap: 0 20px; }
.app-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--ink);
  font-size: 0.91rem;
  font-weight: 700;
  text-decoration: none;
}
.app-nav a:hover, .app-nav [aria-current] { color: var(--forest-dark); text-decoration: underline; }
.app-nav .nav-account {
  padding-inline: 14px;
  color: white;
  background: var(--orange);
  border-radius: 10px;
}

main.shell { flex: 1; padding-block: 32px 48px; }
.page-heading {
  padding: clamp(22px, 5vw, 50px);
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 22px;
}
h1, h2, h3 { margin: 0; line-height: 1.2; overflow-wrap: anywhere; text-wrap: balance; }
h1 { font-size: clamp(2rem, 5vw, 3.5rem); letter-spacing: -0.045em; }
h2 { font-size: clamp(1.3rem, 3vw, 1.65rem); }
h3 { font-size: 1.35rem; }
p { margin: 12px 0; overflow-wrap: anywhere; }
.page-heading > p { max-width: 42rem; }
.eyebrow {
  margin-top: 0;
  color: var(--forest-dark);
  font-size: 0.83rem;
  font-weight: 750;
  letter-spacing: 0.035em;
}
.connection-status {
  display: inline-block;
  margin: 6px 0 0;
  padding: 6px 12px;
  border-radius: 12px;
  color: var(--forest-dark);
  background: var(--forest-soft);
  font-size: 0.89rem;
  font-weight: 650;
}
#setup-status:empty { display: none; }

.library-panel, .device-tools { margin-block-start: 32px; }
.library-panel {
  padding: clamp(18px, 3.5vw, 34px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: white;
}
#library-status { color: var(--muted); }
.library-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.library-grid:not(:empty) { margin-block-start: 20px; }
.package-card {
  min-width: 0;
  padding: clamp(16px, 3vw, 24px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.package-state { font-size: 0.95rem; color: var(--muted); }
.package-state.ready { color: var(--forest-dark); font-weight: 750; }
.small { font-size: 0.88rem; color: var(--muted); }
.library-actions, .card-actions, .dialog-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-block-start: 16px;
}
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  max-width: 100%;
  padding: 10px 16px;
  border: 2px solid var(--forest-dark);
  border-radius: 10px;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  background: var(--forest-dark);
  color: white;
}
.button:hover { background: var(--forest); }
.button.secondary { background: var(--paper); color: var(--forest-dark); }
.button.secondary:hover { background: var(--forest-soft); }
button:disabled { opacity: 0.65; cursor: wait; }
.text-button {
  min-height: 44px;
  max-width: 100%;
  padding: 8px 4px;
  border: 0;
  color: var(--forest-dark);
  background: transparent;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
  text-align: left;
  font-size: 0.94rem;
}

.device-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 12px; margin-top: 14px; }
.install-help { border: 1px solid var(--line); border-radius: 12px; background: white; }
.install-help summary { min-height: 48px; padding: 12px 16px; cursor: pointer; font-weight: 650; }
.install-help > div { padding: 0 16px 12px; }
.device-note { max-width: 62ch; margin-top: 16px; }
.notice { padding: 16px; background: var(--cream); border: 1px solid var(--line); border-radius: 10px; }
.app-footer { background: var(--forest-dark); color: white; padding-block: 16px 22px; }
.app-footer nav { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 20px; }
.app-footer a { color: inherit; display: inline-flex; align-items: center; min-height: 44px; font-size: 0.87rem; }
.app-footer a:focus-visible { outline-color: #ffbd81; }
.app-footer p { font-size: 0.89rem; }

dialog {
  width: min(calc(100% - 32px), 540px);
  max-height: calc(100dvh - 40px);
  overflow: auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  color: var(--ink);
}
dialog::backdrop { background: rgb(20 30 25 / 60%); }

@media (max-width: 700px) {
  body { font-size: 16px; }
  .shell { width: calc(100% - 32px); }
  .app-nav { gap: 0 14px; }
  .app-nav a { font-size: 0.84rem; }
  .library-grid, .device-grid { grid-template-columns: 1fr; }
  main.shell { padding-top: 20px; }
}
@media (max-width: 420px) {
  .card-actions, .dialog-actions { align-items: stretch; flex-direction: column; }
}
