/* Triage — the whole look.
 *
 * An email client that is secretly tense. Cool greys and a single blue, so it reads as software
 * rather than as a game; the only warm colour in the build is the one that means you are drowning.
 *
 * Motion rules, as ever: transforms and opacity only, nothing loops, everything bounded. --t is
 * the one duration; the motion setting scales it and prefers-reduced-motion zeroes it. */

:root {
  --t: 150ms;

  --ground: #0f1418;
  --panel: #161d23;
  --panel-2: #1b242b;
  --edge: #263139;
  --text: #e8eef3;
  --dim: #93a4b1;
  --faint: #5d6e7a;

  --blue: #4fc3e8;
  --blue-soft: #16323f;
  --green: #6fcf8f;
  --green-soft: #14301f;
  --amber: #e8b44f;
  --red: #e4695a;
  --red-soft: #3a1c18;

  --radius: 12px;
  --card-w: min(560px, 100%);
}

html[data-motion="fast"] { --t: 80ms; }
html[data-motion="instant"] { --t: 0ms; }
/* This has to out-specify the tier rules above and still let an explicit Full through.
   `:root` alone is (0,1,0) and loses to `html[data-motion="fast"]` at (0,1,1), so a
   reduced-motion player who chose Fast kept their animation - while one who deliberately
   chose Full was forced to zero, since nothing outranked the media query in that direction.
   Both were backwards. `html:not([data-motion="full"])` ties the tiers, comes later, and
   wins - except where the player has said Full, which is the one case it should lose. */
@media (prefers-reduced-motion: reduce) {
  html:not([data-motion="full"]) { --t: 0ms; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--ground);
  color: var(--text);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button {
  font: inherit;
  color: var(--text);
  background: #1d262d;
  border: 1px solid var(--edge);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: border-color var(--t), background-color var(--t), transform var(--t), opacity var(--t);
}
button:hover { border-color: var(--blue); background: #24303a; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.35; cursor: default; }
button.primary { background: var(--blue-soft); border-color: var(--blue); font-weight: 600; }
button.primary:hover { background: #1d4356; }

.cap { font-size: 9.5px; font-weight: 700; letter-spacing: 0.1em; color: var(--faint); display: block; }

/* ---------------------------------------------------------------- Layout */

.app {
  height: 100vh;
  height: 100dvh;   /* the visible height on a phone, not the one behind the browser's bars */
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-width: 900px;
  margin: 0 auto;
  padding: 12px;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  gap: 10px;
}

.top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 10px 16px;
}

.wordmark { font-weight: 700; font-size: 13px; letter-spacing: 0.14em; color: var(--blue); }
.day { display: block; font-size: 12px; color: var(--dim); margin-top: 2px; }

.counters { display: flex; gap: 22px; justify-content: center; min-width: 0; }
.counter b { font-family: Consolas, "Cascadia Mono", monospace; font-size: 22px; font-weight: 700; }
.counter .of { font-family: Consolas, monospace; font-size: 13px; color: var(--faint); }
.counter.streak b { color: var(--dim); transition: color var(--t), transform var(--t); display: inline-block; }
.counter.streak.hot b { color: var(--green); }
.counter.streak.bump b { transform: scale(1.3); }

.pressure { text-align: right; }
.pips { display: flex; gap: 4px; margin-top: 4px; justify-content: flex-end; }
.pip {
  width: 10px; height: 18px; border-radius: 3px;
  background: #1e2830; border: 1px solid var(--edge);
  transition: background-color var(--t), border-color var(--t), transform var(--t);
}
.pip.on { background: var(--blue); border-color: var(--blue); }
.pip.warn { background: var(--amber); border-color: var(--amber); }
.pip.danger { background: var(--red); border-color: var(--red); transform: scaleY(1.12); }

/* ---------------------------------------------------------------- The desk */

.desk {
  display: grid;
  min-width: 0;
  grid-template-rows: auto auto auto auto;
  /* Centred as a block, so a tall window does not sink everything to the floor. The stack
   * reserves the room it will need and grows upward into it, which is what the player watches. */
  align-content: center;
  gap: 12px;
  justify-items: center;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 0;
  transition: border-color calc(var(--t) * 2), background-color calc(var(--t) * 2);
}
.desk.warning { border-color: var(--red); background: #1a1618; }

/* The queue behind the focused email: shape only, never read. */
.stack {
  display: flex; flex-direction: column-reverse; gap: 3px;
  width: var(--card-w); align-self: end; justify-content: flex-end;
  min-height: 108px;   /* six sheets: a full inbox, reserved so the layout never jumps */
}
.stack .sheet {
  height: 14px; border-radius: 5px 5px 0 0;
  background: var(--panel-2); border: 1px solid var(--edge); border-bottom: none;
  animation: slide-in calc(var(--t) * 2) ease-out 1 both;
  transform-origin: bottom center;
}
.stack .sheet.bounced { border-color: var(--red-soft); background: #24191b; }
@keyframes slide-in { from { transform: translateY(-10px) scaleY(0.6); opacity: 0; } to { transform: none; opacity: 1; } }

.focus { width: var(--card-w); display: grid; }
.focus > * { grid-area: 1 / 1; }

.email {
  background: var(--panel-2);
  border: 1px solid var(--edge);
  border-left: 3px solid var(--blue);
  border-radius: 10px;
  padding: 16px 20px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  transition: transform var(--t) ease-out, opacity var(--t) ease-out;
}
.email.arriving { animation: pop-in calc(var(--t) * 2) ease-out 1 both; }
@keyframes pop-in { from { transform: translateY(8px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }

/* Filed: the card leaves toward its column. Three classes, one per direction. */
.email.go-archive { transform: translateX(-120%) rotate(-6deg); opacity: 0; }
.email.go-reply { transform: translateY(70%) scale(0.85); opacity: 0; }
.email.go-spam { transform: translateX(120%) rotate(6deg); opacity: 0; }

/* Wrong: a short shake, bounded, and the card goes red. */
.email.wrong { animation: shake calc(var(--t) * 2.5) ease-in-out 1 both; border-left-color: var(--red); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-9px); }
  45% { transform: translateX(8px); }
  70% { transform: translateX(-4px); }
}

.from { font-size: 12px; color: var(--dim); display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.bounced { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; color: var(--red); border: 1px solid var(--red-soft); border-radius: 4px; padding: 1px 6px; }
.subject { font-size: clamp(17px, 2.6vw, 23px); font-weight: 600; margin: 0; line-height: 1.3; }

.waiting-for-mail { display: grid; place-content: center; text-align: center; color: var(--faint); min-height: 120px; }
.waiting-for-mail small { display: block; margin-top: 4px; font-size: 12px; }

/* The three columns: the rule and the interface at the same time. */
.columns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: var(--card-w); }
.column {
  background: #141b21; border: 1px solid var(--edge); border-radius: 10px;
  padding: 10px 8px; text-align: center; cursor: pointer;
  transition: border-color var(--t), background-color var(--t), transform var(--t);
}
.column:hover { border-color: var(--blue); }
.column .key { font-family: Consolas, monospace; font-size: 11px; color: var(--blue); font-weight: 700; }
.column .label { font-size: 15px; font-weight: 600; margin-top: 2px; }
.column .hint { font-size: 10.5px; color: var(--faint); margin-top: 3px; line-height: 1.3; min-height: 26px; }
.column.hit { transform: translateY(2px); border-color: var(--blue); background: var(--blue-soft); }
.column.miss { border-color: var(--red); background: var(--red-soft); }

.teach { margin: 0; text-align: center; font-size: 13px; color: var(--dim); min-height: 20px; transition: color var(--t); }
.teach.wrong { color: var(--red); }
.teach.right { color: var(--green); }

/* ---------------------------------------------------------------- Bottom */

/* min-width:0 throughout: without it a flex or grid item refuses to shrink below its content, and
 * six buttons in a row would force the whole page wider than a phone. */
.app > * { min-width: 0; }
.bottom { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; min-width: 0; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; }
.actions button { font-size: 12px; padding: 6px 11px; }

/* ---------------------------------------------------------------- Overlays */

.overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(8, 11, 14, 0.9);
  /* Flex and an auto margin rather than grid centring: a panel taller than the window then
   * scrolls from its top instead of losing its heading and its button off both edges. */
  display: flex; padding: 16px;
  overflow-y: auto; overscroll-behavior: contain;
}
.panel {
  margin: auto;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 14px;
  padding: 24px 28px; max-width: 520px; width: 100%;
  animation: rise calc(var(--t) * 2) ease-out 1 both;
}
@keyframes rise { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
.panel h2 { font-size: 24px; margin: 0 0 10px; }
.panel p { color: var(--dim); margin: 0 0 12px; }
.panel .lede { color: var(--text); font-size: 16px; }
.panel .fine { font-size: 12.5px; color: var(--faint); }
.panel .controls { font-size: 13px; }

/* Say the controls the player actually has: keys on a desk, taps on a phone. */
.touch-only { display: none; }
@media (hover: none) and (pointer: coarse) {
  .touch-only { display: block; }
  .keys-only { display: none; }
}
.panel .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

/* The rules, drawn the same way in the start panel and in help. */
.rules { display: grid; gap: 6px; margin: 14px 0; }
.rule { display: grid; grid-template-columns: 30px 78px 1fr; gap: 10px; align-items: baseline; font-size: 13.5px; }
.rule .k { font-family: Consolas, monospace; font-weight: 700; color: var(--blue); }
.rule .n { font-weight: 600; }
.rule .d { color: var(--faint); font-size: 12.5px; }

.outcome h2 { color: var(--blue); }
.outcome.perfect h2 { color: var(--green); }
.outcome.lost h2 { color: var(--red); }
.lines div { color: var(--dim); margin-bottom: 5px; }
.lines div:first-child { color: var(--text); font-size: 16px; }
.share-done { color: var(--green); font-size: 12px; margin-top: 8px; }
.share-text { display: block; width: 100%; margin-top: 6px; padding: 6px 8px; resize: none; font: inherit; font-size: 12px; background: var(--ground); color: var(--text); border: 1px solid var(--edge); border-radius: 6px; }
.share-text[hidden] { display: none; }
.grid { display: grid; grid-template-columns: 1fr auto; gap: 4px 20px; margin: 0; }
.grid dt { color: var(--dim); }
.grid dd { margin: 0; text-align: right; font-family: Consolas, monospace; }

/* ---------------------------------------------------------------- Responsive */

@media (max-width: 620px) {
  /* One column: nothing on this screen is wide enough to sit beside anything else. */
  .top { grid-template-columns: 1fr; gap: 8px; padding: 10px 12px; }
  .top > * { min-width: 0; }
  .brand { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
  .day { margin-top: 0; }
  .counters { justify-content: space-between; gap: 8px; }
  .counter b { font-size: 19px; }
  .pressure { display: flex; align-items: center; gap: 10px; text-align: left; }
  .pressure .cap { margin: 0; }
  .pips { margin-top: 0; justify-content: flex-start; flex: 1; }
  .pip { flex: 1; max-width: 22px; }
  .desk { padding: 12px; gap: 10px; }
  .column { padding: 12px 6px; }
  .bottom { justify-content: center; }
}

@media (max-width: 420px) {
  .app { padding: 8px; gap: 8px; }
  .subject { font-size: 17px; }
  .email { min-height: 104px; padding: 14px; }
  .stack { min-height: 44px; }
  /* Taps need room: the columns are the only thing you press. */
  .column { padding: 16px 4px; }
  .column .label { font-size: 14px; }
  .bottom { justify-content: center; }
}

/* Narrow rules: name above the explanation, so the explanation gets the whole width. */
@media (max-width: 480px) {
  .rule { grid-template-columns: 22px 1fr; row-gap: 0; }
  .rule .d { grid-column: 2; }
  .overlay { padding: 10px; }
  .panel { padding: 18px; }
  .panel .rules { margin: 10px 0; }
  .panel p { margin-bottom: 9px; }
  .panel .row { margin-top: 12px; }
}

/* Short windows: a tab tucked beside something else, or a phone on its side. The line that says
 * why a misfile was wrong stays - it is the only manual - so the stack and padding give way. */
@media (max-height: 620px) {
  .app { gap: 6px; }
  .desk { padding: 8px 12px; gap: 6px; }
  .stack { min-height: 40px; gap: 2px; }
  .stack .sheet { height: 8px; }
  .email { min-height: 80px; padding: 10px 16px; }
  .waiting-for-mail { min-height: 80px; }
  .column { padding: 8px 6px; }
  .teach { font-size: 12px; }
}
@media (max-height: 480px) {
  .column .hint { display: none; }
}
