/* ==========================================================================
   EvilWhale - Design Tokens & Visual Language

   Catppuccin Mocha. One accent system, not five: mauve is navigation, focus
   and primary action; green and red mean the two flashcard outcomes and
   nothing else; yellow marks where a card is examined.

   Mocha is dark all the way through, so the reading sheet that used to be an
   off-white page is now Base sitting on Crust. That retires the light surface
   but not the two-surface idea: chrome stays a shade below the sheet it
   carries. The `-inverse` and `-light` suffixes below are historical - they
   name the chrome/sheet pair, not a second colour scheme, because every
   surface in this palette is dark.

   Depth is Crust < Mantle < Base < Surface 0 < Surface 1, and the rule is that
   a thing sits exactly one step above what it rests on.
   ========================================================================== */

:root {
  /* Surfaces */
  --ew-background: #11111b;       /* Crust: the ground the whole app sits on */
  --ew-surface: #1e1e2e;          /* Base: the reading sheet */
  --ew-surface-muted: #313244;    /* Surface 0: blocks raised off the sheet */
  --ew-surface-dark: #181825;     /* Mantle: chrome controls */
  --ew-surface-card: #1e1e2e;     /* Base: cards standing on the chrome */

  /* Text */
  --ew-text: #cdd6f4;             /* Text: headings and labels */
  --ew-text-body: #bac2de;        /* Subtext 1: long-form reading copy */
  --ew-text-muted: #a6adc8;       /* Subtext 0 */
  --ew-text-inverse: #cdd6f4;
  --ew-text-inverse-muted: #a6adc8;

  /* Accent */
  --ew-accent: #cba6f7;                          /* Mauve */
  --ew-accent-subtle: rgba(203, 166, 247, 0.16);
  --ew-accent-ink: #11111b;                      /* what goes on top of a filled accent */
  /* Exam anchor - the yellow chip that says where a card is examined */
  --ew-exam: #f9e2af;
  /* The mascot - the whale in the home tank and on the wallpaper is drawn in
     the icon's colours (icons/icon.png), not the accent. Mocha names. */
  --ew-whale: #89b4fa;            /* Blue: body, flukes, fins, spout */
  --ew-whale-shade: #6583b7;      /* Blue 70% over Crust: underside, fin */
  --ew-whale-shine: #abc5f7;      /* Blue 50% over Text: the light on top */
  --ew-whale-pleat: #74c7ec;      /* Sapphire: belly pleats, lines on the notes */
  --ew-whale-blush: #b4befe;      /* Lavender: the cheek */
  --ew-whale-mouth: #eba0ac;      /* Maroon: inside the open mouth */
  --ew-whale-ink: #11111b;        /* Crust: outline, eyes and brows */
  /* The streak flame on home - the only fire in the app. */
  --ew-fire: #fab387;             /* Peach: its edge */
  --ew-fire-core: #f9e2af;        /* Yellow: its core */

  /* Learning outcomes - Anki's four answers on a card in the tank, used nowhere
     else. Filled rather than tinted: Crust on Green/Red/Sky clears AA by a wide
     margin where a tinted pill on Base would not. Hard is neutral, as Anki
     draws it. */
  --ew-got-it-bg: #a6e3a1;
  --ew-got-it-text: #11111b;
  --ew-got-it-border: #a6e3a1;
  --ew-again-bg: #f38ba8;
  --ew-again-text: #11111b;
  --ew-again-border: #f38ba8;
  --ew-hard-bg: #45475a;          /* Surface 1 */
  --ew-hard-text: #cdd6f4;
  --ew-hard-border: #585b70;
  --ew-easy-bg: #89dceb;          /* Sky */
  --ew-easy-text: #11111b;
  --ew-easy-border: #89dceb;

  /* Lines */
  --ew-border: #45475a;           /* Surface 1 */
  --ew-border-subtle: #313244;    /* Surface 0 */
  --ew-border-light: #45475a;     /* Surface 1: dividers on the reading sheet */
  --ew-edge: #585b70;             /* Surface 2: quiet lines - the wallpaper's grid and floor */

  --ew-radius-sm: 8px;
  --ew-radius-md: 12px;
  --ew-radius: 14px;
  --ew-radius-lg: 18px;
  --ew-radius-full: 9999px;

  /* Layout metrics. */
  --ew-safe-bottom: env(safe-area-inset-bottom, 0px);
  --ew-safe-top: env(safe-area-inset-top, 0px);
  --ew-gutter: 16px;
  --ew-tap: 48px;               /* minimum touch target, per WCAG 2.5.8 / Android */

  --ew-font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --ew-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* ==========================================================================
   EvilWhale - App shell, the source sheet and the import sheets

   Mobile first: the base rules are the phone layout, and the one media query
   at the bottom widens it for a desktop window. Every interactive control is
   at least --ew-tap in both directions, and every selected state is carried by
   something other than colour as well. Home has its own sheet, css/home.css.
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  min-height: 100dvh;
  background-color: var(--ew-background);
  color: var(--ew-text-inverse);
  font-family: var(--ew-font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

#app-container {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background-color: var(--ew-background);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   1. BOTTOM SHEETS
   ========================================================================== */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.6);
}

.bottom-sheet {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  /* Deliberately short of the fold, so the card it describes stays in view. */
  max-height: 66dvh;
  padding: 8px var(--ew-gutter) calc(var(--ew-gutter) + var(--ew-safe-bottom));
  background: var(--ew-surface);
  color: var(--ew-text);
  border-radius: var(--ew-radius-lg) var(--ew-radius-lg) 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.55);
}

.bottom-sheet.sheet-evidence {
  z-index: 120;
}

.sheet-grabber {
  width: 40px;
  height: 4px;
  margin: 4px auto 10px;
  border-radius: var(--ew-radius-full);
  background: var(--ew-border-light);
}

.sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--ew-border-light);
}

.sheet-heading {
  min-width: 0;
}

.sheet-subtitle {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ew-accent);
  margin-bottom: 2px;
}

.sheet-title {
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1.3;
}

.sheet-close {
  flex: none;
  width: var(--ew-tap);
  height: var(--ew-tap);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ew-surface-muted);
  border: 1px solid var(--ew-border-light);
  border-radius: var(--ew-radius-full);
  color: var(--ew-text-muted);
  font-size: 1rem;
  cursor: pointer;
}

.sheet-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 0;
}

.sheet-note {
  font-size: 0.9rem;
  color: var(--ew-text-muted);
}

.evidence-snippet {
  background: var(--ew-surface-muted);
  border-left: 4px solid var(--ew-accent);
  padding: 14px;
  margin-bottom: 14px;
  border-radius: 0 var(--ew-radius-sm) var(--ew-radius-sm) 0;
  font-size: 1rem;
  line-height: 1.55;
  color: var(--ew-text-body);
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--ew-border-light);
}

.btn-sheet-action {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--ew-tap);
  padding: 10px 14px;
  border: 1px solid var(--ew-border-light);
  border-radius: var(--ew-radius-md);
  background: var(--ew-surface-muted);
  color: var(--ew-accent);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

/* ==========================================================================
   2. IMPORT SHEET
   ========================================================================== */

/* A native select, as the import sheet's format and language pickers use it. */
.scope-select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-width: 0;
  min-height: var(--ew-tap);
  padding: 0 30px 0 12px;
  background-color: var(--ew-surface-dark);
  background-image: linear-gradient(45deg, transparent 50%, var(--ew-text-inverse-muted) 50%),
                    linear-gradient(135deg, var(--ew-text-inverse-muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) calc(50% + 2px), calc(100% - 11px) calc(50% + 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  border: 1px solid var(--ew-border);
  border-radius: var(--ew-radius-md);
  color: var(--ew-text-inverse);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  text-overflow: ellipsis;
}
.scope-select:focus-visible {
  outline: 2px solid var(--ew-accent);
  outline-offset: 2px;
}

/* The import form needs the room the evidence sheet deliberately leaves. */
.bottom-sheet.sheet-import {
  z-index: 110;
  max-height: 92dvh;
}

.import-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.import-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.import-label {
  padding: 0;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ew-text-muted);
}

.import-file,
.import-text,
.import-input {
  width: 100%;
  min-height: var(--ew-tap);
  padding: 10px 12px;
  border: 1px solid var(--ew-border);
  border-radius: var(--ew-radius-md);
  background: var(--ew-surface-dark);
  color: var(--ew-text);
  font: inherit;
}

.import-text {
  resize: vertical;
  font-family: var(--ew-font-mono);
  font-size: 0.85rem;
}

.import-file::file-selector-button {
  min-height: 28px;
  margin-right: 10px;
  border: 1px solid var(--ew-border-light);
  border-radius: var(--ew-radius-sm);
  background: var(--ew-surface-muted);
  color: var(--ew-accent);
  font: inherit;
  font-weight: 700;
}

.import-choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
}

/* The real input covers its whole 48 dp label, invisible; the span draws it. */
.import-choice {
  position: relative;
  display: flex;
  min-height: var(--ew-tap);
  cursor: pointer;
}

.import-choice input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.import-choice span {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--ew-tap);
  padding: 8px 12px;
  border: 1px solid var(--ew-border);
  border-radius: var(--ew-radius-md);
  background: var(--ew-surface-dark);
  color: var(--ew-text);
}

.import-choice input:checked + span {
  border-color: var(--ew-accent);
  box-shadow: inset 0 0 0 1px var(--ew-accent);
  color: var(--ew-accent);
  font-weight: 700;
}

.import-choice input:focus-visible + span,
.import-file:focus-visible,
.import-text:focus-visible,
.import-input:focus-visible {
  outline: 2px solid var(--ew-accent);
  outline-offset: 2px;
}

.import-toggle span::before {
  content: '';
  flex: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--ew-border-light);
  border-radius: 4px;
}

.import-toggle input:checked + span {
  box-shadow: none;
  border-color: var(--ew-border);
}

.import-toggle input:checked + span::before {
  border-color: var(--ew-accent);
  background: var(--ew-accent);
}

.import-preview-meta {
  margin-bottom: 8px;
  font-size: 0.82rem;
  color: var(--ew-text-muted);
}

.import-card {
  padding: 12px 14px;
  border-left: 4px solid var(--ew-accent);
  border-radius: 0 var(--ew-radius-sm) var(--ew-radius-sm) 0;
  background: var(--ew-surface-muted);
}

.import-card-label {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ew-text-muted);
}

.import-card-q,
.import-card-a {
  margin-bottom: 8px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  color: var(--ew-text-body);
}

.import-card-q {
  font-weight: 700;
  color: var(--ew-text);
}

.import-card-a { margin-bottom: 0; }

.import-error {
  color: var(--ew-again-bg);
  font-weight: 700;
}

/* Flex display would otherwise outrank the hidden attribute. */
.import-field[hidden],
.import-toggle[hidden] { display: none; }

.btn-import-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Find flashcards: the one outside source, AnkiWeb, as a card. */
.anki-source {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--ew-border);
  border-radius: var(--ew-radius-md);
  background: var(--ew-surface-dark);
}

.anki-source .sheet-note { margin: 0; }

.anki-source-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ew-text);
}

/* With nothing typed the link has no address: it looks and acts disabled. */
.anki-search-link[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

.anki-url { overflow-wrap: anywhere; }

/* ==========================================================================
   3. WIDE VIEWPORTS
   ========================================================================== */

@media (min-width: 841px) {
  .sheet-backdrop {
    background: rgba(0, 0, 0, 0.45);
  }

  .bottom-sheet {
    inset: 0 0 0 auto;
    width: 420px;
    max-height: none;
    border-radius: 0;
    padding: 24px;
  }

  .sheet-grabber {
    display: none;
  }
}

/* ==========================================================================
   EvilWhale - Home: the whale's tank, and nothing else

   Home fills the screen with the tank. On it: the whale, pixel art drawn on
   the device (src/components/home/pixel-whale.js) in the icon's colours
   (--ew-whale-*); the flashcards that drift in, as pixel notes; and two
   buttons, Flashcards and Settings, whose sheets hold everything else. There
   is no app header on home.

   The pixels stay square but the motion is smooth: the whale swims, banks and
   turns with eased transforms, and its tail sweeps through many frames. The
   monospace register carries every machine readout; mauve stays the accent.
   ========================================================================== */

/* Home owns the whole screen: no header above it, no padding around it. */
#main-root.is-home {
  max-width: none;
  padding: 0;
}

.home {
  position: relative;
  height: 100dvh;
  overflow: hidden;
}

/* ---- the tank ----------------------------------------------------------- */

.pet-tank {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(137, 180, 250, 0.14), transparent 60%),
    radial-gradient(circle at 1px 1px, rgba(88, 91, 112, 0.42) 1px, transparent 1.5px) 0 0 / 18px 18px,
    linear-gradient(180deg, var(--ew-surface-dark) 0%, var(--ew-background) 100%);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: crosshair;
}

/* Slow light through the water. */
.pet-tank::before {
  content: '';
  position: absolute;
  inset: -10% -40%;
  background: repeating-linear-gradient(105deg,
    transparent 0 70px, rgba(137, 180, 250, 0.035) 70px 110px, transparent 110px 200px);
  pointer-events: none;
  animation: tank-light 16s ease-in-out infinite alternate;
}

@keyframes tank-light {
  from { transform: translateX(-50px); }
  to { transform: translateX(50px); }
}

/* The floor the whale sleeps on, above the buttons. */
.pet-tank::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(88px + var(--ew-safe-bottom));
  height: 1px;
  background: repeating-linear-gradient(90deg, var(--ew-border) 0 6px, transparent 6px 12px);
  pointer-events: none;
}

/* ---- the scenery (tank-decor.js) ----------------------------------------
   Behind the whale and blind to the pointer: fish far off in a muted tint,
   seaweed swaying on the bottom behind the buttons, junk drifting nearer.
   Crossings are Web Animations; only the bob, the tumble and the sway are CSS. */

.tank-decor {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.tank-decor [data-decor] {
  position: absolute;
  inset: 0;
}

.tank-decor [data-decor][hidden] { display: none; }

.tank-decor-pixels {
  display: block;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

.tank-drift {
  position: absolute;
  left: 0;
  width: 100%;
  height: 0;
  will-change: transform;
}

.tank-drift-bob {
  width: max-content;
  animation: tank-bob 3.4s ease-in-out infinite alternate;
}

.tank-drift-fish .tank-drift-bob { animation-duration: 1.3s; }

@keyframes tank-bob {
  from { transform: translateY(calc(var(--bob, 6px) * -1)) rotate(calc(var(--spin, 0deg) * -1)); }
  to { transform: translateY(var(--bob, 6px)) rotate(var(--spin, 0deg)); }
}

/* Far off: dim, so the fish read as depth rather than company. */
.tank-decor-fish { opacity: 0.55; }

.tank-decor-junk { opacity: 0.9; }

/* Planted on the floor line (.pet-tank::after), where the buttons do not hide it. */
.tank-weed {
  position: absolute;
  bottom: calc(88px + var(--ew-safe-bottom));
  margin-left: -10px;
  transform-origin: 50% 100%;
  animation: tank-weed 5s ease-in-out infinite alternate;
}

@keyframes tank-weed {
  from { transform: skewX(-6deg); }
  to { transform: skewX(6deg); }
}

.pet-whale {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  width: 104px;
  height: 108px;
  transform-origin: 50% 55%;
  will-change: transform;
}

/* Turning round is driven frame by frame (turnScale in whale-motion.js): it
   narrows side-on and swaps over, never vanishing, so no transition here. */
.pet-whale-flip {
  width: 100%;
  height: 100%;
}

/* The sprite is 104 x 108 real pixels, one CSS pixel each: never smoothed. */
.whale-pixels {
  display: block;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  transform-origin: 50% 60%;
  filter: drop-shadow(0 0 8px rgba(137, 180, 250, 0.24));
}

.whale-zzz {
  position: absolute;
  top: -6px;
  right: 4px;
  font-family: var(--ew-font-mono);
  font-size: 12px;
  color: var(--ew-text-muted);
  opacity: 0;
  pointer-events: none;
}

@keyframes whale-zzz {
  0% { opacity: 0; transform: translate(0, 6px); }
  40% { opacity: 1; }
  100% { opacity: 0; transform: translate(8px, -10px); }
}

/* Moods: the frames and the swimming carry them; CSS adds the z and a fade. */
.pet-tank[data-mood="starving"] .whale-pixels { filter: saturate(0.35); }
.pet-tank[data-mood="asleep"] .whale-zzz { animation: whale-zzz 2.8s ease-in-out infinite; }

.pet-whale.is-poked .whale-pixels { animation: whale-poke 0.6s cubic-bezier(0.3, 1.6, 0.5, 1); }
.pet-whale.is-bite .whale-pixels { animation: whale-bite 0.24s ease-out; }
.pet-whale[data-happy] .whale-pixels { animation: whale-hop 0.55s ease-in-out infinite; }
.pet-whale.is-gulp .whale-pixels { animation: whale-gulp 0.45s ease-in-out; }

/* The last bite goes down: a swallow that swells the throat and settles. */
@keyframes whale-gulp {
  0%, 100% { transform: none; }
  35% { transform: scale(0.95, 1.07); }
  70% { transform: scale(1.05, 0.96); }
}

@keyframes whale-poke {
  0%, 100% { transform: none; }
  25% { transform: rotate(-9deg) scale(1.08); }
  60% { transform: rotate(5deg) scale(0.98); }
}

@keyframes whale-bite {
  0%, 100% { transform: none; }
  40% { transform: scale(1.1, 0.92); }
}

@keyframes whale-hop {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  45% { transform: translateY(-8px) scale(0.97, 1.04); }
  80% { transform: translateY(1px) scale(1.04, 0.96); }
}

/* The study streak, top right: a pixel flame and the day count. It flickers
   while the streak is alive and goes grey and still at zero. */
.pet-streak {
  position: absolute;
  top: calc(12px + var(--ew-safe-top));
  right: 14px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 8px;
  background: rgba(17, 17, 27, 0.72);
  box-shadow: 0 0 0 2px var(--ew-border);
  pointer-events: none;
}

.pet-streak[data-lit="true"] { box-shadow: 0 0 0 2px var(--ew-fire); }

/* One 3px cell, repeated: Peach edge, Yellow core, 6 x 9 cells. */
.pet-streak-fire {
  position: relative;
  flex: none;
  width: 18px;
  height: 27px;
}

.pet-streak-fire::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 3px;
  height: 3px;
  --a: var(--ew-fire);
  --b: var(--ew-fire-core);
  box-shadow:
    9px 0 var(--a),
    6px 3px var(--a), 9px 3px var(--a),
    6px 6px var(--a), 9px 6px var(--b), 12px 6px var(--a),
    3px 9px var(--a), 6px 9px var(--b), 9px 9px var(--b), 12px 9px var(--a),
    3px 12px var(--a), 6px 12px var(--b), 9px 12px var(--b), 12px 12px var(--b), 15px 12px var(--a),
    0 15px var(--a), 3px 15px var(--b), 6px 15px var(--b), 9px 15px var(--b), 12px 15px var(--b), 15px 15px var(--a),
    0 18px var(--a), 3px 18px var(--b), 6px 18px var(--b), 9px 18px var(--b), 12px 18px var(--b), 15px 18px var(--a),
    3px 21px var(--a), 6px 21px var(--b), 9px 21px var(--b), 12px 21px var(--b), 15px 21px var(--a),
    6px 24px var(--a), 9px 24px var(--a), 12px 24px var(--a);
  transform-origin: 9px 27px;
}

.pet-streak[data-lit="true"] .pet-streak-fire::before {
  animation: pet-streak-flicker 0.9s steps(1) infinite;
}

.pet-streak[data-lit="false"] .pet-streak-fire {
  filter: grayscale(1) brightness(0.6);
}

@keyframes pet-streak-flicker {
  0% { transform: none; }
  33% { transform: translateX(-1px) scaleY(1.08); }
  66% { transform: translateX(1px) scaleY(0.94); }
}

.pet-streak-count {
  font-family: var(--ew-font-mono);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  color: var(--ew-text);
}

.pet-streak[data-lit="false"] .pet-streak-count { color: var(--ew-text-muted); }

/* What the whale says, in a pixel speech bubble that follows it. */
.pet-says {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  width: max-content;
  max-width: min(260px, 70vw);
  padding: 6px 10px;
  background: var(--ew-text);
  color: var(--ew-whale-ink);
  font-family: var(--ew-font-mono);
  font-size: 0.8rem;
  line-height: 1.35;
  box-shadow: 0 0 0 2px var(--ew-whale-ink), 0 0 0 4px var(--ew-accent);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.pet-says.is-showing { opacity: 1; }

.pet-says::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 6px;
  height: 6px;
  margin-left: -3px;
  background: var(--ew-text);
}

/* ---- food, bubbles, hearts, crumbs --------------------------------------- */

.pet-food {
  position: absolute;
  z-index: 1;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  background: var(--ew-accent);
  box-shadow: 0 0 8px var(--ew-accent);
  pointer-events: none;
  animation: pet-food 1.2s ease-in-out infinite;
}

@keyframes pet-food {
  0%, 100% { transform: translateY(0) rotate(0); }
  50% { transform: translateY(3px) rotate(45deg); }
}

/* A finished flashcard: a pixel note that loses a chunk at every bite. */
.pet-food-card {
  width: 22px;
  height: 26px;
  margin: -13px 0 0 -11px;
  background: repeating-linear-gradient(180deg, var(--ew-text) 0 5px, var(--ew-whale-pleat) 5px 6px);
  box-shadow: none;
  outline: 2px solid var(--ew-accent);
  animation: pet-food-sway 1.6s ease-in-out infinite;
}

.pet-food-card[data-bites="2"] {
  clip-path: polygon(0 0, 52% 0, 60% 14%, 72% 8%, 80% 24%, 100% 22%, 100% 100%, 0 100%);
}

.pet-food-card[data-bites="1"] {
  clip-path: polygon(0 0, 26% 0, 34% 18%, 48% 10%, 56% 34%, 70% 28%, 78% 52%, 100% 50%, 100% 100%, 0 100%);
}

@keyframes pet-food-sway {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50% { transform: translateY(4px) rotate(5deg); }
}

.pet-crumb {
  position: absolute;
  z-index: 2;
  width: 4px;
  height: 4px;
  margin: -2px;
  background: var(--ew-text);
  pointer-events: none;
  animation: pet-crumb 0.9s ease-in forwards;
}

@keyframes pet-crumb {
  0% { opacity: 1; transform: translate(0, 0) rotate(0); }
  100% { opacity: 0; transform: translate(var(--dx, 0px), 64px) rotate(90deg); }
}

.pet-bubble {
  position: absolute;
  width: 6px;
  height: 6px;
  margin: -3px;
  border: 1px solid var(--ew-text-muted);
  border-radius: 50%;
  pointer-events: none;
  animation: pet-bubble 2.4s ease-out forwards;
}

@keyframes pet-bubble {
  0% { opacity: 0.8; transform: translate(0, 0) scale(0.6); }
  50% { transform: translate(-4px, -36px) scale(0.9); }
  100% { opacity: 0; transform: translate(6px, -80px) scale(1.2); }
}

/* A pixel heart: one 2px cell, repeated by box-shadow. */
.pet-heart {
  position: absolute;
  z-index: 2;
  width: 2px;
  height: 2px;
  color: var(--ew-whale-mouth);
  box-shadow:
    2px 0, 6px 0,
    0 2px, 2px 2px, 4px 2px, 6px 2px, 8px 2px,
    2px 4px, 4px 4px, 6px 4px,
    4px 6px;
  pointer-events: none;
  animation: pet-heart 1.6s ease-out forwards;
}

@keyframes pet-heart {
  0% { opacity: 1; transform: translate(0, 0) scale(1.5); }
  100% { opacity: 0; transform: translate(6px, -52px) scale(1.5); }
}

/* ---- flashcards in the water ------------------------------------------- */

.tank-card {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  width: var(--ew-tap);
  height: var(--ew-tap);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  animation: tank-card-float 2.8s ease-in-out infinite alternate;
}

.tank-card-note {
  position: relative;
  display: grid;
  place-items: center;
  width: 26px;
  height: 32px;
  background:
    repeating-linear-gradient(180deg, transparent 0 6px, var(--ew-whale-pleat) 6px 8px) 4px 4px / 18px 24px no-repeat,
    var(--ew-text);
  box-shadow: 0 0 0 2px var(--ew-whale-ink), 0 0 0 4px var(--ew-accent);
}

/* The spiral holes down the edge, as in the icon's notes. */
.tank-card-note::before {
  content: '';
  position: absolute;
  top: 4px;
  left: -2px;
  width: 4px;
  height: 4px;
  background: var(--ew-whale-ink);
  box-shadow: 0 10px var(--ew-whale-ink), 0 20px var(--ew-whale-ink);
}

.tank-card-mark {
  padding: 0 2px;
  background: var(--ew-text);
  font-family: var(--ew-font-mono);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  color: var(--ew-whale-ink);
}

.tank-card:focus-visible {
  outline: 2px solid var(--ew-accent);
  outline-offset: 2px;
}

@keyframes tank-card-float {
  from { transform: translateY(0) rotate(-6deg); }
  to { transform: translateY(-8px) rotate(6deg); }
}

/* A card being answered, over the water and clear of the buttons. */
.tank-quiz {
  position: absolute;
  top: 16px;
  bottom: calc(92px + var(--ew-safe-bottom));
  left: 0;
  right: 0;
  z-index: 3;
  width: min(480px, calc(100% - 32px));
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px 12px;
  overflow-y: auto;
  border-radius: var(--ew-radius-md);
  background: var(--ew-surface);
  box-shadow: 0 0 0 2px var(--ew-accent), 0 10px 30px rgba(0, 0, 0, 0.5);
  cursor: auto;
  touch-action: pan-y;
}

.tank-quiz-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tank-quiz-chips {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

.tank-quiz-chip {
  padding: 3px 9px;
  border-radius: var(--ew-radius-full);
  border: 1px solid var(--ew-border);
  background: var(--ew-surface-dark);
  color: var(--ew-text-muted);
  font-size: 0.75rem;
  font-weight: 600;
}

/* Where the card is examined - the reason it is in the deck at all. */
.tank-quiz-chip-exam {
  border-color: var(--ew-exam);
  color: var(--ew-exam);
  white-space: nowrap;
}

/* The passage behind the card, opened in the source sheet over the tank. */
.tank-quiz-source {
  min-height: var(--ew-tap);
  padding: 8px 12px;
  border: 1px solid var(--ew-border);
  border-radius: var(--ew-radius-sm);
  background: var(--ew-surface-muted);
  color: var(--ew-text);
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
}

.tank-quiz-label {
  font-family: var(--ew-font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ew-text-muted);
}

.tank-quiz-close,
.home-sheet-close {
  min-width: var(--ew-tap);
  min-height: var(--ew-tap);
  border: 0;
  background: transparent;
  color: var(--ew-text);
  font-size: 1.4rem;
  cursor: pointer;
}

.tank-quiz-q {
  font-weight: 600;
  line-height: 1.4;
  color: var(--ew-text);
}

.tank-quiz-a {
  line-height: 1.45;
  color: var(--ew-text-body);
}

.tank-quiz-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
}

.tank-quiz-actions button {
  flex: 1 1 120px;
  min-height: var(--ew-tap);
  padding: 8px 12px;
  border: 0;
  border-radius: var(--ew-radius-sm);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* Anki's four answers: four across, two by two on a phone. */
.tank-quiz-answers {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 480px) {
  .tank-quiz-answers {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.tank-quiz-answers button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 4px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.tank-quiz-time {
  font-family: var(--ew-font-mono);
  font-size: 0.78rem;
  font-weight: 600;
}

.tank-quiz [data-tank-reveal] { background: var(--ew-accent); color: var(--ew-accent-ink); }
.tank-quiz [data-tank-rate="again"] { background: var(--ew-again-bg); color: var(--ew-again-text); }
.tank-quiz [data-tank-rate="hard"] { background: var(--ew-hard-bg); color: var(--ew-hard-text); }
.tank-quiz [data-tank-rate="good"] { background: var(--ew-got-it-bg); color: var(--ew-got-it-text); }
.tank-quiz [data-tank-rate="easy"] { background: var(--ew-easy-bg); color: var(--ew-easy-text); }

/* ---- the two buttons ----------------------------------------------------- */

.home-actions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 12px 16px calc(16px + var(--ew-safe-bottom));
  pointer-events: none;
}

.home-action {
  pointer-events: auto;
  flex: 1 1 0;
  max-width: 200px;
  min-height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 14px;
  border: 0;
  background: var(--ew-surface);
  box-shadow: 0 0 0 2px var(--ew-accent), 4px 4px 0 2px var(--ew-whale-ink);
  color: var(--ew-text);
  font-family: var(--ew-font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.2s ease;
}

.home-action:active { transform: translate(2px, 2px); }

.home-action[aria-expanded="true"] {
  background: var(--ew-accent);
  color: var(--ew-accent-ink);
}

.home-action-icon {
  position: relative;
  flex: none;
  width: 12px;
  height: 14px;
}

/* Two stacked cards. */
.home-action-icon-cards {
  border: 2px solid currentColor;
  box-shadow: 4px -4px 0 -2px var(--ew-surface), 4px -4px 0 0 currentColor;
}

.home-action[aria-expanded="true"] .home-action-icon-cards {
  box-shadow: 4px -4px 0 -2px var(--ew-accent), 4px -4px 0 0 currentColor;
}

/* A blocky cog. */
.home-action-icon-settings {
  width: 14px;
  height: 14px;
  border: 3px dotted currentColor;
  border-radius: 50%;
}

/* ---- sheets -------------------------------------------------------------- */

.home-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  width: min(100%, 560px);
  max-height: min(80dvh, 680px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 16px calc(96px + var(--ew-safe-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  border-top: 2px solid var(--ew-accent);
  border-radius: var(--ew-radius-lg) var(--ew-radius-lg) 0 0;
  background: var(--ew-surface);
  box-shadow: 0 -12px 32px rgba(0, 0, 0, 0.45);
  animation: home-sheet-in 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* `display: flex` above would otherwise outrank the hidden attribute. */
.home-sheet[hidden] {
  display: none;
}

@keyframes home-sheet-in {
  from { opacity: 0; transform: translateY(28px); }
  to { opacity: 1; transform: none; }
}

.home-sheet-head {
  position: sticky;
  top: -4px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 4px;
  background: var(--ew-surface);
}

.home-sheet-title {
  font-family: var(--ew-font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ew-text);
}

.home-sheet-title::before {
  content: '// ';
  color: var(--ew-accent);
}

.home-sheet-hint {
  font-size: 0.82rem;
  color: var(--ew-text-muted);
}

/* Flashcards: the courses to train on. */
.home-train {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.home-train-label {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: var(--ew-tap);
  padding-right: 12px;
  border: 1px solid var(--ew-border-subtle);
  border-radius: var(--ew-radius-md);
  background: var(--ew-surface-dark);
  cursor: pointer;
}

.home-train-name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  min-width: 0;
}

.home-train-meta {
  font-size: 0.78rem;
  color: var(--ew-text-muted);
}

/* An imported deck's row carries its remove button beside the tick. */
.home-train > li {
  display: flex;
  gap: 6px;
}

.home-train-label {
  flex: 1 1 auto;
  min-width: 0;
}

.home-train-remove {
  flex: 0 0 var(--ew-tap);
  min-height: var(--ew-tap);
  border: 1px solid var(--ew-border-subtle);
  border-radius: var(--ew-radius-md);
  background: transparent;
  color: var(--ew-text-muted);
  font: inherit;
  font-size: 1.3rem;
  cursor: pointer;
}

.home-import {
  border-color: var(--ew-accent);
  color: var(--ew-accent);
  font-weight: 700;
}

/* A 48x48 touch area around a pixel-style box; the real input fills it,
   invisibly, and the whole row is its label. */
.home-course-pick {
  position: relative;
  flex: 0 0 var(--ew-tap);
  display: grid;
  place-items: center;
  width: var(--ew-tap);
  height: var(--ew-tap);
}

.home-course-pick input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.home-course-check {
  position: relative;
  width: 20px;
  height: 20px;
  background: var(--ew-surface);
  box-shadow: 0 0 0 2px var(--ew-border);
}

.home-course-pick input:checked + .home-course-check {
  background: var(--ew-accent);
  box-shadow: 0 0 0 2px var(--ew-accent);
}

/* The tick, drawn in 2px cells like the rest of the tank's pixel art. */
.home-course-pick input:checked + .home-course-check::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 10px;
  width: 2px;
  height: 2px;
  color: var(--ew-accent-ink);
  background: currentColor;
  box-shadow: 2px 2px, 4px 4px, 6px 2px, 8px 0, 10px -2px, 12px -4px;
}

.home-course-pick input:focus-visible + .home-course-check {
  outline: 2px solid var(--ew-accent);
  outline-offset: 3px;
}

/* Settings: the pet's stats. */
.home-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  font-family: var(--ew-font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ew-text-muted);
}

.home-stats b {
  color: var(--ew-text);
  font-weight: 600;
}

.home-stats-energy {
  flex: 1 1 160px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pet-energy {
  flex: 1 1 auto;
  height: 4px;
  border-radius: var(--ew-radius-full);
  background: var(--ew-surface-muted);
  overflow: hidden;
}

.pet-energy span {
  display: block;
  height: 100%;
  background: var(--ew-accent);
}

.home-label {
  margin-top: 6px;
  font-family: var(--ew-font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ew-text-muted);
}

.home-label::before {
  content: '// ';
  color: var(--ew-accent);
}

.home-courses {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Wraps rather than squeezes: at 200% system text the meta line and even the
   bar drop to their own row instead of pushing the page sideways. */
.home-course {
  width: 100%;
  min-height: var(--ew-tap);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  padding: 10px 14px;
  border: 1px solid var(--ew-border-subtle);
  border-radius: var(--ew-radius-md);
  background: var(--ew-surface-dark);
  color: inherit;
  font: inherit;
  text-align: left;
}

.home-course-code {
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: var(--ew-font-mono);
  font-weight: 700;
  color: var(--ew-text);
}

.home-course-lang {
  padding: 0 4px;
  border: 1px solid var(--ew-border);
  border-radius: 4px;
  font-family: var(--ew-font-mono);
  font-size: 0.7rem;
  color: var(--ew-text-muted);
}

.home-course-bar {
  flex: 1 1 60px;
  display: flex;
  height: 6px;
  overflow: hidden;
  border-radius: var(--ew-radius-full);
  background: var(--ew-surface-muted);
}

.home-course-fill-solid { background: var(--ew-accent); }

.home-course-pct {
  min-width: 4ch;
  font-family: var(--ew-font-mono);
  font-size: 0.85rem;
  text-align: right;
  color: var(--ew-text);
}

.home-course-meta {
  flex-basis: 100%;
  font-size: 0.78rem;
  color: var(--ew-text-muted);
}

.home-wallpaper {
  min-height: var(--ew-tap);
  padding: 10px 14px;
  border: 1px dashed var(--ew-border);
  border-radius: var(--ew-radius-md);
  background: transparent;
  color: var(--ew-text);
  font: inherit;
  cursor: pointer;
}

/* The launcher: the phone's apps, as a quiet monospace list. */
.home-app-search {
  width: 100%;
  min-height: var(--ew-tap);
  padding: 10px 14px;
  border: 1px solid var(--ew-border);
  border-radius: var(--ew-radius-md);
  background: var(--ew-surface-dark);
  color: var(--ew-text);
  font-family: var(--ew-font-mono);
  font-size: 0.9rem;
}

.home-app-search::placeholder { color: var(--ew-text-muted); }

.home-apps {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.home-app {
  width: 100%;
  min-height: var(--ew-tap);
  padding: 8px 12px;
  overflow: hidden;
  border: 1px solid var(--ew-border-subtle);
  border-radius: var(--ew-radius-sm);
  background: transparent;
  color: var(--ew-text-body);
  font-family: var(--ew-font-mono);
  font-size: 0.82rem;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.home-action:focus-visible,
.home-sheet-close:focus-visible,
.tank-quiz button:focus-visible,
.home-app-search:focus-visible,
.home-app:focus-visible,
.home-train-remove:focus-visible,
.home-wallpaper:focus-visible {
  outline: 2px solid var(--ew-accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .pet-tank::before,
  .tank-drift-bob,
  .tank-weed,
  .pet-streak[data-lit="true"] .pet-streak-fire::before,
  .whale-zzz,
  .pet-food,
  .pet-bubble,
  .pet-heart,
  .pet-crumb,
  .tank-card,
  .home-sheet,
  .pet-whale.is-poked .whale-pixels,
  .pet-whale.is-bite .whale-pixels,
  .pet-whale.is-gulp .whale-pixels,
  .pet-whale[data-happy] .whale-pixels {
    animation: none !important;
  }
  .pet-whale-flip,
  .pet-says,
  .home-action { transition: none; }
}

