:root {
  --milk: #f6f0e5;
  --paper: #fffdf8;
  --ink: #292e2a;
  --muted: #676c66;
  --olive: #687353;
  --olive-dark: #566044;
  --olive-soft: #dfe3d5;
  --terra: #b66e52;
  --line: #d8d4ca;
  --danger: #9e493c;
  --max: 1040px;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: linear-gradient(180deg, var(--milk) 0, var(--milk) 390px, var(--paper) 390px);
  font: 16px/1.55 Arial, "DejaVu Sans", sans-serif;
}

button,
input,
a { font: inherit; }

button { cursor: pointer; }

button:disabled {
  cursor: wait;
  opacity: .58;
}

a { color: inherit; }

h1,
h2,
h3,
p { margin-top: 0; }

h1 {
  max-width: 780px;
  margin-bottom: 22px;
  font-size: clamp(2.65rem, 6vw, 5rem);
  line-height: .98;
  letter-spacing: -.052em;
}

h2 {
  margin-bottom: 14px;
  font-size: clamp(1.8rem, 3.5vw, 2.8rem);
  line-height: 1.05;
  letter-spacing: -.035em;
}

h3 {
  margin-bottom: 8px;
  line-height: 1.2;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 30;
  padding: 10px 14px;
  background: var(--ink);
  color: #fff;
  transform: translateY(-160%);
}

.skip-link:focus { transform: none; }

.cabinet-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(24px, calc((100vw - var(--max)) / 2));
  border-bottom: 1px solid rgba(41, 46, 42, .14);
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--ink);
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-decoration: none;
}

.brand span {
  width: 30px;
  height: 5px;
  background: var(--terra);
}

.home-link,
.cabinet-footer a,
.field-hint a {
  text-underline-offset: 4px;
}

.home-link:hover,
.cabinet-footer a:hover,
.field-hint a:hover { color: var(--olive); }

.cabinet-main {
  width: min(100%, calc(var(--max) + 48px));
  min-height: calc(100vh - 226px);
  margin: 0 auto;
  padding: 72px 24px 110px;
}

.intro { max-width: 800px; }

.intro > p:last-child {
  max-width: 650px;
  color: var(--muted);
  font-size: 1.12rem;
}

.eyebrow {
  margin-bottom: 17px;
  color: var(--olive);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.muted { color: var(--muted); }

.panel {
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr);
  gap: 32px;
  margin-top: 48px;
  padding: 40px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 22px 60px rgba(48, 44, 35, .07);
}

.panel[hidden],
[hidden] { display: none !important; }

.panel-number {
  display: grid;
  width: 72px;
  height: 72px;
  place-items: center;
  background: var(--olive-soft);
  color: var(--olive);
  font-size: 1.6rem;
}

.panel-number--terra {
  background: #f2dfd7;
  color: var(--terra);
  font-size: 2.4rem;
}

.panel-content { max-width: 720px; }

form { margin-top: 28px; }

label {
  display: block;
  margin-bottom: 8px;
  font-size: .88rem;
  font-weight: 700;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

input {
  width: 100%;
  min-height: 56px;
  padding: 13px 15px;
  border: 1px solid #aaa99f;
  border-radius: 3px;
  background: var(--paper);
  color: var(--ink);
  outline: none;
}

input:focus {
  border-color: var(--olive);
  box-shadow: 0 0 0 3px rgba(104, 115, 83, .18);
}

input[aria-invalid="true"] { border-color: var(--danger); }

.code-input {
  max-width: 240px;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: .3em;
  text-align: center;
}

.field-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: .8rem;
}

.button {
  min-height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 15px 24px;
  border: 0;
  border-radius: 3px;
  background: var(--olive);
  box-shadow: 0 8px 20px rgba(64, 70, 53, .12);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
}

.button:hover:not(:disabled) { background: var(--olive-dark); }

.button:focus-visible,
.text-button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(182, 110, 82, .52);
  outline-offset: 3px;
}

.secondary-actions,
.panel-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 15px 24px;
  margin-top: 24px;
}

.text-button {
  padding: 3px 0;
  border: 0;
  border-bottom: 1px solid currentColor;
  background: transparent;
  color: var(--olive);
  text-align: left;
}

.text-button:hover:not(:disabled) { color: var(--olive-dark); }

.loading-mark {
  width: 52px;
  height: 52px;
  border: 5px solid var(--olive-soft);
  border-top-color: var(--olive);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

#loading-view,
.materials-loading {
  grid-template-columns: 60px 1fr;
  align-items: center;
}

#loading-view h2,
.materials-loading h2 { margin-bottom: 4px; }

#loading-view p,
.materials-loading p { margin-bottom: 0; }

.account-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-top: 48px;
  padding: 20px 24px;
  border-left: 4px solid var(--terra);
  background: var(--ink);
  color: #fff;
}

.account-bar > div {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.account-bar strong {
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-bar .text-button { color: #dce1d2; }

.account-label {
  color: #bfc4bf;
  font-size: .76rem;
}

.materials-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin: 64px 0 28px;
}

.materials-heading h2,
.materials-heading .eyebrow { margin-bottom: 0; }

.materials-heading .eyebrow { margin-bottom: 12px; }

.material-group {
  margin-top: 38px;
}

.material-group__heading {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 14px;
}

.material-group__heading h3 {
  margin: 0;
  font-size: 1.2rem;
}

.material-group__heading::after {
  height: 1px;
  flex: 1;
  background: var(--line);
  content: "";
}

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

.material-card {
  position: relative;
  min-height: 172px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 24px;
  border: 1px solid var(--line);
  background: #fff;
}

.material-card--interactive {
  cursor: pointer;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.material-card--interactive:hover {
  border-color: var(--olive);
  box-shadow: 0 12px 28px rgba(53, 59, 45, .1);
  transform: translateY(-2px);
}

.material-card__open {
  position: absolute;
  z-index: 1;
  inset: 0;
}

.material-card__open:focus-visible {
  outline: 3px solid var(--olive);
  outline-offset: -4px;
}

.material-card--bundle {
  border-color: var(--olive);
  background: var(--olive-soft);
}

.material-card__meta {
  margin-bottom: 14px;
  color: var(--terra);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.material-card p {
  margin-bottom: 22px;
  color: var(--muted);
  font-size: .9rem;
}

.download-link {
  position: relative;
  z-index: 2;
  margin-top: auto;
  color: var(--olive-dark);
  font-weight: 700;
  text-underline-offset: 4px;
}

.empty-state {
  padding: 35px;
  border: 1px dashed #aaa99f;
  background: var(--milk);
  text-align: center;
}

.empty-state p { margin-bottom: 0; }

.notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-top: 28px;
  padding: 22px 24px;
  border-left: 4px solid var(--danger);
  background: #f8e9e4;
}

.notice p { margin: 4px 0 0; }

.notice .text-button {
  flex: 0 0 auto;
  color: var(--danger);
}

.cabinet-footer {
  min-height: 150px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 35px;
  max-width: var(--max);
  margin: auto;
  padding: 34px 24px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .78rem;
}

.cabinet-footer > div {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.cabinet-footer nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 18px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 700px) {
  body { background-position-y: -60px; }

  .cabinet-header { min-height: 62px; }

  .cabinet-main { padding-top: 50px; padding-bottom: 75px; }

  .panel {
    grid-template-columns: 1fr;
    gap: 20px;
    padding: 26px;
  }

  .panel-number {
    width: 52px;
    height: 52px;
    font-size: 1.2rem;
  }

  .field-row,
  .material-grid { grid-template-columns: 1fr; }

  .field-row .button { width: 100%; }

  .code-input { max-width: none; }

  .account-bar,
  .materials-heading,
  .notice,
  .cabinet-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .materials-heading { margin-top: 48px; }

  .cabinet-footer nav { justify-content: flex-start; }
}

@media (max-width: 440px) {
  h1 { font-size: 2.7rem; }
  .home-link { font-size: .85rem; }
  .brand { letter-spacing: .08em; }
  .brand span { width: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .loading-mark { animation-duration: 1.8s; }
}
