/* hAIku. Phone first; the wide-screen layout is at the bottom. */

:root {
  --bg: #0F1113;
  --ink: #ECE8E1;
  --mute: #A3A7AD;
  --line: #3A3F45;
  --field: #171A1D;
  --accent: #E2553D;
  --serif: "Shippori Mincho", Georgia, serif;
  --sans: Inter, system-ui, sans-serif;

  /* Sizes that the wide layout changes. */
  --haiku-size: 21px;
  --asked-size: 13px;
  --past-size: 15px;
  --past-asked-size: 11px;
  --column: 520px;
}

/* Fonts are kept in /fonts so no visitor's browser has to contact Google.
   Latin subset only: enough for English and Italian. Both are under the
   SIL Open Font License. */
@font-face { font-family: "Shippori Mincho"; font-weight: 400; font-display: swap; src: url("fonts/shippori-mincho-400-latin.woff2") format("woff2"); }
@font-face { font-family: "Shippori Mincho"; font-weight: 500; font-display: swap; src: url("fonts/shippori-mincho-500-latin.woff2") format("woff2"); }
@font-face { font-family: Inter; font-weight: 400 500; font-display: swap; src: url("fonts/inter-latin.woff2") format("woff2"); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { font-family: var(--sans); -webkit-text-size-adjust: 100%; }
p { margin: 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---- the one screen ---- */
.stage {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: clamp(20px, 6.6vh, 56px) 32px max(28px, env(safe-area-inset-bottom));
}
header, main, footer { width: 100%; max-width: var(--column); margin-inline: auto; }

/* ---- brush circle ---- */
.enso {
  position: absolute;
  z-index: -1;
  left: 50%;
  top: 45%;
  width: min(340px, 87vw, 62vh);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  color: var(--ink);
  opacity: 0.1;
  transition: opacity 0.8s ease;
}
.enso svg { display: block; width: 100%; height: 100%; animation: enso-turn 7s linear infinite paused; }
.waiting .enso { opacity: 0.32; }
.waiting .enso svg { animation-play-state: running; }
@keyframes enso-turn { to { transform: rotate(360deg); } }

/* ---- header ---- */
header { display: flex; justify-content: center; flex-shrink: 0; }
.brand { margin: 0; font-family: var(--serif); font-size: 22px; font-weight: 500; letter-spacing: 0.04em; }
.brand span { color: var(--accent); }

/* ---- the middle ---- */
main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 36px;
  padding-top: 20px;
  padding-bottom: clamp(28px, 15.4vh, 130px);
  transition: padding-bottom 0.9s ease;
}
/* Once there is an earlier exchange above, everything sits lower to make room. */
main:has(.past-item) { padding-bottom: clamp(16px, 5vh, 48px); }
.intro {
  margin-bottom: clamp(40px, 17.8vh, 150px);
  font-family: var(--serif);
  font-size: var(--haiku-size);
  line-height: 1.7;
  color: var(--mute);
  text-align: center;
}

.now { display: flex; flex-direction: column; gap: 28px; flex-shrink: 0; }
.asked { font-size: var(--asked-size); line-height: 1.5; color: var(--mute); overflow-wrap: anywhere; }
.haiku { display: flex; flex-direction: column; gap: 10px; font-family: var(--serif); font-size: var(--haiku-size); line-height: 1.5; }
.haiku p { min-height: 1.5em; }
.haiku.fits p { white-space: nowrap; } /* app.js sized it so each line fits on one row */

/* Earlier exchanges: the newest is clearest, older ones fade. */
/* If there still is not enough room, it is this block that gives way: it is
   cut off at the top (and only at the top) instead of running into the title. */
.past { position: relative; display: flex; flex-direction: column; justify-content: flex-end; gap: 24px;
  flex: 0 1 auto; min-height: 0; clip-path: inset(0 -100vw -100vh -100vw); }
.past-item { flex-shrink: 0; }
.past:empty { display: none; }
.past-item { --o: 0.55; opacity: var(--o); transform-origin: left top; display: flex; flex-direction: column; gap: 12px; }
.past-item:nth-last-child(2) { --o: 0.34; }
.past-item:nth-last-child(n+3) { --o: 0.2; }
.past-item .q { font-size: var(--past-asked-size); line-height: 1.5; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.past-item .l { display: flex; flex-direction: column; gap: 4px; font-family: var(--serif); font-size: var(--past-size); line-height: 1.5; }
.past-item.roll { animation: roll 0.9s cubic-bezier(.2, .7, .2, 1) both; }
.past-item.gone { position: absolute; left: 0; top: 0; animation: gone 0.9s ease both; }
@keyframes roll { from { transform: translateY(150px) scale(1.4); opacity: 1; } to { transform: none; opacity: var(--o); } }
@keyframes gone { from { transform: none; } to { transform: translateY(-48px) scale(.85); opacity: 0; } }

/* The plain message. Deliberately not in the poem's voice or typeface. */
.plain { display: flex; flex-direction: column; gap: 14px; padding: 20px; max-height: 100%; overflow-y: auto; border: 1px solid var(--line); border-radius: 16px; background: var(--field); font-size: 15px; line-height: 1.6; }
.plain a { color: var(--ink); }

/* ---- footer ---- */
footer { display: flex; flex-direction: column; gap: 16px; flex-shrink: 0; }
.ask { display: flex; gap: 10px; align-items: center; }
.ask textarea {
  flex: 1; min-width: 0; height: 48px; padding: 12px 16px;
  border: 1px solid var(--line); border-radius: 24px;
  background: var(--field); color: var(--ink);
  font-family: var(--sans); font-size: 16px; line-height: 22px;
  resize: none; overflow: hidden; white-space: nowrap; scrollbar-width: none;
}
.ask textarea::placeholder { color: var(--mute); }
.ask textarea:focus { outline: 2px solid var(--ink); outline-offset: 2px; }
.ask button {
  flex-shrink: 0; width: 48px; height: 48px; border: 0; border-radius: 24px;
  background: var(--accent); color: var(--bg);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.ask button:focus-visible, .anew:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.busy .ask button { opacity: 0.5; cursor: default; }

/* Daily quota used up. */
.closed .ask textarea { border-style: dashed; background: var(--bg); }
.closed .ask button { border: 1px solid var(--line); background: var(--field); color: var(--mute); cursor: default; }

.note { font-size: 11px; line-height: 1.5; color: var(--mute); text-align: center; }
.anew { margin-left: 6px; padding: 6px 2px; border: 0; background: none; color: var(--mute); font: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.anew:hover { color: var(--ink); }

/* The plain message is always in both languages; the chosen one comes first. */
.plain > div { display: flex; flex-direction: column; gap: 14px; }
.plain > div + div, html[lang="it"] .plain-en { padding-top: 14px; border-top: 1px solid var(--line); }
html[lang="it"] .plain-it { order: -1; padding-top: 0; border-top: 0; }

/* While it shows, it takes the room the poem would have had. */
main:has(.plain:not([hidden])) { justify-content: center; padding-bottom: 16px; }
@media (max-width: 899px) { .plain { font-size: 14px; line-height: 1.55; padding: 18px; } }

/* ---- settings ---- */
.gear, .help {
  position: absolute; z-index: 1;
  top: clamp(8px, calc(6.6vh - 12px), 44px); right: 16px;
  width: 44px; height: 44px; padding: 0; border: 0; border-radius: 22px;
  background: none; color: var(--mute); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.help { right: 52px; }
.gear:hover, .help:hover { color: var(--ink); }
.about p { margin: 0 0 14px; font-size: 15px; line-height: 1.6; }
.about .about-small { margin-bottom: 0; font-size: 13px; color: var(--mute); }
.gear:focus-visible, .help:focus-visible, .lang:focus-visible, .settings-close:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.settings {
  width: min(340px, calc(100vw - 48px)); padding: 28px;
  border: 1px solid var(--line); border-radius: 20px;
  background: var(--field); color: var(--ink); font-family: var(--sans);
}
.settings::backdrop { background: rgba(8, 9, 10, 0.72); }
.settings h2 { margin: 0 0 24px; font-family: var(--serif); font-size: 21px; font-weight: 500; letter-spacing: 0.02em; }
.settings-label { margin-bottom: 10px; font-size: 12px; color: var(--mute); }
.langs { display: flex; flex-direction: column; gap: 8px; }
.lang {
  display: flex; align-items: center; gap: 14px; height: 52px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 14px;
  background: none; color: var(--ink); font: inherit; font-size: 16px; text-align: left; cursor: pointer;
}
.lang[aria-pressed="true"] { border-color: var(--ink); background: var(--bg); }
.lang[aria-pressed="true"]::after { content: ""; margin-left: auto; width: 8px; height: 8px; border-radius: 4px; background: var(--accent); }
.flag { width: 30px; height: 20px; flex-shrink: 0; }
.settings-close {
  display: block; margin: 24px auto 0; padding: 10px 16px; border: 0; background: none;
  color: var(--mute); font: inherit; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.settings-close:hover { color: var(--ink); }

/* Short screens (keyboard open, landscape phone): give the poem the room. */
@media (max-height: 520px) {
  .past { display: none; }
  main { gap: 20px; }
  .now { gap: 16px; }
}

/* ---- wide screens: the same page with room to breathe ---- */
@media (min-width: 900px) and (min-height: 600px) {
  :root {
    --haiku-size: clamp(28px, 2.5vw, 38px);
    --asked-size: 16px;
    --past-size: 18px;
    --past-asked-size: 13px;
    --column: min(760px, 62vw);
  }
  .stage { padding: 44px 64px 36px; }
  .gear, .help { top: 36px; right: 44px; }
  .help { right: 82px; }
  .brand { font-size: 28px; }
  .enso { top: 47%; width: min(640px, 72vh); }
  main { gap: 48px; padding-bottom: clamp(40px, 12vh, 120px); }
  .intro { margin-bottom: clamp(60px, 20vh, 200px); }
  .now { gap: 32px; }
  .haiku { gap: 14px; }
  .past { gap: 28px; }
  footer { gap: 18px; }
  .ask textarea { height: 56px; padding: 16px 22px; border-radius: 28px; font-size: 17px; }
  .ask button { width: 56px; height: 56px; border-radius: 28px; }
  .note { font-size: 12px; }
  .plain { font-size: 17px; padding: 28px; }
  @keyframes roll { from { transform: translateY(220px) scale(1.7); opacity: 1; } to { transform: none; opacity: var(--o); } }
}

@media (prefers-reduced-motion: reduce) {
  .enso svg { animation: none; }
  .past-item.roll, .past-item.gone { animation-duration: 1ms; }
}
