:root {
  --bg: #050505;
  --surface: #0d0d0d;
  --surface-raised: #151515;
  --line: #333;
  --muted: #8e8e8e;
  --text: #f3f3f3;
  --danger: #d93636;
  --danger-dark: #6d1616;
  --success: #1d6d44;
  --safe-bottom: max(16px, env(safe-area-inset-bottom));
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px) 0 0 / 100% 4px,
    var(--bg);
}

button, input, .interactive, .file-row {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

button { font: inherit; }

button:focus-visible, input:focus-visible, .file-row:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.app {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  border-inline: 1px solid rgba(255,255,255,.08);
  background: rgba(5,5,5,.96);
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(5,5,5,.94);
  backdrop-filter: blur(12px);
}

.topbar__title { font-weight: 800; letter-spacing: .12em; }

.trash-trigger {
  position: relative;
  display: flex;
  gap: 7px;
  align-items: center;
  min-height: 34px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  transition: transform 120ms ease;
  touch-action: manipulation;
}

.trash-trigger.is-escaping { position: fixed; z-index: 80; }

.game { min-height: calc(100vh - 104px); padding: 12px 12px 24px; }

.storage-panel { position: sticky; z-index: 10; top: 52px; padding-bottom: 12px; background: var(--bg); }

.banner {
  padding: 12px;
  border: 1px solid #844;
  border-left: 5px solid var(--danger);
  background: rgba(109,22,22,.45);
  font-size: 13px;
  line-height: 1.45;
}

.banner--success { border-color: #285c43; border-left-color: #4bd18d; background: rgba(29,109,68,.36); }

.storage-copy { display: flex; justify-content: space-between; gap: 12px; padding: 12px 2px 7px; font-size: 12px; }
.meter { height: 5px; overflow: hidden; background: #242424; }
.meter span { display: block; width: 99%; height: 100%; background: var(--danger); transition: width 500ms ease; }

.system-whisper {
  min-height: 0;
  margin: 0;
  color: #e7e7e7;
  font-size: 12px;
  line-height: 1.45;
}
.system-whisper:not(:empty) { min-height: 38px; margin: 4px 0 10px; padding: 9px 10px; border-left: 1px solid #fff; background: #0b0b0b; }

.file-list { border-top: 1px solid var(--line); }

.file-row {
  position: relative;
  min-height: 62px;
  overflow: hidden;
  border-bottom: 1px solid #262626;
  background: var(--bg);
  touch-action: pan-y;
}

.file-row__main {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  min-height: 61px;
  padding: 10px 8px;
  border: 0;
  color: inherit;
  text-align: left;
  background: var(--bg);
  cursor: pointer;
  transform: translateX(var(--swipe-x, 0));
  transition: transform 180ms ease, opacity 280ms ease;
}

.file-row__name { overflow: hidden; font-size: 13px; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
.file-row__size { color: var(--muted); font-size: 12px; white-space: nowrap; }
.file-row__delete {
  position: absolute;
  z-index: 1;
  inset: 0 0 0 auto;
  width: 92px;
  border: 0;
  color: #fff;
  background: var(--danger-dark);
  cursor: pointer;
}

.file-row.is-open { --swipe-x: -92px; }
.file-row.is-removing .file-row__main { opacity: 0; transform: translateX(-110%); }
.file-row.is-returning { animation: return-file 620ms cubic-bezier(.2,.8,.2,1); }
.file-row.is-nudging { animation: nudge 1.2s ease-in-out infinite; }
.file-row.is-system .file-row__name { color: #fff; text-shadow: 0 0 10px rgba(255,255,255,.5); }

@keyframes return-file { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: translateY(0); } }
@keyframes nudge { 0%,100% { transform: translateX(0); } 50% { transform: translateX(7px); } }

.gesture-hint { margin: 16px 4px 0; color: var(--muted); font-size: 11px; text-align: center; }

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 16px var(--safe-bottom);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}
.site-footer a { color: inherit; }

.layer { position: fixed; z-index: 100; inset: 0; }
.layer__scrim { position: absolute; inset: 0; width: 100%; border: 0; background: rgba(0,0,0,.74); }

.file-card {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  width: min(100%, 520px);
  min-height: 280px;
  max-height: 90vh;
  margin: 0 auto;
  padding: 14px 16px calc(var(--safe-bottom) + 12px);
  border: 1px solid #464646;
  border-bottom: 0;
  background: #111;
  box-shadow: 0 -22px 70px rgba(0,0,0,.65);
}

.file-card__handle { width: 42px; height: 3px; margin: 0 auto 20px; background: #5e5e5e; }
.file-card h2 { overflow-wrap: anywhere; margin: 0 0 8px; font-size: 18px; }
.file-meta { margin: 0 0 28px; color: var(--muted); font-size: 12px; }
.file-reply { min-height: 58px; margin: 0 0 26px; font-size: 15px; line-height: 1.6; }
.file-reply::before, .file-reply::after { color: #777; }
.file-reply:not(:empty)::before { content: "«"; }
.file-reply:not(:empty)::after { content: "»"; }

.card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.card-actions .button--ghost { grid-column: 1 / -1; }
.card-actions.is-falling .button { position: fixed; z-index: 130; width: min(42vw, 210px); animation: fall 720ms cubic-bezier(.2,.9,.35,1.05) forwards; }
.card-actions.is-falling #delete-button { left: calc(50% + 4px); bottom: calc(var(--safe-bottom) + 64px); animation-delay: 0ms; }
.card-actions.is-falling #keep-button { right: calc(50% + 4px); bottom: calc(var(--safe-bottom) + 64px); animation-delay: 180ms; }
.card-actions.is-falling #cancel-button { left: 50%; bottom: var(--safe-bottom); transform: translateX(-50%); animation-delay: 360ms; }
@keyframes fall { 0% { opacity: .2; translate: 0 -50vh; } 72% { opacity: 1; translate: 0 8px; } 86% { translate: 0 -5px; } 100% { opacity: 1; translate: 0 0; } }

.button {
  min-height: 48px;
  padding: 11px 12px;
  border: 1px solid #555;
  border-radius: 2px;
  color: #fff;
  background: #171717;
  cursor: pointer;
  touch-action: manipulation;
}
.button:disabled { cursor: not-allowed; opacity: .38; }
.button--danger { border-color: #7a2828; background: #531818; }
.button--quiet { background: #242424; }
.button--ghost { color: var(--muted); background: transparent; }

.full-panel {
  width: min(100%, 620px);
  height: 100%;
  margin: 0 auto;
  overflow-y: auto;
  background: var(--bg);
  padding-bottom: var(--safe-bottom);
}
.panel-header { position: sticky; z-index: 2; top: 0; display: flex; gap: 13px; align-items: center; min-height: 64px; padding: max(10px,env(safe-area-inset-top)) 14px 10px; border-bottom: 1px solid var(--line); background: rgba(5,5,5,.96); }
.panel-header h2 { margin: 0; font-size: 15px; }
.panel-header p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.back-button { width: 40px; height: 40px; border: 1px solid var(--line); color: #fff; background: #111; cursor: pointer; }
.trash-list, .single-list { display: grid; gap: 1px; padding: 12px; border: 0; }
.trash-item, .single-option { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 12px; align-items: center; min-height: 58px; padding: 10px 8px; border-bottom: 1px solid #272727; font-size: 12px; }
.trash-item button { min-height: 36px; border: 1px solid #4a4a4a; color: #fff; background: #171717; cursor: pointer; }
.empty-copy { padding: 30px 14px; color: var(--muted); text-align: center; }
.single-option { grid-template-columns: auto minmax(0,1fr); cursor: pointer; }
.single-option input { width: 20px; height: 20px; accent-color: #fff; }
.single-actions { position: sticky; bottom: 0; display: grid; gap: 8px; padding: 12px; background: rgba(5,5,5,.96); }

.ending {
  position: fixed;
  z-index: 150;
  inset: 0;
  overflow-y: auto;
  padding: max(20px,env(safe-area-inset-top)) 18px var(--safe-bottom);
  background: #000;
  color: #fff;
}
.ending__inner { display: grid; place-content: center; gap: 22px; width: min(100%,520px); min-height: calc(100vh - 40px); margin: 0 auto; text-align: center; }
.ending__headline { margin: 0; font-size: clamp(20px,7vw,40px); font-weight: 500; overflow-wrap: anywhere; }
.ending__file { width: 100%; min-height: 62px; padding: 18px 12px; border: 1px solid #383838; color: #fff; background: #060606; text-align: left; cursor: pointer; }
.ending__green { padding: 15px; border-left: 5px solid #4bd18d; background: rgba(29,109,68,.45); }

.act { width: min(100%,560px); margin: 0 auto; text-align: left; }
.act__paper { padding: clamp(18px,5vw,34px); border: 1px solid #454545; background: #080808; box-shadow: 12px 12px 0 #151515; }
.act__paper h1 { margin: 0 0 30px; font-size: clamp(18px,5vw,26px); }
.act__paper dl { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 12px; margin: 0 0 28px; font-size: 13px; }
.act__paper dt { color: var(--muted); }
.act__paper dd { margin: 0; text-align: right; }
.act__quote { min-height: 58px; padding-top: 18px; border-top: 1px solid #333; line-height: 1.55; }
.act__actions { display: grid; gap: 8px; margin-top: 26px; }
.result-link { display: flex; align-items: center; justify-content: center; color: inherit; text-decoration: none; }
.current-stats { margin: 24px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.back-top { margin: 24px 0 0; font-size: 12px; }
.back-top a { color: var(--muted); }
.result-page { display: block; }
.result-page .act { min-height: 100%; padding-block: 20px; }

.toast {
  position: fixed;
  z-index: 200;
  right: 12px;
  bottom: calc(var(--safe-bottom) + 8px);
  left: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: min(calc(100% - 24px),496px);
  min-height: 52px;
  margin: auto;
  padding: 10px 12px;
  border: 1px solid #454545;
  background: #1a1a1a;
  box-shadow: 0 8px 30px rgba(0,0,0,.7);
  font-size: 11px;
}
.toast__action { border: 0; color: #fff; background: transparent; cursor: pointer; }

.hold-button { position: relative; overflow: hidden; }
.hold-button::before { content: ""; position: absolute; inset: 0; width: var(--hold,0%); background: rgba(255,255,255,.2); pointer-events: none; }

.fatal { display: grid; place-content: center; min-height: 100vh; padding: 30px; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }

@media (orientation: landscape) and (max-height: 540px) {
  .topbar { min-height: 44px; padding-top: 7px; padding-bottom: 7px; }
  .storage-panel { top: 44px; }
  .banner { padding: 8px 10px; }
  .storage-copy { padding-block: 7px 5px; }
  .file-row, .file-row__main { min-height: 50px; }
  .file-card { min-height: 240px; max-height: 96vh; overflow-y: auto; }
  .file-meta { margin-bottom: 14px; }
  .file-reply { min-height: 36px; margin-bottom: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 120ms !important; animation-delay: 0ms !important; transition-duration: 120ms !important; }
}
