/* 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(--tb-body);
  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(--tb-body);
  font-size: 17px;
  font-weight: 600;
}

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

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

.sheet h3 {
  margin: 22px 0 6px;
  font-family: var(--tb-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(--tb-body);
  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(--tb-hand);
  font-weight: 700;
  font-size: 21px;
  line-height: 1.2;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.tape__meta {
  font-family: var(--tb-body);
  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(--tb-body);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

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

/* Shared libraries: each one a named section above the device's own tapes. */

.libs {
  display: grid;
  gap: 4px;
}

.libs:empty {
  display: none;
}

.lib__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.sheet .lib__name {
  flex: 1;
  min-width: 0;
  margin: 14px 0 8px;
  overflow-wrap: anywhere;
}

.lib__remove {
  flex: none;
  min-height: 44px;
  font-size: 15px;
}

/* A curator's own collection: Add a tape, then Share or change. */
.lib__keys {
  flex: none;
  display: flex;
  gap: 4px;
}

.lib__add {
  min-height: 44px;
  font-size: 15px;
  font-weight: 700;
}

/* On a phone the two keys go under the collection's name, so a long name still reads. */
@media (max-width: 480px) {
  .lib[data-mine] .lib__head {
    flex-wrap: wrap;
    gap: 0 12px;
  }

  .lib[data-mine] .lib__name {
    flex-basis: 100%;
    margin-bottom: 0;
  }
}

#collectionAddTitle:focus {
  outline: none;
}

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

.lib[data-status='gone'] .lib__note,
.lib[data-status='bad'] .lib__note {
  padding: 10px 12px;
  border-left: 5px solid #a23b23;
  border-radius: 6px;
  background: rgba(162, 59, 35, 0.1);
  color: #5c1d0f;
}

.lib__confirm {
  margin: 0 0 12px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(162, 59, 35, 0.08);
}

.lib__confirm p {
  margin: 0 0 10px;
  font-size: 15px;
  text-wrap: pretty;
}

.lib__confirm .btn {
  margin: 0 8px 6px 0;
}

/* A shared tape: no Label key (it is read-only), a cover, and a keep switch. */

.tape--shared {
  grid-template-columns: 1fr;
}

.tape--shared .tape__load {
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 12px;
}

.tape--shared[data-no-cover] .tape__load {
  grid-template-columns: 1fr;
}

.tape__cover {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  object-fit: cover;
  background: rgba(23, 36, 60, 0.12);
  box-shadow: 0 0 0 1px rgba(23, 36, 60, 0.25);
}

.tape__text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.tape__keep {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 6px 12px 6px 16px;
  border: 0;
  border-top: 2px solid rgba(23, 36, 60, 0.2);
  background: none;
  text-align: left;
  font-family: var(--tb-body);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.tape__keep:hover:not([data-busy]) {
  background: rgba(23, 36, 60, 0.06);
}

.tape__keep[data-busy] {
  cursor: progress;
}

/* The switch itself: a small slide, off to the left and on to the right. */
.tape__keep-switch {
  flex: none;
  position: relative;
  width: 40px;
  height: 24px;
  border-radius: 12px;
  border: 2px solid var(--ink-soft);
  background: rgba(23, 36, 60, 0.08);
}

.tape__keep-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--ink-soft);
  transition: transform 0.15s ease;
}

.tape__keep[aria-checked='true'] .tape__keep-switch {
  border-color: var(--ink);
  background: var(--ink);
}

.tape__keep[aria-checked='true'] .tape__keep-switch::after {
  background: #fbf4e2;
  transform: translateX(16px);
}

.tape__keep[data-busy] .tape__keep-switch::after {
  animation: keep-busy 0.9s ease-in-out infinite alternate;
}

@keyframes keep-busy {
  to {
    transform: translateX(16px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tape__keep-switch::after {
    transition: none;
  }

  .tape__keep[data-busy] .tape__keep-switch::after {
    animation: none;
    transform: translateX(8px);
  }
}

.tape__keep-note {
  margin: 0;
  padding: 0 12px 10px 16px;
  font-family: var(--tb-body);
  font-size: 14px;
  color: #5c1d0f;
  text-wrap: pretty;
}

.tape__keep-note:empty {
  display: none;
}

.code-form {
  margin-top: 18px;
  padding-top: 4px;
  border-top: 1px solid rgba(23, 36, 60, 0.14);
}

.code-form input {
  letter-spacing: 0.06em;
}

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

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

.field__name,
.side legend,
.file__name {
  font-family: var(--tb-body);
  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(--tb-body);
  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(--tb-body);
  font-size: 14px;
  color: #5d4e41;
}

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

.side__current {
  margin: 0 0 8px;
  font-family: var(--tb-body);
  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(--tb-body);
  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(--tb-body);
  cursor: pointer;
}

/* "Add a track": the whole dashed box is the press target. The file input
   covers it, unseen, so a press anywhere opens the picker and the keyboard
   still reaches it. */
.file--add {
  position: relative;
  min-height: 48px;
  margin: 4px 0 12px;
  place-items: center;
  border: 2px dashed var(--ink-soft);
  border-radius: 10px;
  background: #fffaf0;
  cursor: pointer;
}

.file--add .file__name {
  padding: 10px 14px;
  text-align: center;
}

.file--add input[type='file'] {
  position: absolute;
  inset: 0;
  min-height: 0;
  opacity: 0;
  cursor: pointer;
}

.file--add:hover {
  border-style: solid;
}

.file--add:focus-within {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

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

/* ---- collections: a curator's own shared libraries -------------------------------- */

/* A row that is not itself a key: its facts on the left, what can be done on the right. */
.tape__info {
  min-height: 64px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 10px 12px 10px 16px;
  min-width: 0;
}

.tape__actions {
  display: flex;
}

.tape__edit:disabled {
  opacity: 0.5;
  cursor: progress;
}

.tape__edit--danger {
  color: #8f2f1a;
}

.tape__why {
  grid-column: 1 / -1;
  margin: 0;
  padding: 0 14px 12px 16px;
  font-size: 14px;
  color: #5c1d0f;
  text-wrap: pretty;
}

/* Progress and problems stay at the foot of the sheet, in view while a
   recording is being sent from a row far down the list. */
.sheet__foot {
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin: 18px -20px -22px;
  padding: 10px 20px 16px;
  background: var(--paper);
  border-top: 1px solid rgba(23, 36, 60, 0.14);
}

.sheet__foot .sheet__status,
.sheet__foot .sheet__error {
  margin-top: 0;
}

.sheet__foot .sheet__status {
  color: var(--ink);
  font-weight: 600;
}

.field .field__link {
  font-family: var(--tb-body);
  font-size: 16px;
}

.manage {
  margin-top: 22px;
  border-top: 1px solid rgba(23, 36, 60, 0.14);
}

.manage summary {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--tb-body);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

.manage__part {
  padding-bottom: 16px;
}

.manage__part .btn {
  margin-top: 10px;
}

.manage__part .side__hint {
  margin-bottom: 0;
}

/* ---- 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(--tb-body);
  font-size: 16px;
}

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

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

.keysheet dd {
  margin: 0;
}

/* ---- tracks: a side made of several recordings ----------------------------------- */

.side__hint--file {
  margin: 6px 0 10px;
}

.tracklist {
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.track {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 8px;
  row-gap: 4px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid rgba(23, 36, 60, 0.28);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.6);
  min-width: 0;
}

.track__number {
  font-family: var(--tb-head);
  font-size: 16px;
  color: var(--ink);
  min-width: 1.6em;
  text-align: right;
}

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

.track__facts {
  grid-column: 2;
  font-family: var(--tb-body);
  font-size: 14px;
  color: #4b3c2e;
  overflow-wrap: anywhere;
}

.track__actions {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}

.track__act {
  min-height: 44px;
  min-width: 44px;
  padding: 0 6px;
}

.track__act:disabled {
  opacity: 0.4;
}

/* The same list, to read: what is on a shared tape. */
.track--read {
  grid-template-columns: 1fr auto;
  padding: 10px 12px;
  font-family: var(--tb-body);
  font-size: 16px;
  color: #1d1610;
}

.tracklist--read {
  counter-reset: track;
}

.tracklist--read .track__name::before {
  counter-increment: track;
  content: counter(track) '. ';
  font-family: var(--tb-head);
  color: var(--ink);
}

.track__length {
  font-variant-numeric: tabular-nums;
  color: #4b3c2e;
}

.track__here {
  grid-column: 1 / -1;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

.track--read[aria-current='true'] {
  border-color: var(--ink);
  border-width: 2px;
}
