:root {
  --glass: rgba(48, 32, 22, 0.55);
  --glass-strong: rgba(44, 30, 21, 0.86);
  --edge: rgba(255, 236, 214, 0.16);
  --ink: #fbf3e8;
  --ink-dim: rgba(251, 243, 232, 0.68);
  --accent: #e8a36d;
  --paper: #f6eddf;
  --paper-ink: #3f2f24;
  --ui-font: ui-rounded, 'Segoe UI', system-ui, -apple-system, sans-serif;
  --title-font: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #5a3f2b;
  color: var(--ink);
  font-family: var(--ui-font);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#view {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: none;
}

/* ---------- toolbar (sits on the sill) ---------- */
#hud {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--edge);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0.7;
  transition: opacity 0.3s ease;
}

#hud:hover,
#hud:focus-within {
  opacity: 1;
}

#hud button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease;
}

#hud button:hover {
  background: rgba(255, 240, 220, 0.14);
}

#hud button:active {
  transform: scale(0.92);
}

#hud button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#hud button.on {
  background: rgba(255, 240, 220, 0.22);
}

#hud svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

body[data-season='spring'] .ic-winter,
body[data-season='winter'] .ic-spring {
  display: none;
}

#hud [data-act='sound'] .wave {
  display: none;
}
#hud [data-act='sound'].on .wave {
  display: inline;
}
#hud [data-act='sound'].on .mute {
  display: none;
}

#count {
  padding: 0 12px 0 6px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-dim);
  white-space: nowrap;
}

/* ---------- toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  top: max(18px, env(safe-area-inset-top));
  z-index: 7;
  max-width: calc(100vw - 32px);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--glass-strong);
  border: 1px solid var(--edge);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(30, 18, 10, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.overlay.show {
  opacity: 1;
  pointer-events: auto;
}

#help.show {
  cursor: pointer;
}

.card {
  position: relative;
  width: min(400px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 24px 26px 20px;
  border-radius: 18px;
  background: var(--paper);
  color: var(--paper-ink);
  box-shadow: 0 24px 70px rgba(20, 10, 0, 0.45), inset 0 0 0 1px rgba(120, 90, 60, 0.18);
  font-size: 14px;
  line-height: 1.55;
}

.card.wide {
  width: min(760px, 100%);
}

.card h1 {
  margin: 0;
  font-family: var(--title-font);
  font-weight: 500;
  font-size: 28px;
}

.card .sub {
  margin: 2px 0 14px;
  font-family: var(--title-font);
  font-style: italic;
  color: rgba(63, 47, 36, 0.7);
}

.card ul {
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
}

.card li {
  position: relative;
  padding: 3px 0 3px 18px;
}

.card li::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 0.72em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.card b {
  font-weight: 600;
}

.card .keys {
  margin: 0;
  font-size: 12px;
  line-height: 2;
  color: rgba(63, 47, 36, 0.7);
}

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 0 6px;
  margin-right: 2px;
  border-radius: 6px;
  border: 1px solid rgba(120, 90, 60, 0.3);
  background: #fffaf2;
  font: 600 11px/18px var(--ui-font);
  text-align: center;
  color: var(--paper-ink);
}

.card .hint {
  margin: 14px 0 0;
  text-align: center;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: rgba(63, 47, 36, 0.55);
}

.close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--paper-ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.close:hover {
  background: rgba(120, 90, 60, 0.12);
}

#journal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.bird-card {
  padding: 8px 8px 10px;
  border-radius: 12px;
  background: #fffaf2;
  box-shadow: inset 0 0 0 1px rgba(120, 90, 60, 0.15);
  text-align: center;
}

.bird-card canvas {
  width: 120px;
  height: 90px;
  display: block;
  margin: 0 auto 4px;
}

.bird-card .name {
  font-weight: 600;
  font-size: 13px;
}

.bird-card .meta {
  font-family: var(--title-font);
  font-style: italic;
  font-size: 12px;
  color: rgba(63, 47, 36, 0.62);
}

.bird-card.unseen {
  background: #f1e6d6;
}

.bird-card.unseen .name {
  color: rgba(63, 47, 36, 0.5);
  letter-spacing: 0.15em;
}

@media (max-width: 480px) {
  #hud button {
    width: 34px;
    height: 34px;
  }
  .card {
    padding: 20px 18px 16px;
  }
}

#boot-error {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 10;
  width: min(560px, calc(100vw - 32px));
  transform: translate(-50%, -50%);
  padding: 20px 22px;
  border-radius: 14px;
  background: var(--paper);
  color: var(--paper-ink);
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

#boot-error[hidden] {
  display: none;
}

#boot-error p {
  margin: 0 0 10px;
}

#boot-error pre {
  margin: 0 0 10px;
  padding: 10px;
  border-radius: 8px;
  background: #fffaf2;
  font-size: 12px;
  white-space: pre-wrap;
  user-select: text;
}

#boot-error small {
  display: block;
  font-size: 11px;
  opacity: 0.6;
  user-select: text;
}

/* Credit: a quiet link back to the main site, top right, clear of the controls */
#credit {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 30; /* above the help card, so the first tap follows the link */
  padding: 10px 4px;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-decoration: none;
  opacity: 0.55;
  transition: opacity 0.35s ease;
}
#credit:hover,
#credit:focus-visible {
  opacity: 1;
  text-decoration: underline;
  text-underline-offset: 4px;
}
