/* Paper sheets: the tape box, the cassette label form, and the storage notes.
   Plain and readable on purpose; the player is the showpiece, not these. */

.sheet {
  /* Keep clear of the notch, the Dynamic Island and the home indicator: the
     page draws under the status bar (viewport-fit=cover, black-translucent). */
  --safe-top: max(12px, calc(env(safe-area-inset-top) + 8px));
  --safe-bottom: max(12px, calc(env(safe-area-inset-bottom) + 8px));
  width: min(520px, calc(100vw - 20px));
  max-height: calc(100vh - var(--safe-top) - var(--safe-bottom));
  max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
  margin: auto;
  /* No top padding: the header carries it, so it can stick to the very top. */
  padding: 0 20px 22px;
  border: 0;
  border-radius: 14px;
  color: #2a1f16;
  background:
    url('../assets/wear-stain.svg') 0 0 / 420px auto,
    var(--paper);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.7);
  font-family: var(--font-read);
  font-size: 17px;
  line-height: 1.45;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet::backdrop {
  background: rgba(15, 8, 4, 0.72);
}

/* Phones: anchor the sheet just below the status bar instead of centring it,
   so its header (and the way out) is always in the same reachable place. */
@media (max-width: 600px) {
  .sheet {
    margin: var(--safe-top) auto auto;
  }
}

/* The header stays put while a long form scrolls beneath it, so Cancel and
   the × are never more than one tap away. */
.sheet__head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 -20px 6px;
  padding: 14px 20px 8px;
  background: var(--paper);
  border-bottom: 1px solid rgba(23, 36, 60, 0.14);
}

.sheet__head--form {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
}

.sheet__head--form h2 {
  text-align: center;
  font-size: 22px;
}

.sheet__cancel {
  min-width: 44px;
  min-height: 44px;
  margin: -6px 0 -6px -8px;
  padding: 0 8px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 17px;
  font-weight: 600;
}

.sheet__cancel:hover {
  background: rgba(23, 36, 60, 0.08);
}

.sheet h2 {
  margin: 0;
  font-family: var(--font-slab);
  font-size: 24px;
  line-height: 1.15;
  color: var(--ink);
  text-wrap: balance;
}

.sheet h3 {
  margin: 22px 0 6px;
  font-family: var(--font-label);
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.sheet__close {
  flex: none;
  width: 44px;
  height: 44px;
  margin: -6px -8px -6px 0;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
}

.sheet__close:hover {
  background: rgba(23, 36, 60, 0.08);
}

.sheet__lede {
  margin: 0 0 14px;
  color: #4b3c2e;
}

.sheet__note {
  margin: 14px 0 0;
  font-size: 15px;
  color: #55463a;
  text-wrap: pretty;
}

.sheet__status {
  margin: 10px 0 0;
  min-height: 1.45em;
  font-size: 15px;
  color: var(--ink-soft);
}

.sheet__status:empty {
  display: none;
}

.sheet__error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-left: 5px solid #a23b23;
  border-radius: 6px;
  background: rgba(162, 59, 35, 0.1);
  color: #5c1d0f;
  font-size: 16px;
  text-wrap: pretty;
}

.sheet__error::before {
  content: 'Not saved. ';
  font-weight: 700;
}

.sheet__error[data-plain]::before {
  content: none;
}

.sheet__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.sheet__actions--start {
  justify-content: flex-start;
}

.btn {
  min-height: 46px;
  padding: 0 18px;
  border-radius: 10px;
  border: 2px solid var(--ink-soft);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 16px;
  font-weight: 600;
}

.btn--primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fbf4e2;
}

.btn--plain {
  border-color: transparent;
  padding: 0 4px;
  text-decoration: underline;
  text-underline-offset: 3px;
  color: #6b2a18;
}

.btn--danger {
  background: #8f2f1a;
  border-color: #8f2f1a;
  color: #fff6ea;
}

.btn:disabled {
  opacity: 0.55;
  cursor: progress;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.12);
}

.sheet :focus-visible {
  outline: 3px solid #1c5fb8;
  outline-offset: 2px;
}

/* ---- the tape box -------------------------------------------------------------- */

.tapes {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.tapes:empty {
  display: none;
}

.tape {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: stretch;
  border-radius: 10px;
  border: 2px solid rgba(23, 36, 60, 0.35);
  background: rgba(255, 255, 255, 0.45);
  overflow: hidden;
}

.tape[data-current] {
  border-color: var(--ink);
  box-shadow: inset 5px 0 0 var(--ink);
}

.tape__load {
  min-height: 64px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 10px 12px 10px 16px;
  border: 0;
  background: none;
  text-align: left;
  color: inherit;
  min-width: 0;
}

.tape__load:hover {
  background: rgba(23, 36, 60, 0.06);
}

.tape__title {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 21px;
  line-height: 1.2;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.tape__meta {
  font-family: var(--font-text);
  font-size: 14px;
  color: #55463a;
  overflow-wrap: anywhere;
}

.tape__edit {
  min-width: 64px;
  padding: 0 14px;
  border: 0;
  border-left: 2px solid rgba(23, 36, 60, 0.2);
  background: none;
  font-family: var(--font-text);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.tape__edit:hover {
  background: rgba(23, 36, 60, 0.06);
}

/* ---- the cassette form --------------------------------------------------------- */

.field {
  display: grid;
  gap: 4px;
  margin-top: 12px;
}

.field__name,
.side legend,
.file__name {
  font-family: var(--font-text);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.field__name em,
.side legend em {
  font-style: normal;
  font-weight: 400;
  color: #5d4e41;
}

.field input,
.field textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 2px solid rgba(23, 36, 60, 0.45);
  border-radius: 8px;
  background: #fffaf0;
  color: #1d1610;
  font-family: var(--font-text);
  font-size: 17px; /* 16px+ keeps iOS from zooming the page on focus */
}

.field textarea {
  resize: vertical;
}

.field input[aria-invalid='true'] {
  border-color: #a23b23;
}

.side {
  margin: 16px 0 0;
  padding: 10px 14px 14px;
  border: 2px solid rgba(23, 36, 60, 0.3);
  border-radius: 10px;
  min-width: 0;
  scroll-margin-top: 84px; /* land below the sticky header */
}

.field--side {
  margin-top: 4px;
}

.field--side + .field--side {
  margin-top: 10px;
}

.side__hint {
  margin: 6px 0 12px;
  font-family: var(--font-text);
  font-size: 14px;
  color: #5d4e41;
}

.side legend {
  padding: 0 6px;
  font-family: var(--font-slab);
  font-size: 18px;
}

.side__current {
  margin: 0 0 8px;
  font-family: var(--font-text);
  font-size: 15px;
  color: #4b3c2e;
  overflow-wrap: anywhere;
}

.file {
  display: grid;
  gap: 6px;
}

.file input[type='file'] {
  width: 100%;
  min-height: 46px;
  font-family: var(--font-text);
  font-size: 15px;
  color: #2a1f16;
}

.file input[type='file']::file-selector-button {
  min-height: 42px;
  margin-right: 12px;
  padding: 0 14px;
  border-radius: 8px;
  border: 2px solid var(--ink-soft);
  background: #fffaf0;
  color: var(--ink);
  font: 600 15px var(--font-text);
  cursor: pointer;
}

.danger {
  margin-top: 22px;
  padding-top: 12px;
  border-top: 1px dashed rgba(23, 36, 60, 0.35);
}

.danger__confirm {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.danger__confirm p {
  flex-basis: 100%;
  margin: 0 0 4px;
  font-size: 16px;
}

/* ---- storage notes -------------------------------------------------------------- */

.plain {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 8px;
}

.plain li {
  text-wrap: pretty;
}

.keysheet {
  margin: 0;
  display: grid;
  gap: 6px;
  font-family: var(--font-text);
  font-size: 16px;
}

.keysheet div {
  display: grid;
  grid-template-columns: 96px 1fr;
  align-items: baseline;
}

.keysheet dt {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--ink);
}

.keysheet dd {
  margin: 0;
}
