/* ── Free word counter (/word-counter): the "writing desk" layout ── */
/* Mission cards and the stamp come from missions.css (body.word-counter-page gets its --ms-*
   paper colors, light and dark). */

/* ── Colors: light by default, dark from the theme switch (html.dark-theme) or the system setting ── */
html.wc-html {
  --wc-bg: #f4f8fc; --wc-card: #fff; --wc-card-glass: rgba(255,255,255,0.93);
  --wc-ink: #1a3a5c; --wc-text: #1d2a3a; --wc-text2: #3d5670; --wc-muted: #5a7a9a; --wc-hand: #2e64b5;
  --wc-line: #e3edf7; --wc-hover: #eaf2fa; --wc-accent: #2a6cb8; --wc-focus: #8bb8d8;
  --wc-placeholder: #8bb0d0; --wc-input-line: #c9dcee; --wc-good: #3f8a43; --wc-warn: #b45309;
  --wc-btn: #1a3a5c; --wc-btn-hover: #24507d; --wc-btn-ink: #fff; --wc-deck: #1a3a5c;
  --wc-notice-bg: #fff7ed; --wc-notice-ink: #7c2d12;
  --wc-sky: linear-gradient(180deg, #f4f8fc 0%, #daedf9 50%, #f4f8fc 100%); --wc-cloud-opacity: 0.25;
}
html.wc-html.dark-theme {
  --wc-bg: #0c1929; --wc-card: #132d47; --wc-card-glass: rgba(19,45,71,0.93);
  --wc-ink: #e0eaf4; --wc-text: #d5e2ef; --wc-text2: #a9c1d8; --wc-muted: #8badc8; --wc-hand: #7aa8f2;
  --wc-line: #1e3a55; --wc-hover: #1a3a55; --wc-accent: #7aa8f2; --wc-focus: #4a7fb0;
  --wc-placeholder: #5f7f9e; --wc-input-line: #2a4a6a; --wc-good: #7fd083; --wc-warn: #e8a24a;
  --wc-btn: #e0eaf4; --wc-btn-hover: #ffffff; --wc-btn-ink: #0c1929; --wc-deck: #2a5a8c;
  --wc-notice-bg: rgba(232,162,74,0.12); --wc-notice-ink: #f3c48a;
  --wc-sky: linear-gradient(180deg, #0c1929 0%, #162d4a 50%, #0c1929 100%); --wc-cloud-opacity: 0;
}
html.wc-html, html.wc-html body.word-counter-page { background: var(--wc-bg); }
/* Watercolor in light mode, flat in dark, like the profile's nature scenes */
html.wc-html.dark-theme .wc-goal-art g { filter: none; }
html.wc-html.dark-theme .wc-credit { display: none; }
/* The same in dark for System, as a fallback for the head script's dark-theme class */
@media (prefers-color-scheme: dark) {
  html.wc-html:not(.light-theme) {
    --wc-bg: #0c1929; --wc-card: #132d47; --wc-card-glass: rgba(19,45,71,0.93);
    --wc-ink: #e0eaf4; --wc-text: #d5e2ef; --wc-text2: #a9c1d8; --wc-muted: #8badc8; --wc-hand: #7aa8f2;
    --wc-line: #1e3a55; --wc-hover: #1a3a55; --wc-accent: #7aa8f2; --wc-focus: #4a7fb0;
    --wc-placeholder: #5f7f9e; --wc-input-line: #2a4a6a; --wc-good: #7fd083; --wc-warn: #e8a24a;
    --wc-btn: #e0eaf4; --wc-btn-hover: #ffffff; --wc-btn-ink: #0c1929; --wc-deck: #2a5a8c;
    --wc-notice-bg: rgba(232,162,74,0.12); --wc-notice-ink: #f3c48a;
    --wc-sky: linear-gradient(180deg, #0c1929 0%, #162d4a 50%, #0c1929 100%); --wc-cloud-opacity: 0;
  }
  html.wc-html:not(.light-theme) .wc-goal-art g { filter: none; }
  html.wc-html:not(.light-theme) .wc-credit { display: none; }
}

body.word-counter-page { color: var(--wc-ink); }
/* redesign-shared.css hides horizontal overflow on body, which makes body a scroll
   container and stops the side panel from sticking. clip hides it without that. */
html.redesign body.word-counter-page { overflow-x: clip; }

/* The panels below set display, which would otherwise beat the hidden attribute */
.wc-page [hidden], .wc-corner[hidden], .wc-corner [hidden] { display: none !important; }
.wc-visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Buttons and links */
.wc-link-btn {
  border: 0; background: none; padding: 0.3rem 0; min-height: 32px; cursor: pointer;
  font: 600 0.88rem 'Inter', sans-serif; color: var(--wc-accent); text-decoration: underline; text-underline-offset: 3px;
}
.wc-pill-btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0.55rem 1.3rem;
  box-sizing: border-box; text-align: center; line-height: 1.25; border-radius: 25px; font: 600 0.95rem 'Inter', sans-serif; cursor: pointer; text-decoration: none;
  transition: background 0.2s, filter 0.2s;
}
.wc-pill-btn-dark { border: 0; background: var(--wc-btn); color: var(--wc-btn-ink); }
.wc-pill-btn-dark:hover { background: var(--wc-btn-hover); color: var(--wc-btn-ink); }
.wc-pill-btn-outline { border: 1.5px solid var(--wc-ink); background: transparent; color: var(--wc-ink); }
.wc-pill-btn-outline:hover { background: var(--wc-hover); }
.wc-pill-btn:disabled { opacity: 0.45; cursor: default; }
.wc-pill-btn-dark:disabled:hover { background: var(--wc-btn); }
.wc-wide { width: 100%; box-sizing: border-box; }
.wc-link-btn:focus-visible, .wc-pill-btn:focus-visible, .wc-tool:focus-visible,
.wc-mission-strip:focus-visible, .wc-corner:focus-visible {
  outline: 3px solid var(--wc-focus); outline-offset: 3px;
}

/* ── The sky band and the counts ── */
/* Jessica's cloud painting, muted as on the register page (.rd-page--clouds), behind the
   whole page. Fixed layers instead of background-attachment: fixed, which iOS ignores. */
.wc-page { position: relative; isolation: isolate; }
.wc-page::before, .wc-page::after {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
}
.wc-page::before { background: var(--wc-sky); }
.wc-page::after { background: url('../images/clouds.png') no-repeat center center / cover; opacity: var(--wc-cloud-opacity); }
/* The page is positioned, so its fixed cloud layers would paint over the plain footer below it */
body.word-counter-page .rd-footer { position: relative; z-index: 1; }
.wc-sky { position: relative; padding: 104px 1.25rem 1.5rem; }
.wc-credit { margin: 0 1.25rem 1rem; text-align: center; font-size: 0.75rem; font-style: italic; color: var(--wc-muted); }
.wc-status {
  position: relative; max-width: 1180px; margin: 0 auto; box-sizing: border-box;
  display: flex; flex-wrap: wrap; align-items: stretch;
  background: var(--wc-card); border-radius: 14px; box-shadow: 0 10px 30px rgba(0,80,160,0.10); padding: 0 1.5rem;
}
.wc-count {
  display: flex; flex-direction: column; justify-content: center; gap: 0.1rem;
  padding: 0.9rem 1.75rem 0.9rem 0; margin-right: 1.75rem; border-right: 1px solid var(--wc-line);
}
.wc-count-label { font-size: 0.75rem; font-weight: 500; color: var(--wc-muted); }
.wc-count-value { font: 800 1.85rem/1.1 'Playfair Display', serif; color: var(--wc-ink); font-variant-numeric: tabular-nums; }

.wc-goal { flex: 1 1 260px; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; padding: 0.7rem 0; min-width: 0; }
.wc-goal > form, .wc-goal > .wc-goal-show { flex: 1 1 200px; min-width: 0; }
.wc-goal-art { flex: none; width: 72px; height: 48px; overflow: visible; }
.wc-goal-btn { min-height: 44px; }
.wc-goal-form { display: flex; flex-direction: column; gap: 0.3rem; }
.wc-goal-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.wc-goal-input {
  width: 8.5rem; min-height: 40px; box-sizing: border-box; padding: 0 0.8rem;
  border: 1.5px solid var(--wc-input-line); border-radius: 10px; font: 500 1rem 'Inter', sans-serif; color: var(--wc-ink);
}
.wc-goal-input:focus { outline: none; border-color: var(--wc-accent); }
.wc-goal-row .wc-pill-btn { min-height: 40px; padding: 0 1rem; }
.wc-goal-show { display: flex; flex-direction: column; gap: 0.35rem; }
.wc-goal-head { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.8rem; }
.wc-goal-text { font-weight: 600; color: var(--wc-ink); font-variant-numeric: tabular-nums; }
.wc-goal-actions { display: flex; gap: 1rem; }
.wc-goal-actions .wc-link-btn { min-height: 28px; font-size: 0.8rem; }

.wc-bar { height: 8px; border-radius: 4px; background: var(--wc-line); overflow: hidden; }
.wc-bar span { display: block; height: 100%; width: 0; background: var(--wc-accent); transition: width 0.3s ease; }
.wc-bar.is-done span { background: var(--wc-good); }

/* ── The desk: text on the left, the mission on the right ── */
.wc-desk {
  max-width: 1180px; margin: 0 auto; padding: 0.5rem 1.25rem 1.5rem; box-sizing: border-box;
  display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: flex-start;
}
.wc-editor {
  flex: 999 1 560px; min-width: 0; background: var(--wc-card); border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,80,160,0.08); display: flex; flex-direction: column;
}
.wc-toolbar { display: flex; align-items: center; gap: 0.25rem; padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--wc-line); flex-wrap: wrap; }
.wc-tool {
  min-height: 36px; padding: 0 0.9rem; border: 0; border-radius: 18px; background: transparent;
  font: 500 0.82rem 'Inter', sans-serif; color: var(--wc-ink); cursor: pointer;
}
.wc-tool:hover { background: var(--wc-hover); }
.wc-toolbar-note { margin-left: auto; font-size: 0.78rem; color: var(--wc-muted); }
/* Grows with the text, so the page scrolls and the counts tuck into the corner. The
   space at the end keeps the line being typed clear of the corner pill. */
.wc-text {
  display: block; width: 100%; box-sizing: border-box; min-height: 480px; resize: none; overflow: hidden;
  padding: 2rem 3.2rem 5.5rem; border: 0; border-radius: 0 0 14px 14px; background: transparent;
  font: 400 1.1rem/1.8 'Inter', sans-serif; color: var(--wc-text);
}
.wc-text:focus { outline: none; }
.wc-editor:focus-within { box-shadow: 0 0 0 2px var(--wc-focus), 0 10px 30px rgba(0,80,160,0.08); }
.wc-text::placeholder { color: var(--wc-placeholder); }

/* The side panel stays in view while writing */
.wc-side {
  flex: 1 1 300px; max-width: 340px; position: sticky; top: 96px;
  display: flex; flex-direction: column; gap: 0.9rem;
}

.wc-draw { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; text-align: center; }
.wc-status-text { min-height: 1.2em; margin: 0; font-size: 0.85rem; color: var(--wc-muted); }
.wc-status-text a { color: var(--wc-accent); font-weight: 600; }
/* ── The deck: three face-down cards, fanned, with one plain label ── */
.wc-deck-btn {
  display: flex; flex-direction: column; align-items: center; gap: 0.9rem; padding: 1rem 1.5rem 0.75rem;
  border: 0; border-radius: 14px; background: none; cursor: pointer; color: var(--wc-ink);
}
.wc-deck { position: relative; display: block; width: 150px; height: 112px; }
.wc-deck-card {
  position: absolute; left: 50%; bottom: 0; width: 70px; height: 100px; margin-left: -35px; box-sizing: border-box;
  border-radius: 8px; background: var(--wc-deck); border: 3px solid var(--wc-card); box-shadow: 0 8px 20px rgba(0,80,160,0.18);
  transform-origin: 50% 120%; transition: transform 0.25s ease;
}
/* A thin inner frame and a small star, like the back of a playing card */
.wc-deck-card::after {
  content: '★'; position: absolute; inset: 5px; display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(255,255,255,0.35); border-radius: 4px; color: rgba(255,255,255,0.75); font-size: 1rem;
}
.wc-deck-card:nth-child(1) { transform: rotate(-14deg); }
.wc-deck-card:nth-child(3) { transform: rotate(14deg); }
.wc-deck-btn:hover .wc-deck-card:nth-child(1), .wc-deck-btn:focus-visible .wc-deck-card:nth-child(1) { transform: rotate(-20deg); }
.wc-deck-btn:hover .wc-deck-card:nth-child(3), .wc-deck-btn:focus-visible .wc-deck-card:nth-child(3) { transform: rotate(20deg); }
.wc-deck-label { font: 600 1rem 'Inter', sans-serif; text-decoration: underline; text-decoration-color: var(--wc-focus); text-underline-offset: 5px; text-decoration-thickness: 2px; }
.wc-deck-btn:hover .wc-deck-label { text-decoration-color: var(--wc-ink); }
.wc-deck-btn:focus-visible { outline: 3px solid var(--wc-focus); outline-offset: 2px; }
.wc-deck-btn:disabled { cursor: default; opacity: 0.6; }
@media (prefers-reduced-motion: reduce) { .wc-deck-card { transition: none; } }

/* ── The popup with the three drawn cards ── */
.wc-dialog {
  margin: auto; width: min(960px, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); box-sizing: border-box;
  padding: 1.5rem 1.75rem 1.75rem; border: 0; border-radius: 18px; overflow: auto;
  background: var(--wc-bg); color: var(--wc-ink); box-shadow: 0 24px 60px rgba(0,40,90,0.3);
}
.wc-dialog::backdrop { background: rgba(19,45,71,0.45); }
.wc-dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.wc-dialog-title { margin: 0; font: 700 2rem/1.1 'Caveat', cursive; color: var(--wc-hand); }
.wc-dialog-hint { margin: 0.35rem 0 0; font-size: 0.9rem; line-height: 1.5; color: var(--wc-muted); }
.wc-dialog-close {
  display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px;
  border: 0; border-radius: 50%; background: var(--wc-card); color: var(--wc-ink); cursor: pointer; box-shadow: 0 2px 8px rgba(0,60,120,0.12);
}
.wc-dialog-close:focus-visible { outline: 3px solid var(--wc-focus); outline-offset: 2px; }
.wc-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.5rem; padding: 1.25rem 0.25rem 0.75rem; }
.wc-cards .ms-card { width: 100%; max-width: none; box-sizing: border-box; }
/* Each card is a button: no button chrome, the whole card lifts on hover, and the text shows in full */
.wc-card-choice { border: 0; font: inherit; color: inherit; cursor: pointer; }
.wc-card-choice.ms-card-drawn { cursor: pointer; }
.wc-card-choice:focus-visible { outline: 3px solid var(--wc-focus); outline-offset: 4px; }
.wc-card-choice .ms-card-name { display: block; }
.wc-card-choice .ms-card-desc { display: block; -webkit-line-clamp: unset; overflow: visible; }
/* Cards have no points tag, so words already sit on their own line: no dot needed */
.wc-cards .ms-tag-dot { display: none; }

.wc-mission-strip { display: none; }
.wc-mission-body { display: flex; flex-direction: column; gap: 0.7rem; }
.wc-mission-card { padding: 1.1rem 1.3rem 1.3rem; text-align: center; rotate: -1deg; margin-bottom: 0.4rem; }
.wc-mission-card h2.wc-mission-title { margin: 0.2rem 0 0.4rem; font: 800 1.55rem/1.15 'Playfair Display', serif; color: var(--wc-ink); }
.wc-mission-desc { margin: 0 0 0.6rem; font-size: 0.9rem; line-height: 1.55; color: var(--wc-text2); }
.wc-meter-text { margin: 0 0 0.35rem; font: 600 1.3rem 'Caveat', cursive; color: var(--wc-muted); }
.wc-meter-text.is-done { color: var(--wc-good); }
.wc-hint { min-height: 1.1em; margin: -0.3rem 0 0; text-align: center; font: 600 1.2rem 'Caveat', cursive; color: var(--wc-warn); }
.wc-hint:empty { display: none; }
.wc-note { margin: 0; text-align: center; font-size: 0.8rem; line-height: 1.5; color: var(--wc-muted); }

.wc-result {
  margin-top: 0.4rem; padding: 1.1rem 1.1rem 1.2rem; background: var(--wc-card); border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,80,160,0.10); display: flex; flex-direction: column; align-items: center; gap: 0.5rem; text-align: center;
}
.wc-result p { margin: 0; }
.wc-result .ms-stamp { font-size: 0.95rem; padding: 0.35rem 0.6rem; }
.wc-result-title { font: 800 1.25rem 'Playfair Display', serif; color: var(--wc-ink); }
.wc-result-reason { font: 600 1.3rem/1.2 'Caveat', cursive; color: var(--wc-text2); }
.wc-result-next { font-size: 0.85rem; color: var(--wc-muted); }
.wc-result-actions { width: 100%; display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.3rem; }
.wc-result-actions .wc-pill-btn { white-space: normal; text-align: center; padding-top: 0.5rem; padding-bottom: 0.5rem; }

.wc-notice {
  padding: 0.9rem 1rem; border-radius: 12px; background: var(--wc-notice-bg); color: var(--wc-notice-ink);
  display: flex; flex-direction: column; align-items: center; gap: 0.6rem; text-align: center;
}
.wc-notice p { margin: 0; font-size: 0.9rem; line-height: 1.55; }

/* ── Sign-up card: under the mission on wide screens, after the text on phones ── */
.wc-pitch {
  display: flex; flex-direction: column; gap: 0.5rem; margin-top: 1.5rem; padding: 1.25rem 1.3rem;
  background: var(--wc-card-glass); border-radius: 14px; box-shadow: 0 10px 30px rgba(0,80,160,0.08);
}
.wc-pitch p { margin: 0; }
.wc-pitch-title { font: 800 1.2rem 'Playfair Display', serif; color: var(--wc-ink); }
.wc-pitch-text { font-size: 0.9rem; line-height: 1.5; color: var(--wc-text2); }
.wc-pitch .wc-pill-btn { margin-top: 0.35rem; }
.wc-pitch-end { display: none; }

/* ── The compact stats bar in the corner ── */
.wc-corner {
  position: fixed; z-index: 90;
  left: max(16px, env(safe-area-inset-left)); bottom: max(16px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: stretch; gap: 0.35rem;
  min-height: 44px; min-width: 120px; max-width: calc(100vw - 32px); box-sizing: border-box;
  padding: 0.6rem 1.2rem; border: 0; border-radius: 22px; cursor: pointer;
  background: var(--wc-card-glass); color: var(--wc-ink); box-shadow: 0 8px 24px rgba(0,60,120,0.18);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  font: 600 0.9rem 'Inter', sans-serif; font-variant-numeric: tabular-nums; text-align: left;
  animation: wc-corner-in 0.2s ease both;
}
.wc-corner-stats { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0; font-size: 0.8rem; font-weight: 500; color: var(--wc-muted); }
.wc-corner-stat { white-space: nowrap; padding: 0 0.75rem; border-left: 1px solid var(--wc-line); }
.wc-corner-stat:first-child { padding-left: 0; border-left: 0; }
.wc-corner-stat b { font: 800 1.05rem 'Playfair Display', serif; color: var(--wc-ink); }
@media (max-width: 560px) { .wc-corner-extra { display: none; } }
.wc-corner-bar { display: block; height: 4px; border-radius: 2px; background: var(--wc-line); overflow: hidden; }
.wc-corner-bar span { display: block; height: 100%; width: 0; background: var(--wc-accent); }
.wc-corner-bar.is-done span { background: var(--wc-good); }
@keyframes wc-corner-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .wc-corner { animation: none; }
  .wc-bar span { transition: none; }
}

/* ── Tablets and phones: the mission moves above the text as a one-line strip ── */
@media (max-width: 900px) {
  .wc-pitch-side { display: none; }
  .wc-pitch-end { display: flex; flex-basis: 100%; margin-top: 0; }
  .wc-side { order: -1; position: static; flex-basis: 100%; max-width: none; }
  .wc-draw { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .wc-dialog { padding: 1.1rem 1.1rem 1.25rem; }
  .wc-mission-strip {
    display: flex; align-items: center; gap: 0.75rem; width: 100%; min-height: 48px; box-sizing: border-box;
    padding: 0.5rem 1rem; border: 0; border-radius: 12px; background: var(--wc-card); color: var(--wc-ink); cursor: pointer;
    box-shadow: 0 6px 18px rgba(0,80,160,0.10); text-align: left;
  }
  .wc-strip-title { flex: 1 1 auto; min-width: 0; font: 800 1.05rem 'Playfair Display', serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .wc-strip-meter { flex: none; font: 600 0.85rem 'Inter', sans-serif; color: var(--wc-muted); font-variant-numeric: tabular-nums; }
  .wc-strip-meter.is-done { color: var(--wc-good); }
  .wc-strip-chevron { flex: none; transition: transform 0.2s; }
  .wc-mission.is-open .wc-strip-chevron { transform: rotate(180deg); }
  .wc-mission:not(.is-open) .wc-mission-body { display: none; }
  .wc-mission.is-open .wc-mission-body { margin-top: 0.6rem; }
}
@media (max-width: 768px) {
  .wc-sky { padding: 92px 1rem 1rem; }
  .wc-status { padding: 0 1rem; }
  .wc-count { padding: 0.7rem 1rem 0.7rem 0; margin-right: 1rem; }
  .wc-count-value { font-size: 1.4rem; }
  .wc-goal { flex-basis: 100%; border-top: 1px solid var(--wc-line); }
  .wc-desk { padding: 0.5rem 1rem 2.5rem; }
  .wc-text { min-height: 360px; padding: 1.25rem 1.25rem 5.5rem; font-size: 1.05rem; }
  .wc-toolbar-note { flex-basis: 100%; margin: 0.2rem 0 0 0.9rem; }
}
@media (prefers-reduced-motion: reduce) { .wc-strip-chevron { transition: none; } }
