/* Warm dark theme. The app is always dark; these six tones plus the peach
   accent are the whole palette. */
:root {
  --bg: #111111;        /* Dreamless Sleep: page */
  --surface: #1a1919;   /* Thamar Black: cards, tab bar */
  --raised: #2b2726;    /* Bokara Grey: icon tiles, chips, player */
  --line: #2b2726;      /* hairlines between rows */
  --edge: #47403d;      /* Wild Truffle: outlines, inactive bits */
  --dim: #77615a;       /* Raisin in the Sun: inactive icons */
  --muted: #8f7a72;     /* readable secondary text */
  --soft: #c9b8b1;      /* icons on raised tiles */
  --text: #f2ede9;
  --accent: #e07b5b;    /* Dry Peach */
  --accent-text: #111111;
  --danger: #ff7a66;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --tabbar: calc(var(--safe-bottom) + 76px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar) + 70px);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg circle { fill: currentColor; stroke: none; }

.primary { background: var(--accent); color: var(--accent-text); border: 0; font-weight: 600; }

/* Login */
.login { max-width: 340px; margin: 0 auto; padding: calc(var(--safe-top) + 14vh) 16px 0; text-align: center; }
.login-icon { width: 76px; height: 76px; border-radius: 18px; box-shadow: 0 10px 40px rgb(224 123 91 / .25); }
.login h1 { margin: 14px 0 28px; font-size: 28px; font-weight: 700; }
.login input, .login button { width: 100%; height: 50px; border-radius: 14px; font-size: 17px; }
.login input { border: 1px solid var(--edge); background: var(--surface); padding: 0 16px; margin-bottom: 12px; }
.login input:focus { outline: none; border-color: var(--accent); }
.error { color: var(--danger); min-height: 1.4em; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  padding: calc(var(--safe-top) + 6px) 16px 10px;
}
.back { display: flex; align-items: center; gap: 2px; background: none; border: 0; padding: 4px 0; margin-left: -6px; color: var(--accent); font-size: 15px; max-width: 70%; }
.back svg { width: 20px; height: 20px; flex: none; }
.back span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title-row { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.title-row h1 { flex: 1; margin: 0; font-size: 30px; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.round-btn { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--raised); color: var(--accent); display: grid; place-items: center; flex: none; }
.round-btn svg { width: 18px; height: 18px; }
.select-btn svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.select-btn svg circle { fill: none; stroke: currentColor; } /* the app's icons fill circles by default */
.select-btn.on { width: auto; padding: 0 12px; border-radius: 17px; font-size: 14px; color: var(--soft); }
.select-btn.on svg { display: none; }
.select-btn.on::after { content: "Cancel"; }
.title-row h1.long { font-size: 24px; }
/* Newest/Oldest toggle: the arrow points down the list, newest at the top */
.sort-btn { flex: none; height: 30px; padding: 0 12px 0 9px; border: 0; border-radius: 15px; background: var(--raised); color: var(--soft); font-size: 14px; display: flex; align-items: center; gap: 5px; }
.sort-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s; }
.sort-btn.flip svg { transform: rotate(180deg); }
.icon-btn { background: none; border: 0; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; color: var(--accent); flex: none; }
.icon-btn:active { background: var(--raised); }
.search { position: relative; margin-top: 8px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--dim); pointer-events: none; }
.search input { width: 100%; height: 38px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface); padding: 0 12px 0 34px; font-size: 16px; }
.search input::placeholder { color: var(--dim); }
.search input:focus { outline: none; border-color: var(--edge); }
.chips { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 0; height: 30px; padding: 0 14px; border-radius: 15px; background: var(--raised); color: var(--soft); font-size: 14px; }
.chip.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.chip .count { margin-left: 6px; font-weight: 400; opacity: .7; font-variant-numeric: tabular-nums; }
.chip .count:empty { display: none; }

/* List: one rounded card of rows */
.list { list-style: none; margin: 6px 12px 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.list:empty { display: none; }
.item { display: flex; align-items: center; gap: 4px; padding: 0 4px 0 12px; min-height: 62px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item:active { background: var(--raised); }
.item-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; background: none; border: 0; text-align: left; padding: 10px 0; }
.thumb { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex: none; background: var(--raised); color: var(--soft); overflow: hidden; }
.thumb svg { width: 21px; height: 21px; }
.thumb.folder { color: var(--accent); }
.item-text { min-width: 0; }
.item-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { font-size: 13px; color: var(--muted); }
.item .icon-btn { color: var(--dim); }
.item .chev { color: var(--edge); width: 18px; height: 18px; margin-right: 10px; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* Photo grid, grouped by month */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; margin-top: 6px; }
@media (min-width: 500px) { .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); } }
.list:not(:empty) + .grid { margin-top: 18px; }
.month { grid-column: 1 / -1; padding: 14px 16px 8px; font-size: 17px; font-weight: 700; }
.month:first-child { padding-top: 4px; }
.month span { font-weight: 400; font-size: 14px; color: var(--muted); margin-left: 4px; }
.tile { position: relative; aspect-ratio: 1; background: var(--surface); border: 0; padding: 0; overflow: hidden; cursor: pointer; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity .25s; }
.tile.pending { background: linear-gradient(100deg, var(--surface) 30%, var(--raised) 50%, var(--surface) 70%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
.tile.pending img { opacity: 0; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
#grid-end { height: 1px; }

/* Search results from every folder, under the open folder's own */
.everywhere { margin-top: 14px; }
.everywhere-head { padding: 6px 16px 8px; font-size: 17px; font-weight: 700; }
.everywhere-head .count { font-weight: 400; font-size: 14px; color: var(--muted); }
.everywhere-none { padding: 0 16px; color: var(--muted); }
.everywhere-more { display: block; margin: 12px auto 0; border: 0; border-radius: 15px; height: 34px; padding: 0 18px; background: var(--raised); color: var(--soft); font-size: 14px; }
.thumb { position: relative; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }

/* Select: ticks on tiles and rows, and an action bar in place of the tabs */
body.selecting .tabbar { display: none; }
body.selecting .tile::before { content: ""; position: absolute; top: 6px; right: 6px; width: 20px; height: 20px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 3px rgb(0 0 0 / .6); z-index: 2; }
body.selecting .tile.picked::before { top: 0; right: 0; bottom: 0; left: 0; width: auto; height: auto; border: 0; border-radius: 0; box-shadow: inset 0 0 0 3px var(--accent);
  background: rgb(0 0 0 / .3) no-repeat right 5px top 5px / 24px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='11' fill='%23e07b5b' stroke='%23fff' stroke-width='2'/%3E%3Cpath d='M7 12.5l3.2 3L17 9' fill='none' stroke='%23fff' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.item.picked { background: rgb(224 123 91 / .16); }
.select-bar { position: fixed; left: 12px; right: 12px; bottom: calc(var(--safe-bottom) + 10px); z-index: 20; max-width: 520px; margin: 0 auto; height: 58px; border-radius: 29px; background: var(--raised); border: 1px solid var(--edge); display: flex; align-items: center; gap: 2px; padding: 0 8px 0 18px; box-shadow: 0 8px 30px rgb(0 0 0 / .5); }
.select-bar #select-count { flex: 1; font-size: 14px; color: var(--soft); white-space: nowrap; }
.select-bar button { width: 44px; height: 44px; border: 0; background: none; color: var(--accent); display: grid; place-items: center; border-radius: 50%; flex: none; }
.select-bar button:disabled { opacity: .35; }
.select-bar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Drive Status rows; a warning shows red */
.item.status .item-main { cursor: default; }
.item.status button.item-main { cursor: pointer; }
.status-text { white-space: pre-line; }
.status-bar { margin-top: 8px; height: 6px; border-radius: 3px; background: var(--raised); overflow: hidden; }
.status-bar span { display: block; height: 100%; background: var(--accent); }
.item.status.warn .item-name { color: #ff5a6e; }
.item.status.warn { background: rgb(255 90 110 / .1); }

/* Recently viewed: a row of thumbnails at the top of the Library */
.recent { margin: 10px 0 4px; }
.recent-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 16px 8px; font-size: 17px; font-weight: 700; }
.recent-clear { border: 0; background: none; color: var(--accent); font-size: 14px; padding: 4px 0; }
.recent-strip { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; padding: 0 0 2px; }
.recent-strip::-webkit-scrollbar { display: none; }
.recent-strip .tile { flex: none; width: 84px; height: 84px; }
.tile .fallback { position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); }
.tile.video-tile { background: var(--raised); }
.tile .badge { position: absolute; right: 6px; bottom: 6px; filter: drop-shadow(0 1px 2px rgb(0 0 0 / .6)); }
.tile .badge svg { width: 16px; height: 16px; fill: #fff; stroke: none; }
.tile .caption { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 5px; font-size: 11px; color: #fff; background: linear-gradient(transparent, rgb(0 0 0 / .6)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; }

/* Floating tab bar */
.tabbar {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--safe-bottom) + 10px); z-index: 20;
  max-width: 520px; margin: 0 auto; height: 58px; border-radius: 29px;
  display: flex; align-items: center; justify-content: space-around;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border: 1px solid var(--edge);
}
.tabbar button, .tabbar .add { cursor: pointer; background: none; border: 0; width: 48px; height: 48px; display: grid; place-items: center; color: var(--dim); border-radius: 50%; }
.tabbar button.on { color: var(--accent); }
.tabbar svg { width: 24px; height: 24px; }
.tabbar .add { width: 46px; height: 46px; background: var(--accent); color: var(--accent-text); box-shadow: 0 0 0 4px rgb(224 123 91 / .12), 0 6px 22px rgb(224 123 91 / .45); }
.tabbar .add svg { stroke-width: 2.4; }

/* Toast */
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar) + 8px); z-index: 30; max-width: 500px; margin: 0 auto; background: var(--raised); border: 1px solid var(--edge); border-radius: 14px; padding: 12px 14px; box-shadow: 0 8px 30px rgb(0 0 0 / .5); font-size: 14px; }
.bar { height: 4px; background: var(--edge); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* Mini audio player, sits just above the tab bar */
.player { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar) + 2px); z-index: 19; max-width: 520px; margin: 0 auto; display: flex; gap: 10px; align-items: center; background: var(--raised); border: 1px solid var(--edge); border-radius: 16px; padding: 8px 6px 8px 8px; box-shadow: 0 8px 30px rgb(0 0 0 / .5); }
.player-art { position: relative; overflow: hidden; width: 38px; height: 38px; border-radius: 10px; border: 0; padding: 0; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; flex: none; }
.player-art svg { width: 20px; height: 20px; }
.player-art img, .player-full-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.player-info { flex: 1; min-width: 0; }
.player-title { display: block; width: 100%; background: none; border: 0; padding: 0; color: inherit; font: inherit; text-align: left; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { height: 14px; display: flex; align-items: center; cursor: pointer; }
.progress div { height: 3px; width: 100%; background: var(--edge); border-radius: 2px; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); }
.player-btns { display: flex; }
.player-btns .icon-btn { width: 36px; color: var(--text); }
.player-btns svg { fill: currentColor; width: 18px; height: 18px; }
#close-player svg { fill: none; color: var(--dim); }

/* Full-screen player */
.player-full { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; align-items: center;
  padding: calc(var(--safe-top) + 6px) 24px calc(var(--safe-bottom) + 28px); touch-action: pan-y; will-change: transform; }
.player-full-top { display: flex; align-items: center; width: 100%; gap: 4px; margin: 0 -12px; }
.player-full-top .icon-btn { color: var(--soft); }
.player-full-sub { flex: 1; min-width: 0; text-align: center; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-full-art { position: relative; width: min(78vw, 360px); aspect-ratio: 1; margin: auto 0; border-radius: 22px; background: var(--raised); color: var(--accent);
  display: grid; place-items: center; overflow: hidden; box-shadow: 0 16px 50px rgb(0 0 0 / .6); }
.player-full-art svg { width: 40%; height: 40%; fill: currentColor; stroke: none; }
.player-full-title { width: 100%; font-size: 20px; font-weight: 700; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 24px 0 6px; }
.player-full .progress { width: 100%; height: 28px; }
.player-full .progress div { height: 5px; border-radius: 3px; }
.player-full-times { width: 100%; display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: -4px; }
.player-full-btns { display: flex; align-items: center; justify-content: center; gap: 24px; margin: 20px 0 8px; }
.player-full-btns button { background: none; border: 0; color: var(--text); width: 64px; height: 64px; display: grid; place-items: center; border-radius: 50%; }
.player-full-btns button:active { background: var(--raised); }
.player-full-btns svg { width: 30px; height: 30px; fill: currentColor; }
.player-full-btns .big { width: 78px; height: 78px; background: var(--accent); color: var(--accent-text); }
.player-full-btns .big svg { width: 36px; height: 36px; }

/* Viewer */
.viewer { position: fixed; inset: 0; z-index: 40; background: #000; display: flex; flex-direction: column; }
.viewer-top { display: flex; align-items: center; gap: 4px; padding: calc(var(--safe-top) + 6px) 8px 6px; color: #fff; }
.viewer-top .icon-btn { color: #fff; }
.viewer-head { flex: 1; min-width: 0; text-align: center; }
.viewer-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-meta { font-size: 12px; color: var(--muted); }
.viewer-stage { flex: 1; min-height: 0; display: grid; place-items: center; touch-action: pan-y pinch-zoom; }
.viewer-stage img, .viewer-stage video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-stage .photo { position: relative; width: 100%; height: 100%; overflow: hidden; touch-action: none; }
.viewer-stage .photo .full { transform-origin: 0 0; will-change: transform; }
.viewer-stage .photo img { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; object-fit: contain; }
/* The square grid thumbnail, stretched and blurred into a soft backdrop while
   the photo arrives, so there's no shape to jump when the photo fades in. */
.viewer-stage .photo .ph { object-fit: cover; filter: blur(28px); transform: scale(1.1); opacity: .55; }
.viewer-stage .photo .full { opacity: 0; transition: opacity .2s; }
.viewer-stage .photo .full.loaded { opacity: 1; }
.viewer-stage .no-preview { color: var(--soft); text-align: center; padding: 24px; }
.viewer-stage .no-preview button { margin-top: 14px; height: 44px; padding: 0 20px; border-radius: 12px; }
.nav-btn { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 64px; border: 0; background: rgb(43 39 38 / .6); color: #fff; display: grid; place-items: center; }
.nav-btn.left { left: 0; border-radius: 0 12px 12px 0; }
.nav-btn.right { right: 0; border-radius: 12px 0 0 12px; }
@media (hover: none) { .nav-btn { display: none; } }
.viewer-bar { display: flex; justify-content: space-around; align-items: center; margin: 8px 12px calc(var(--safe-bottom) + 10px); height: 54px; border-radius: 27px; background: var(--surface); border: 1px solid var(--line); }
.viewer-bar button { background: none; border: 0; width: 48px; height: 48px; display: grid; place-items: center; color: var(--soft); }
.viewer-bar .del { color: var(--accent); }
.viewer-bar .fav svg { fill: none; stroke: currentColor; transition: transform .15s; }
.viewer-bar .fav.on { color: #ff5a6e; }
.viewer-bar .fav.on svg { fill: currentColor; }
.viewer-bar .fav:active svg { transform: scale(1.25); }
/* Album rows: a stack icon, or the album's cover photo */
.thumb.albums-icon { color: var(--accent); }
.thumb.albums-icon svg { fill: none; stroke: currentColor; }
/* The Favorites album's row on the home screen */
.thumb.fav-album { color: #ff5a6e; }
.thumb.fav-album svg { fill: currentColor; stroke: none; }
/* A small heart on favorite tiles */
.tile.fav::after { content: ""; position: absolute; left: 6px; bottom: 6px; width: 15px; height: 15px; filter: drop-shadow(0 1px 2px rgb(0 0 0 / .6));
  background: no-repeat center/contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23fff' d='M12 20s-7-4.4-7-10a4 4 0 0 1 7-2.6A4 4 0 0 1 19 10c0 5.6-7 10-7 10z'/%3E%3C/svg%3E"); }

/* Action sheet */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / .55); display: flex; align-items: flex-end; }
.sheet { width: 100%; max-width: 520px; margin: 0 auto; padding: 8px 8px calc(var(--safe-bottom) + 8px);
  /* A long menu (many folders or albums) fits the screen and scrolls. */
  max-height: calc(100vh - var(--safe-top) - 12px); /* older iPhones */
  max-height: calc(100dvh - var(--safe-top) - 12px); display: flex; flex-direction: column; }
.sheet-title, .sheet-cancel { flex: none; }
#sheet-actions { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; border-radius: 0 0 16px 16px; }
.sheet-title { background: var(--raised); border-radius: 16px 16px 0 0; padding: 14px; text-align: center; font-size: 13px; color: var(--muted); word-break: break-word; white-space: pre-line; }
#sheet-actions button, .sheet-cancel { display: block; width: 100%; height: 56px; border: 0; background: var(--raised); color: var(--text); font-size: 17px; border-top: 1px solid var(--edge); }
#sheet-actions button:last-child { border-radius: 0 0 16px 16px; }
#sheet-actions button.danger { color: var(--danger); }
#sheet-actions button.primary { color: var(--accent); font-weight: 600; }
.sheet-cancel { margin-top: 8px; border-radius: 16px; font-weight: 600; border-top: 0; color: var(--accent) !important; }
