/* Wieczorne słuchanie: granat nocy, papier, światło lampki. Postęp książki pokazuje zakładka-wstążka na okładce. */
:root {
  --night: #101c26;
  --surface: #1a2a37;
  --raised: #25394a;
  --paper: #efe7d6;
  --dim: #8fa0aa;
  --lamp: #f0b24a;
  --moon: #a9cbd6;
  --danger: #e2796b;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--night); color: var(--paper); font: 16px/1.45 var(--sans);
  -webkit-text-size-adjust: 100%; touch-action: manipulation; overscroll-behavior-y: none;
  -webkit-user-select: none; user-select: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--lamp); outline-offset: 3px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; letter-spacing: 0.01em; }
svg { width: 26px; height: 26px; fill: currentColor; display: block; }

.view { min-height: 100%; padding: calc(var(--top) + 14px) 18px calc(var(--bottom) + 110px); max-width: 900px; margin: 0 auto; }

/* wejście */
.login { max-width: 320px; margin: 14vh auto 0; display: flex; flex-direction: column; gap: 10px; }
.login img { border-radius: 20px; }
.login h1 { font-size: 34px; margin: 8px 0 18px; }
.login label { color: var(--dim); font-size: 14px; }
.login input {
  font: inherit; font-size: 18px; color: var(--paper); background: var(--surface); border: 1px solid var(--raised);
  border-radius: 10px; padding: 13px 14px; -webkit-user-select: text; user-select: text;
}
.error { color: var(--danger); min-height: 1.4em; margin: 0; font-size: 14px; }
.primary { background: var(--lamp); color: #1c1405; font-weight: 600; border-radius: 10px; padding: 13px; font-size: 17px; }

/* półka */
.top { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; }
.top h1 { font-size: 30px; flex: 1; }
.chip { border: 1px solid var(--raised); border-radius: 999px; padding: 8px 14px; font-size: 14px; color: var(--paper); white-space: nowrap; }
.chip.accent { background: var(--lamp); border-color: var(--lamp); color: #1c1405; font-weight: 600; }
.upload { background: var(--surface); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; font-size: 14px; }
.bar { height: 4px; background: var(--raised); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--lamp); transition: width .2s; }
.bar.busy i { width: 35%; animation: slide 1.2s ease-in-out infinite alternate; }
@keyframes slide { from { transform: translateX(-20%); } to { transform: translateX(210%); } }
.empty { color: var(--dim); max-width: 34em; }

.now { display: flex; gap: 16px; align-items: stretch; width: 100%; text-align: left; background: var(--surface); border-radius: 16px; padding: 14px; margin-bottom: 26px; }
.now .cover { width: 38%; max-width: 170px; flex: none; }
.now-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.now-text small { color: var(--lamp); font-size: 13px; }
.now-text b { font: 600 21px/1.2 var(--serif); margin: 4px 0 2px; }
.now-text span { color: var(--dim); font-size: 14px; }
.now-text .where { color: var(--paper); margin-top: auto; padding-top: 10px; font-size: 14px; }
.now-text .resume { align-self: flex-start; margin-top: 10px; background: var(--lamp); color: #1c1405; font-weight: 600; border-radius: 999px; padding: 9px 18px 9px 14px; display: flex; gap: 6px; align-items: center; }
.now-text .resume span { color: inherit; font-size: 15px; }
.resume svg { width: 18px; height: 18px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 22px 16px; }
.book { text-align: left; display: flex; flex-direction: column; min-width: 0; }
.book b { font: 600 15px/1.25 var(--serif); margin-top: 9px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book span { color: var(--dim); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cover { position: relative; aspect-ratio: 1; border-radius: 6px 10px 10px 6px; background: var(--raised); box-shadow: -3px 0 0 #0a141c, 0 10px 22px #060d13aa; }
.cover img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }
.cover-blank { position: absolute; inset: 0; border-radius: inherit; padding: 12% 10%; display: flex; align-items: flex-end;
  background: linear-gradient(160deg, hsl(var(--hue) 34% 30%), hsl(var(--hue) 40% 16%)); font: 600 15px/1.2 var(--serif); overflow: hidden; }
/* zakładka: im dalej w książce, tym dłuższa wstążka */
.ribbon { position: absolute; top: -4px; right: 12%; width: 13%; max-width: 26px; height: calc(12% + 80% * var(--p)); background: var(--lamp);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% calc(100% - 9px), 0 100%); box-shadow: 0 2px 6px #0008; }
.ribbon.done { background: var(--moon); }

/* pasek „teraz gra” na półce */
.mini { position: fixed; left: 10px; right: 10px; bottom: calc(var(--bottom) + 10px); max-width: 880px; margin: 0 auto; display: flex; align-items: center; gap: 12px;
  background: var(--raised); border-radius: 14px; padding: 8px 10px; text-align: left; box-shadow: 0 10px 30px #050b10cc; }
.mini .cover { width: 46px; flex: none; box-shadow: none; border-radius: 6px; }
.mini-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mini-text b, .mini-text small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-text b { font: 600 15px var(--serif); }
.mini-text small { color: var(--dim); font-size: 13px; }
.mini-play { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: var(--lamp); color: #1c1405; flex: none; }

/* odtwarzacz */
.player { position: fixed; inset: 0; background: linear-gradient(180deg, #16293a, var(--night) 55%); display: flex; flex-direction: column;
  padding: calc(var(--top) + 6px) 22px calc(var(--bottom) + 14px); overflow-y: auto; }
.player-top { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: var(--paper); }
.icon:active, .tool:active, .play:active { transform: scale(.94); }
.timer-note { color: var(--moon); font-size: 14px; font-variant-numeric: tabular-nums; }
.player-body { flex: 1; display: flex; flex-direction: column; justify-content: space-evenly; gap: 14px; max-width: 460px; width: 100%; margin: 0 auto; }
.player-cover { width: min(100%, 44vh); margin: 0 auto; }
.player-cover .cover-blank { font-size: 24px; }
.player-info { text-align: center; }
.player-info h2 { font-size: 23px; line-height: 1.2; }
.player-info > p { margin: 3px 0 0; color: var(--dim); font-size: 15px; }
.chapter-button { margin-top: 12px; color: var(--lamp); font-size: 15px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 4px 0; }
.scrub { -webkit-appearance: none; appearance: none; width: 100%; height: 30px; background: transparent; margin: 4px 0 0; --v: 0%; }
.scrub::-webkit-slider-runnable-track { height: 5px; border-radius: 3px; background: linear-gradient(90deg, var(--lamp) var(--v), var(--raised) var(--v)); }
.scrub::-moz-range-track { height: 5px; border-radius: 3px; background: linear-gradient(90deg, var(--lamp) var(--v), var(--raised) var(--v)); }
.scrub::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--paper); margin-top: -6.5px; box-shadow: 0 1px 4px #0009; }
.scrub::-moz-range-thumb { width: 18px; height: 18px; border: 0; border-radius: 50%; background: var(--paper); }
.times { display: flex; justify-content: space-between; gap: 8px; color: var(--dim); font-size: 13px; font-variant-numeric: tabular-nums; }
.controls { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 12px; }
.play { width: 76px; height: 76px; border-radius: 50%; background: var(--lamp); color: #1c1405; display: grid; place-items: center; }
.play svg { width: 34px; height: 34px; }
.skip { position: relative; width: 52px; height: 52px; }
.skip svg { width: 40px; height: 40px; }
.skip::after { content: attr(data-n); position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; font-weight: 700; padding-top: 3px; }
.tools { display: flex; gap: 8px; }
.tool { flex: 1; background: var(--surface); border-radius: 12px; padding: 11px 6px; font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tool.on { color: var(--moon); box-shadow: inset 0 0 0 1px var(--moon); }
.awake { margin-top: 12px; width: 100%; background: var(--moon); color: #0c1a22; font-weight: 600; border-radius: 12px; padding: 13px; }

/* wysuwane panele */
.sheet { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.sheet-back { position: absolute; inset: 0; background: #060c11b3; }
.sheet-panel { position: relative; width: 100%; max-width: 560px; max-height: 78vh; overflow-y: auto; background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(var(--bottom) + 16px); animation: rise .18s ease-out; -webkit-overflow-scrolling: touch; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.sheet-panel h3 { font-size: 19px; margin: 0 4px 10px; }
.row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 13px 10px; border-radius: 10px; font-size: 16px; }
.row + .row { border-top: 1px solid #ffffff0d; }
.row.on { color: var(--lamp); }
.row.danger { color: var(--danger); }
.row small { margin-left: auto; color: var(--dim); font-size: 13px; font-variant-numeric: tabular-nums; flex: none; }
.row span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sheet-form { display: flex; gap: 8px; margin-top: 12px; }
.sheet-form input { flex: 1; min-width: 0; font: inherit; color: var(--paper); background: var(--night); border: 1px solid var(--raised); border-radius: 10px; padding: 11px 12px; -webkit-user-select: text; user-select: text; }
.sheet-form button { background: var(--lamp); color: #1c1405; font-weight: 600; border-radius: 10px; padding: 0 16px; }
.note { color: var(--dim); font-size: 13px; margin: 10px 4px 0; }

.toast { position: fixed; left: 50%; bottom: calc(var(--bottom) + 90px); transform: translateX(-50%); z-index: 20; background: var(--paper); color: #17232c;
  padding: 10px 16px; border-radius: 999px; font-size: 14px; max-width: 88vw; text-align: center; box-shadow: 0 8px 24px #000a; }

@media (min-width: 700px) and (orientation: landscape) {
  .player-body { flex-direction: row; max-width: 860px; align-items: center; gap: 40px; }
  .player-cover { width: 42%; margin: 0; }
  .player-info { flex: 1; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
