/* stashr: the web as it looked in 2013. Flat colour, a wall of tiles, long
   shadows, light lowercase headings, buttons with a solid edge you can press. */

:root {
  /* The Flat UI palette. */
  --midnight: #2c3e50;
  --asphalt: #34495e;
  --clouds: #ecf0f1;
  --silver: #bdc3c7;
  --concrete: #95a5a6;
  --turquoise: #1abc9c;
  --emerald: #2ecc71;
  --emerald-edge: #27ae60;
  --river: #3498db;
  --river-edge: #2980b9;
  --amethyst: #9b59b6;
  --sunflower: #f1c40f;
  --carrot: #e67e22;
  --alizarin: #e74c3c;
  --alizarin-edge: #c0392b;

  --font: "Lato", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --gap: 10px;
  --gutter: 14px;
  --nav: 62px;
}

* { box-sizing: border-box; }

html {
  background: var(--midnight);
  color: #fff;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0 auto;
  max-width: 760px;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) var(--gutter) calc(var(--nav) + env(safe-area-inset-bottom) + 24px);
}

h1, h2, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { fill: currentColor; }

:focus-visible { outline: 3px solid var(--sunflower); outline-offset: 2px; }

.hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ------------------------------------------------------------ header */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 0 12px;
}

.logo {
  font-weight: 300;
  font-size: 2.5rem;
  line-height: 1;
  letter-spacing: -0.02em;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--asphalt);
  font-size: 0.875rem;
  font-weight: 700;
}

.status::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--concrete);
}

.status[data-state="ok"]::before { background: var(--emerald); }
.status[data-state="busy"]::before { background: var(--sunflower); animation: blink 1s steps(2) infinite; }
.status[data-state="bad"] { background: var(--alizarin); }
.status[data-state="bad"]::before { background: #fff; }

@keyframes blink { 50% { opacity: 0.25; } }

/* ------------------------------------------------------------ buttons */

.btn {
  --face: var(--river);
  --edge: var(--river-edge);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  border: 0;
  border-radius: 6px;
  background: var(--face);
  box-shadow: 0 4px 0 var(--edge);
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
  transform: translateY(-2px);
  transition: transform 0.06s, box-shadow 0.06s;
}

.btn:active { transform: translateY(2px); box-shadow: 0 0 0 var(--edge); }
.btn[disabled] { --face: var(--concrete); --edge: #7f8c8d; cursor: default; }
.btn-green { --face: var(--emerald); --edge: var(--emerald-edge); }
.btn-red { --face: var(--alizarin); --edge: var(--alizarin-edge); }
.btn-flat { --face: var(--asphalt); --edge: #22303f; }
.btn-light { --face: var(--silver); --edge: var(--concrete); color: var(--midnight); }
.btn-done { --face: transparent; --edge: transparent; box-shadow: inset 0 0 0 2px var(--emerald); color: var(--emerald); transform: none; }

/* ------------------------------------------------------------ search bar */

.search {
  display: flex;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 8px 0 12px;
  background: var(--midnight);
}

.search input {
  flex: 1;
  min-width: 0;
  height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  background: #fff;
  color: var(--midnight);
  font-size: 1.0625rem;
}

.search input::placeholder { color: var(--concrete); }
.search input::-webkit-search-cancel-button { display: none; }

/* ------------------------------------------------------------ views */

.view[hidden] { display: none; }

.title {
  font-weight: 300;
  font-size: 3rem;
  line-height: 1;
  letter-spacing: -0.02em;
  margin: 10px 0 16px;
}

.note { color: var(--silver); max-width: 34em; margin: 4px 0 14px; }
.note[data-kind="error"] { color: #fff; background: var(--alizarin); padding: 12px 14px; border-radius: 6px; }
.note[hidden] { display: none; }

.speeds { color: var(--silver); font-weight: 700; margin: -8px 0 14px; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ tile wall */

.tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--gap);
}

@media (min-width: 520px) { .tiles { grid-template-columns: repeat(4, 1fr); } }

.tile {
  --color: var(--river);
  position: relative;
  display: block;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--color);
  padding: 12px;
  text-align: left;
  border: 0;
  width: 100%;
  transition: transform 0.08s;
}

.tile:active { transform: scale(0.96); }
.tile-wide { grid-column: span 2; aspect-ratio: auto; min-height: 150px; }

/* The long shadow: a dark band running from the icon to the bottom right. */
.tile .glyph {
  position: absolute;
  left: 50%;
  top: 44%;
  width: 46%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
}

.tile .glyph::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 400%;
  height: 72%;
  background: rgba(0, 0, 0, 0.14);
  transform-origin: 0 50%;
  transform: translateY(-50%) rotate(45deg);
}

.glyph svg { position: relative; display: block; width: 100%; height: 100%; }

.tile-name {
  position: absolute;
  left: 12px;
  right: 40px;
  bottom: 9px;
  font-size: 1.125rem;
  font-weight: 400;
  line-height: 1.15;
}

.tile-name small { display: block; font-size: 0.8125rem; opacity: 0.85; }

.tile-more {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 44px;
  height: 44px;
  border: 0;
  background: rgba(0, 0, 0, 0.16);
  color: #fff;
  font-size: 1.25rem;
  font-weight: 900;
  line-height: 1;
}

.tile-more:active { background: rgba(0, 0, 0, 0.32); }

.tile[data-state="stopped"] { --color: #7f8c8d !important; }
.tile[data-state="stopped"] .tile-name small,
.tile[data-state="busy"] .tile-name small { font-weight: 700; opacity: 1; }

.tile[data-state="busy"]::after,
.tile-add::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.tile[data-state="busy"]::after { background: var(--stripes); background-size: 40px 40px; animation: stripes 1s linear infinite; }

/* Storage tile */
.tile-storage { background: var(--asphalt); padding: 14px; }
.storage-number { font-weight: 900; font-size: 3.25rem; line-height: 0.95; letter-spacing: -0.02em; }
.storage-number small { font-size: 1.25rem; font-weight: 400; letter-spacing: 0; margin-left: 4px; }

.bar {
  display: flex;
  height: 16px;
  margin-top: 12px;
  background: var(--midnight);
  border-radius: 3px;
  overflow: hidden;
}

.bar span { min-width: 3px; transition: flex-grow 0.5s; }

.legend { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 8px; font-size: 0.8125rem; color: var(--clouds); }
.legend li { display: flex; align-items: center; gap: 5px; }
.legend li::before { content: ""; width: 9px; height: 9px; background: var(--swatch); }
.storage-meta { margin-top: 8px; font-size: 0.8125rem; color: var(--silver); font-variant-numeric: tabular-nums; }
.storage-meta b { color: #fff; }

/* Downloads tile */
.tile-downloads { background: var(--emerald); padding: 14px; }
.tile-downloads .big { font-weight: 900; font-size: 3.25rem; line-height: 0.95; }
.tile-downloads .big small { font-size: 1.125rem; font-weight: 400; margin-left: 6px; }
.tile-downloads p { font-size: 0.9375rem; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-downloads .progress { margin-top: 10px; background: rgba(0, 0, 0, 0.18); }
.tile-downloads .progress i { background-color: #fff; }

/* "Get more apps" tile */
.tile-add { background: transparent; box-shadow: inset 0 0 0 3px var(--asphalt); color: var(--silver); }
.tile-add .plus { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); font-size: 4rem; font-weight: 300; line-height: 1; }

/* ------------------------------------------------------------ progress */

:root { --stripes: linear-gradient(45deg, rgba(255, 255, 255, 0.18) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.18) 50%, rgba(255, 255, 255, 0.18) 75%, transparent 75%, transparent); }

.progress {
  height: 14px;
  border-radius: 3px;
  background: var(--asphalt);
  overflow: hidden;
}

.progress i {
  display: block;
  height: 100%;
  background-color: var(--river);
  transition: width 0.5s;
}

.progress.active i { background-image: var(--stripes); background-size: 40px 40px; animation: stripes 1s linear infinite; }

@keyframes stripes { from { background-position: 40px 0; } to { background-position: 0 0; } }

li[data-state="seeding"] .progress i,
li[data-state="done"] .progress i { background-color: var(--emerald); }
li[data-state="paused"] .progress i,
li[data-state="waiting"] .progress i { background-color: var(--concrete); }
li[data-state="error"] .progress i { background-color: var(--alizarin); }

/* ------------------------------------------------------------ rows */

.rows li {
  background: var(--asphalt);
  border-radius: 6px;
  padding: 14px;
  margin-bottom: var(--gap);
}

.row-title { font-weight: 700; overflow-wrap: anywhere; line-height: 1.3; }

.facts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; font-size: 0.875rem; }

.fact {
  padding: 2px 8px;
  border-radius: 3px;
  background: var(--midnight);
  color: var(--clouds);
  font-variant-numeric: tabular-nums;
}

.fact b { color: #fff; }
.fact-free { background: var(--emerald); color: #fff; font-weight: 700; }

.row-actions { display: flex; gap: 8px; margin-top: 14px; }
.row-actions .btn { flex: 1; }
.row-actions select { flex: none; }

select {
  appearance: none;
  height: 46px;
  padding: 0 32px 0 12px;
  border: 0;
  border-radius: 6px;
  background: var(--midnight) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23bdc3c7' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 10px center;
}

.dl-facts { margin: 8px 0 0; font-size: 0.875rem; color: var(--silver); font-variant-numeric: tabular-nums; }
.rows .progress { margin-top: 10px; background: var(--midnight); }

/* Category tiles: one solid colour each, like the home wall. */
.cats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}

.cats button {
  --color: var(--concrete);
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: var(--asphalt);
  color: var(--silver);
  font-weight: 700;
  font-size: 0.875rem;
  box-shadow: inset 0 -4px 0 var(--color);
}

.cats [data-cat="all"] { --color: var(--clouds); }
.cats [data-cat="movies"] { --color: var(--sunflower); }
.cats [data-cat="tv"] { --color: var(--alizarin); }
.cats [data-cat="books"] { --color: var(--turquoise); }
.cats [data-cat="music"] { --color: var(--amethyst); }
.cats button[aria-pressed="true"] { background: var(--color); color: var(--midnight); box-shadow: none; }
.cats [data-cat="tv"][aria-pressed="true"],
.cats [data-cat="music"][aria-pressed="true"] { color: #fff; }

/* A search result: poster and details on top, actions across the bottom. */
.rows li.result { padding: 16px; margin-bottom: 14px; }
.release { display: flex; gap: 16px; align-items: flex-start; }
.release-main { flex: 1; min-width: 0; padding-top: 2px; }
.result .row-title.clean { font-size: 1.125rem; line-height: 1.25; }
.result .tags { margin-top: 8px; }

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 14px;
  margin-top: 10px;
  font-size: 0.875rem;
  color: var(--silver);
  font-variant-numeric: tabular-nums;
}

.seeds-good { color: var(--emerald); font-weight: 700; }
.free { margin-top: 8px; }
.tag.tag-free { background: var(--emerald); }
.result .row-actions { margin-top: 16px; }
.result .row-actions select { flex: 0 0 38%; }

.poster {
  flex: none;
  width: 86px;
  height: 129px;
  object-fit: cover;
  background: var(--midnight);
}

/* No poster: a flat tile in the category's colour with a long-shadow icon. */
.poster-none {
  --color: var(--concrete);
  position: relative;
  overflow: hidden;
  background: var(--color);
}

.poster-none .glyph { position: absolute; left: 50%; top: 50%; width: 44%; aspect-ratio: 1; transform: translate(-50%, -50%); color: #fff; }
.poster-none .glyph::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 400%;
  height: 72%;
  background: rgba(0, 0, 0, 0.14);
  transform-origin: 0 50%;
  transform: translateY(-50%) rotate(45deg);
}

/* Clean release names */
.row-title.clean {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  font-size: 1.0625rem;
  cursor: pointer;
}

.row-title .year { font-weight: 300; color: var(--silver); }
.raw-name { margin-top: 4px; font-size: 0.75rem; color: var(--concrete); overflow-wrap: anywhere; }
.raw-name[hidden] { display: none; }

.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }

.tag {
  padding: 1px 7px;
  border-radius: 3px;
  background: var(--river);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

.tag[data-tag="4k"] { background: var(--amethyst); }
.tag[data-tag="remux"],
.tag[data-tag="bluray"] { background: var(--carrot); }
.tag[data-tag="hdr"],
.tag[data-tag="dolby-vision"] { background: var(--sunflower); color: var(--midnight); }
.tag[data-tag="romanian"],
.tag[data-tag="multi"],
.tag[data-tag="spanish"] { background: var(--turquoise); }
.tag[data-tag^="s"][data-tag*="e"],
.tag[data-tag^="season"],
.tag[data-tag="complete"] { background: var(--alizarin); }

.dl-head .row-title.clean { font-size: 1rem; }

.pills { display: flex; gap: 8px; margin-bottom: 14px; }
.pills[hidden] { display: none; }

.pills button {
  border: 0;
  border-radius: 999px;
  padding: 7px 14px;
  background: var(--asphalt);
  color: var(--silver);
  font-weight: 700;
  font-size: 0.875rem;
}

.pills button[aria-pressed="true"] { background: var(--river); color: #fff; }

/* ------------------------------------------------------------ setup */

.setup fieldset {
  margin: 0 0 var(--gap);
  padding: 14px;
  border: 0;
  border-radius: 6px;
  background: var(--asphalt);
}

.setup legend {
  float: left;
  width: 100%;
  margin-bottom: 6px;
  font-weight: 300;
  font-size: 1.5rem;
}

.setup label { display: block; margin: 12px 0 6px; font-weight: 700; font-size: 0.9375rem; clear: both; }

.setup input {
  width: 100%;
  height: 46px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: #fff;
  color: var(--midnight);
  font-size: 1.0625rem;
}

.setup .hint { margin-top: 6px; font-size: 0.8125rem; color: var(--silver); }
.btn-big { width: 100%; min-height: 56px; font-size: 1.125rem; margin-top: 6px; }

/* Home tile that starts setup */
.tile-setup { background: var(--sunflower); color: var(--midnight); padding: 14px; }
.tile-setup .big { font-weight: 900; font-size: 2rem; line-height: 1; }
.tile-setup p { margin-top: 6px; font-weight: 700; }
.tile-setup[data-failed] { background: var(--alizarin); color: #fff; }
.tile-setup .progress { margin-top: 12px; background: rgba(0, 0, 0, 0.15); }
.tile-setup .progress i { background-color: var(--midnight); }

/* Account controls at the bottom of the store */
.account { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 24px; padding: 14px; border-radius: 6px; background: var(--asphalt); }
.account[hidden] { display: none; }
.account p { flex: 1 0 100%; color: var(--silver); }

/* While logged out, only the login screen shows. */
body[data-gate] .search,
body[data-gate] .nav { display: none; }

/* ------------------------------------------------------------ store */

.starter {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  margin-bottom: var(--gap);
  border-radius: 6px;
  background: var(--river);
}

.starter[hidden] { display: none; }
.starter p { flex: 1; }

.store-row { display: flex; align-items: center; gap: 12px; }

.store-icon {
  flex: none;
  position: relative;
  width: 56px;
  height: 56px;
  overflow: hidden;
  background: var(--color);
}

.store-icon .glyph { position: absolute; inset: 12px; }
.store-icon .glyph::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 300%;
  height: 72%;
  background: rgba(0, 0, 0, 0.14);
  transform-origin: 0 50%;
  transform: translateY(-50%) rotate(45deg);
}

.store-text { flex: 1; min-width: 0; }
.store-text b { display: block; font-size: 1.0625rem; }
.store-text span { display: block; font-size: 0.875rem; color: var(--silver); }
.store-row .btn { flex: none; min-width: 96px; }
.store-job { margin-top: 12px; }
.store-job p { margin-top: 6px; font-size: 0.8125rem; color: var(--silver); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.store-job[data-failed] p { color: #fff; white-space: normal; }
.store-job[data-failed] .progress i { background-color: var(--alizarin); background-image: none; animation: none; }

/* ------------------------------------------------------------ nav */

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  height: calc(var(--nav) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--asphalt);
  box-shadow: 0 -4px 0 rgba(0, 0, 0, 0.18);
}

.nav a {
  position: relative;
  flex: 1;
  max-width: 190px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--silver);
}

.nav svg { width: 24px; height: 24px; }
.nav a[aria-current="page"] { color: #fff; background: var(--river); }

.badge {
  position: absolute;
  top: 6px;
  left: calc(50% + 6px);
  min-width: 20px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--alizarin);
  color: #fff;
  font-size: 0.75rem;
  text-align: center;
}

.badge[hidden] { display: none; }

/* ------------------------------------------------------------ app sheet */

.sheet {
  width: min(100%, 520px);
  max-width: 100%;
  max-height: 88dvh;
  margin: auto auto 0;
  padding: 0 0 calc(16px + env(safe-area-inset-bottom));
  border: 0;
  border-radius: 10px 10px 0 0;
  background: var(--clouds);
  color: var(--midnight);
  overflow-y: auto;
}

@media (min-width: 560px) { .sheet { margin: auto; border-radius: 10px; } }

.sheet::backdrop { background: rgba(20, 30, 40, 0.7); }

.sheet-head {
  --color: var(--river);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
  background: var(--color);
  color: #fff;
}

.sheet-head .glyph { flex: none; width: 52px; height: 52px; }
.sheet-head h2 { font-weight: 300; font-size: 2rem; line-height: 1; }
.sheet-head p { font-size: 0.9375rem; margin-top: 4px; }

.sheet-state { padding: 14px 18px 0; font-weight: 700; }
.sheet-state:empty { display: none; }

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px 18px 6px;
}

.sheet-actions .btn-wide { grid-column: span 2; min-height: 54px; font-size: 1.0625rem; }
.sheet-close { display: flex; width: calc(100% - 36px); margin: 12px 18px 0; }

.log {
  margin: 10px 18px 0;
  padding: 12px;
  max-height: 40dvh;
  overflow: auto;
  border-radius: 6px;
  background: var(--midnight);
  color: var(--clouds);
  font: 0.75rem/1.5 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.log[hidden] { display: none; }

.keybox {
  grid-column: span 2;
  padding: 10px 12px;
  border-radius: 6px;
  background: #fff;
  font: 0.875rem/1.4 ui-monospace, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
  user-select: all;
}

/* ------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav) + 16px + env(safe-area-inset-bottom));
  z-index: 20;
  transform: translate(-50%, 16px);
  width: min(calc(100% - 28px), 440px);
  padding: 13px 16px;
  border-radius: 6px;
  background: var(--emerald);
  box-shadow: 0 4px 0 var(--emerald-edge);
  color: #fff;
  font-weight: 700;
  overflow-wrap: anywhere;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
}

.toast[data-show] { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { background: var(--alizarin); box-shadow: 0 4px 0 var(--alizarin-edge); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
