/* chute — neo-brutalism: 2px black borders, hard offset shadows, zero radius, flat yellow.
   Layout: usage on top -> composer -> masonry (top to bottom per column, height follows content). */

:root {
  color-scheme: light;

  --bg: #f3efe6;
  --card: #fffdf7;
  --ink: #111;
  --muted: #4d4a42;
  --faint: #8a867b;
  --yellow: #ffd60a;
  --on-yellow: #111;
  --red: #e03131;
  --blue: #2f5fe0;

  --bd: 2px solid var(--ink);
  --shadow-c: #111;
  --shadow-accent: #111;
  --sh: 4px 4px 0 var(--shadow-c);
  --sh-sm: 3px 3px 0 var(--shadow-c);
  --meta-bg: #fff;
  --toast-bg: #111;
  --toast-fg: #fff;

  --sans: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --gap: 14px;
}

/* Dark: lighter borders, shadows fade to near-black. Controlled by <html data-theme>; initial value is set in <head>. */
:root[data-theme="dark"] {
    color-scheme: dark;

    --bg: #141414;
    --card: #1d1d1d;
    --ink: #eae6da;
    --muted: #aaa69b;
    --faint: #7d7970;
    --red: #ff6b5e;
    --blue: #7aa2ff;

    /* A black shadow on a near-black background is invisible: cards use warm gray, controls switch to yellow. */
    --shadow-c: #46423a;
    --shadow-accent: #ffd60a;
    --meta-bg: #262626;
    --toast-bg: #eae6da;
    --toast-fg: #141414;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  /* Same formula as max(84px, (100% - 1400px) / 2 + 66px), 10px smaller overall. */
  padding: 20px max(74px, calc((100% - 1400px) / 2 + 56px)) 56px;
  background: var(--bg);
  color: var(--ink);
  font: 400 14px/1.55 var(--sans);
}

.sprite {
  display: none;
}

.icon {
  width: 1em;
  height: 1em;
}

/* Left dock: filters and search */

.dock {
  position: fixed;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dockbtn {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: var(--bd);
  background: var(--card);
  box-shadow: var(--sh-sm);
  color: var(--ink);
  cursor: pointer;
}

.dockbtn .icon {
  width: 22px;
  height: 22px;
}

.dockbtn:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--shadow-accent);
}

.dockbtn:active {
  transform: translate(3px, 3px);
  box-shadow: none;
}

.dockbtn.on {
  background: var(--yellow);
  color: var(--on-yellow);
}

.searchbar {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 45;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  width: min(720px, calc(100% - 40px));
  padding: 12px 16px;
  border: var(--bd);
  background: var(--card);
  box-shadow: 5px 5px 0 var(--shadow-accent);
}

.searchbar[hidden] {
  display: none;
}

.searchbar input {
  width: 100%;
  border: 0;
  background: none;
  font: 400 16px var(--sans);
  color: var(--ink);
}

.searchbar input:focus {
  outline: none;
}

/* Top: usage meter */

.topline {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-height: 32px;
  margin-bottom: 12px;
}

.themebtn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: var(--bd);
  background: var(--card);
  box-shadow: 2px 2px 0 var(--shadow-accent);
  color: var(--ink);
  cursor: pointer;
}

.themebtn .icon {
  width: 15px;
  height: 15px;
}

.themebtn:hover {
  background: var(--yellow);
  color: var(--on-yellow);
}

.themebtn:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

.meter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px 9px;
  border: var(--bd);
  background: var(--yellow);
  color: var(--on-yellow);
  font: 700 12px/1.4 var(--mono);
  letter-spacing: 0.02em;
}

.meter-hint,
#meter-text.low {
  color: var(--red);
}

/* Composer */

.composer {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 16px;
  padding: 8px 8px 8px 12px;
  border: var(--bd);
  background: var(--card);
  box-shadow: var(--sh);
}

.composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 26px;
  max-height: 132px;
  padding: 4px 0;
  border: 0;
  background: none;
  resize: none;
  overflow-y: auto;
  font: 400 15px/1.5 var(--sans);
  color: var(--ink);
}

.composer textarea:focus {
  outline: none;
}

.composer textarea::placeholder {
  color: var(--faint);
}

.iconbtn {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: var(--bd);
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
}

.iconbtn .icon {
  width: 16px;
  height: 16px;
}

.iconbtn:hover {
  background: var(--yellow);
  color: var(--on-yellow);
}

.iconbtn:active {
  transform: translate(2px, 2px);
}

.send {
  flex: none;
  padding: 7px 16px;
  border: var(--bd);
  background: var(--yellow);
  box-shadow: var(--sh-sm);
  color: var(--on-yellow);
  font: 700 13px/1.2 var(--mono);
  letter-spacing: 0.06em;
  cursor: pointer;
}

.send:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--shadow-accent);
}

.send:active {
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 var(--ink);
}

.send[disabled] {
  opacity: 0.55;
  cursor: progress;
  transform: none;
  box-shadow: var(--sh-sm);
}

/* Upload progress */

.uploadbar {
  margin: -4px 0 12px;
  border: var(--bd);
  background: var(--card);
  box-shadow: var(--sh-sm);
}

.uploadbar[hidden] {
  display: none;
}

.uploadbar i {
  display: block;
  width: 0;
  height: 5px;
  background: var(--yellow);
  transition: width 0.15s linear;
}

.uploadbar span {
  display: block;
  padding: 4px 9px;
  font: 700 11.5px var(--mono);
}

/* Capacity warning */

.capwarn {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -4px 0 12px;
  padding: 8px 12px;
  border: var(--bd);
  background: var(--yellow);
  color: var(--on-yellow);
  box-shadow: var(--sh-sm);
  font: 700 12px var(--mono);
}

.capwarn[hidden] {
  display: none;
}

.capwarn button {
  margin-left: auto;
  border: 0;
  background: none;
  color: var(--on-yellow);
  font: 700 15px var(--mono);
  cursor: pointer;
}

/* Board: multi-column masonry */

main {
  padding-bottom: 10px;
}

.board {
  columns: 260px;
  column-gap: var(--gap);
}

.tile {
  position: relative;
  display: block;
  width: 100%;
  margin: 0 0 var(--gap);
  break-inside: avoid;
  border: var(--bd);
  background: var(--card);
  box-shadow: var(--sh);
}

.tile.gone {
  opacity: 0;
  transition: opacity 0.12s linear;
}

.tile[hidden] {
  display: none;
}

/* Text: preserve line breaks, no truncation */

.text {
  margin: 0;
  padding: 12px 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 400 14px/1.62 var(--sans);
}

.text.code {
  font: 400 13px/1.6 var(--mono);
}

.textwrap {
  position: relative;
}

.tile[data-kind="text"] .text {
  max-height: 480px;
  overflow: hidden;
}

.tile.expanded .text {
  max-height: none;
}

.textwrap .fade {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 72px;
  pointer-events: none;
  background: linear-gradient(to bottom, transparent, var(--card));
}

.tile.clipped .textwrap .fade {
  display: block;
}

.tile.expanded .fade {
  display: none;
}

.expand {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 3px 10px;
  border: var(--bd);
  background: var(--card);
  box-shadow: 2px 2px 0 var(--shadow-c);
  font: 700 11px var(--mono);
  cursor: pointer;
}

.expand[hidden] {
  display: none;
}

.expand:hover {
  background: var(--yellow);
  color: var(--on-yellow);
}

/* Search hits */
mark.hit {
  background: var(--yellow);
  color: var(--on-yellow);
  padding: 0 1px;
}

/* Images: full column width, keep aspect ratio */

.tile[data-kind="image"] {
  overflow: hidden;
  background: var(--bg);
  line-height: 0;
}

.tile[data-kind="image"] .shot {
  display: block;
  width: 100%;
  height: auto;
}

/* Files: icon + name */

.tile[data-kind="file"] {
  padding: 11px 13px;
}

.file {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font: 700 13px/1.4 var(--mono);
  white-space: nowrap;
}

.file .icon {
  width: 16px;
  height: 16px;
  flex: none;
}

.name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Meta bar: date · size · download · delete */

.meta {
  position: absolute;
  top: -12px;
  right: -12px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px 3px 2px 8px;
  border: var(--bd);
  background: var(--meta-bg);
  box-shadow: 3px 3px 0 var(--shadow-accent);
  opacity: 0;
  transition: opacity 0.1s linear;
  pointer-events: none;
}

.tile:hover .meta,
.tile:focus-within .meta {
  opacity: 1;
  pointer-events: auto;
}

/* Crop image cards; keep the meta bar inside the card */
.tile[data-kind="image"] .meta {
  top: 6px;
  right: 6px;
}

/* Touch screens: the meta bar becomes a footer inside the tile instead of an overlay.
   On narrow columns it used to cover the first line of text and the file name. */
@media (hover: none), (max-width: 700px) {
  .meta {
    position: static;
    top: auto;
    right: auto;
    margin: 0;
    padding: 4px 6px 4px 10px;
    border: 0;
    border-top: var(--bd);
    background: var(--meta-bg);
    box-shadow: none;
    opacity: 1;
    pointer-events: auto;
    line-height: 1.4;
    min-height: 36px;
  }

  .meta time,
  .size {
    white-space: nowrap;
  }

  .meta .act {
    width: 30px;
    height: 30px;
  }

  .meta .act .icon {
    width: 15px;
    height: 15px;
  }

  /* Push the action buttons to the right edge, date and size stay on the left. */
  .meta time + .act,
  .meta .size + .act {
    margin-left: auto;
  }

  .tile[data-kind="file"] {
    padding: 0;
  }

  .tile[data-kind="file"] .file {
    padding: 11px 13px;
  }
}

.meta time {
  font: 700 11px/1 var(--mono);
  padding-right: 4px;
}

.size {
  font: 400 11px/1 var(--mono);
  color: var(--muted);
  padding-right: 4px;
}

.act {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
}

.act .icon {
  width: 13px;
  height: 13px;
}

.act:hover {
  background: var(--yellow);
  color: var(--on-yellow);
}

.act.del:hover {
  background: var(--red);
  color: #fff;
}

.empty {
  margin: 0;
  padding: 70px 0;
  text-align: center;
  font: 700 13px var(--mono);
  color: var(--muted);
}

/* Hint */

.toasts {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(460px, 90vw);
}

.toast {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  border: var(--bd);
  background: var(--toast-bg);
  color: var(--toast-fg);
  font: 700 12.5px var(--mono);
  box-shadow: 4px 4px 0 var(--yellow);
}

.toast.bad {
  background: var(--red);
  color: #fff;
  box-shadow: 4px 4px 0 var(--ink);
}

.toast button {
  margin-left: auto;
  padding: 2px 8px;
  border: 1px solid currentColor;
  background: none;
  color: inherit;
  font: 700 12px var(--mono);
  cursor: pointer;
}

.toast button:hover {
  background: var(--toast-fg);
  color: var(--toast-bg);
}

.drop-hint {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  background: rgba(17, 17, 17, 0.45);
  pointer-events: none;
}

.drop-hint span {
  padding: 14px 26px;
  border: 4px dashed #fff;
  background: #111;
  color: var(--yellow);
  font: 700 14px var(--mono);
  letter-spacing: 0.08em;
}

.drop-hint[hidden] {
  display: none;
}

@media (max-width: 700px) {
  :root {
    --gap: 10px;
  }

  body {
    padding: calc(14px + env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
      calc(96px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  /* Keep the sticky composer below the status bar in an installed PWA. */
  .composer {
    top: env(safe-area-inset-top);
  }

  .dock {
    left: 50%;
    top: auto;
    bottom: calc(12px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    flex-direction: row;
  }

  .dockbtn {
    width: 46px;
    height: 46px;
  }

  .searchbar {
    bottom: calc(70px + env(safe-area-inset-bottom));
    width: calc(100% - 20px);
  }
}

/* One readable column on phones; two or more columns need room. */
@media (max-width: 560px) {
  .board {
    columns: 1;
  }
}

/* Logout button in the top bar */

.logout {
  display: flex;
}

.logout[hidden] {
  display: none;
}

.logoutbtn {
  height: 30px;
  padding: 0 10px;
  border: var(--bd);
  background: var(--card);
  box-shadow: 2px 2px 0 var(--shadow-accent);
  color: var(--ink);
  font: 700 12px/1 var(--mono);
  cursor: pointer;
}

.logoutbtn:hover {
  background: var(--yellow);
  color: var(--on-yellow);
}

.logoutbtn:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

/* Login page */

.login-page {
  min-height: 100dvh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) max(24px, env(safe-area-inset-right))
    calc(24px + env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
}

.login-card {
  width: min(360px, 100%);
  padding: 28px;
  border: var(--bd);
  background: var(--card);
  box-shadow: var(--sh);
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 28px;
  letter-spacing: -0.02em;
}

.login-sub {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14px;
}

.login-card form {
  display: grid;
  gap: 12px;
}

.login-card label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.login-card input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: var(--bd);
  border-radius: 0;
  background: var(--meta-bg);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

.login-card button {
  margin-top: 4px;
  padding: 10px 14px;
  border: var(--bd);
  border-radius: 0;
  background: var(--yellow);
  box-shadow: var(--sh-sm);
  color: var(--on-yellow);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.login-card button:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

.login-error {
  margin: 0;
  color: var(--red);
  font-size: 13px;
}