:root {
  --bg: #e7f3fb;
  --bg-strong: #dfeff8;
  --panel: #f5fbff;
  --panel-strong: #e5f2fa;
  --surface: #fcfeff;
  --surface-strong: #f2f8fd;
  --accent: #5b89b0;
  --accent-strong: #436a87;
  --accent-soft: #dcecf7;
  --text: #203648;
  --muted: #5d7387;
  --border: #456b83;
  --shadow: rgba(32, 54, 72, 0.16);
  --panel-radius: 18px;
  --button-radius: 14px;
  --input-radius: 14px;
  --panel-padding: 18px;
}

* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: var(--accent-strong) var(--accent-soft);
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: var(--accent-soft);
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
  background-color: var(--accent-strong);
}

html {
  min-height: 100%;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: auto;
}

body {
  min-height: 100%;
  font-family: "Trebuchet MS", "Segoe UI", Tahoma, sans-serif;
  font-size: 17px;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-strong) 100%);
  color: var(--text);
  overflow: auto;
  scroll-behavior: smooth;
}

body::before {
  /* removed blocking overlay that prevented interactions */
  content: none;
  display: none;
  pointer-events: none;
}

body.flash {
  animation: flashPulse 220ms ease;
}

@keyframes flashPulse {
  0% { filter: brightness(1); }
  50% { filter: brightness(1.04); }
  100% { filter: brightness(1); }
}

.game {
  width: 95vw;
  max-width: none;
  height: 100vh;
  max-height: 100vh;
  margin: 0 auto;
  padding: clamp(16px, 2.5vw, 28px);
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 1.2vw, 20px);
  overflow: hidden;
}

.topbar {
  border: 2px solid var(--border);
  border-radius: var(--panel-radius);
  padding: clamp(12px, 1.4vw, 16px);
  background: linear-gradient(135deg, var(--panel) 0%, var(--panel-strong) 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  box-shadow: 0 5px 0 var(--shadow);
}

.topbar-copy {
  min-width: 0;
}

.topbar-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 1 1 220px;
  flex-wrap: wrap;
}

.flock-counter {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 8px;
  min-width: 52px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-strong);
}

.flock-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.flock-count {
  font-size: 1.8rem;
  font-weight: 700;
}

.topbar-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.meta-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 8px;
  min-width: 52px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-strong);
}

.meta-pill span {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.meta-pill strong {
  font-size: 1.5rem;
  font-weight: 700;
}

h1,
h2,
h3 {
  margin: 0 0 6px 0;
  line-height: 1.1;
}

h1 {
  font-size: 1.8rem;
}

h2 {
  font-size: 1.2rem;
}

.topbar p,
.panel-subtitle,
.status,
.overlay-card p,
.overlay-card li,
.list .item small,
.list .item .meta {
  color: var(--muted);
}

.topbar p {
  margin: 0;
  max-width: 720px;
  line-height: 1.4;
  font-size: 0.78rem;
}

/* Prevent selecting the passage text to avoid accidental highlighting */
.passage, .passage * {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.95fr);
  gap: clamp(12px, 1.2vw, 18px);
  align-items: stretch;
  overflow: hidden;
}

.typing-panel,
.side-stack {
  min-height: 0;
  height: 100%;
}

.typing-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.side-stack {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.side-stack > .panel {
  padding: clamp(8px, 1vw, 12px);
  overflow: visible;
  flex: 0 0 auto;
}

/* ensure panel bodies remain scrollable and don't clip their content */
.side-stack .panel-grid > .panel .panel-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.panel {
  border: 2px solid var(--border);
  border-radius: var(--panel-radius);
  padding: clamp(14px, 1.6vw, 20px);
  background: var(--panel);
  box-shadow: 0 4px 0 var(--shadow);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.panel:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 0 var(--shadow);
}

.typing-panel {
  padding: clamp(14px, 1.6vw, 20px);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.panel-subtitle {
  margin: 0;
  font-size: 0.96rem;
}

.mode-select {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: calc(var(--panel-radius) - 6px);
  background: var(--panel-strong);
  flex-wrap: wrap;
}

.mode-select select,
input,
button {
  font: inherit;
}

.mode-select select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  background: var(--panel);
  color: var(--text);
}

.passage {
  border: 1px solid var(--border);
  border-radius: calc(var(--panel-radius) - 6px);
  padding: 13px 15px;
  margin-bottom: 14px;
  /* font scales with viewport and container via vmin/vw to better fill available space */
  font-size: clamp(1rem, 3.2vmin, 3.2rem);
  line-height: 1.5;
  background: linear-gradient(180deg, var(--surface) 0%, var(--panel-strong) 100%);
  min-height: clamp(220px, 24vh, 420px);
  max-height: 100%;
  white-space: normal;
  flex: 1 1 auto;
  overflow: auto;
  overflow-x: hidden;
}

.word {
  display: inline-block;
  margin-right: 4px;
  padding: 1px 0;
}

.current-word {
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

.correct {
  color: #257a41;
  font-weight: 700;
}

.incorrect {
  color: #b53b3b;
  font-weight: 700;
}

textarea,
input {
  width: 100%;
  box-sizing: border-box;
  padding: 12px 13px;
  border: 2px solid var(--border);
  border-radius: var(--input-radius);
  background: linear-gradient(180deg, var(--surface) 0%, var(--panel-strong) 100%);
  color: var(--text);
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
  font-size: 1rem;
}

textarea {
  min-height: 150px;
  max-height: 270px;
  resize: none;
  overflow: hidden;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  padding: 14px 15px;
  margin-bottom: 12px;
}

textarea:focus,
input:focus {
  outline: none;
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.status {
  margin-top: 10px;
  min-height: 24px;
  font-size: 0.96rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.stat-box {
  border: 1px solid var(--border);
  border-radius: calc(var(--panel-radius) - 8px);
  padding: 11px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--panel-strong) 100%);
}

.stats-grid strong,
.list .item strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats-grid span {
  font-size: 1.05rem;
  font-weight: 700;
}

.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button {
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--button-radius);
  background: linear-gradient(180deg, var(--accent-soft) 0%, var(--accent) 100%);
  color: #f8fcff;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, filter 140ms ease;
  box-shadow: 0 2px 0 rgba(28, 46, 60, 0.16);
}

.danger-button {
  background: linear-gradient(180deg, #ffd6d6 0%, #a84a4a 100%);
  color: #fffdfd;
}

button:hover {
  filter: brightness(1.02);
  box-shadow: 0 3px 0 rgba(28, 46, 60, 0.2);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
  box-shadow: none;
}

.side-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  height: 100%;
  overflow: visible;
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: minmax(220px, 1fr);
  gap: clamp(10px, 1vw, 14px);
  min-height: 0;
  flex: 1 1 auto;
  align-items: stretch;
  height: 100%;
}

.side-stack .panel-grid > .panel {
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-height: none;
  flex: 1 1 auto;
  overflow: hidden;
}

.compact-panel {
  min-height: 0;
}

.panel-body {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
}

.list {
  display: grid;
  gap: 8px;
}

.list .item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 11px;
  overflow: visible;
  border: 1px solid var(--border);
  border-radius: calc(var(--panel-radius) - 8px);
  background: linear-gradient(180deg, var(--surface) 0%, var(--panel-strong) 100%);
}

.list .item .text {
  flex: 1 1 220px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.list .item .meta {
  text-align: right;
  min-width: 96px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.list .item small {
  display: block;
  margin-top: 4px;
  line-height: 1.45;
}

.floating-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 30;
}

.floating-text {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  opacity: 0;
  font-weight: 700;
  color: var(--accent-strong);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.75);
  animation: driftUp 900ms ease-out forwards;
}

@keyframes driftUp {
  0% {
    transform: translate(-50%, -50%) scale(0.96);
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -120%) scale(1.08);
    opacity: 0;
  }
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 37, 49, 0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(620px, 100%);
  max-height: 86vh;
  overflow: auto;
  overflow-x: hidden;
  border: 2px solid var(--border);
  border-radius: calc(var(--panel-radius) + 4px);
  background: var(--panel);
  padding: 16px;
  box-shadow: 0 7px 0 var(--shadow);
}

.overlay-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 12px;
}

.overlay-card p,
.overlay-card li {
  line-height: 1.6;
  margin: 0 0 8px 0;
}

.settings-grid {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--accent-soft);
}

.setting-row:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.setting-row span {
  font-weight: 700;
}

.setting-row input[type="color"] {
  width: 44px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: transparent;
}

.setting-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent-strong);
}

.setting-row output {
  min-width: 44px;
  text-align: right;
  font-weight: 700;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1280px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .panel-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .topbar,
  .panel-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .panel-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .topbar-actions button {
    flex: 1 1 calc(50% - 6px);
  }
}

@media (max-width: 700px) {
  .game {
    padding: 12px;
  }

  .panel,
  .topbar {
    padding: 16px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions button {
    flex-basis: 100%;
  }

  .mode-select {
    width: 100%;
    justify-content: space-between;
  }
}

@media (max-width: 480px) {
  .topbar-actions {
    flex-direction: column;
  }

  .topbar-actions button {
    width: 100%;
    flex-basis: auto;
  }

  .list .item {
    padding: 10px;
  }

  .list .item .meta {
    width: 100%;
    min-width: 0;
    align-items: flex-start;
    text-align: left;
  }
}

/* Discovery Locked styles */
.list .item.undiscovered {
  filter: brightness(0.6) grayscale(0.8);
  opacity: 0.6;
  position: relative;
  cursor: help;
}

.list .item.undiscovered .text strong {
  filter: blur(4px);
  user-select: none;
}

.list .item.undiscovered .text div {
  filter: blur(4px);
  user-select: none;
}

.list .item.undiscovered .meta button {
  pointer-events: none;
  opacity: 0.3;
}

/* Glow animation for new unlocks */
.list .item.newly-unlocked {
  animation: unlockGlow 2.5s ease-out;
}

@keyframes unlockGlow {
  0% {
    box-shadow: 0 0 16px var(--accent), inset 0 0 8px var(--accent);
    border-color: var(--accent);
  }
  50% {
    box-shadow: 0 0 24px var(--accent), inset 0 0 16px var(--accent);
    border-color: var(--accent-strong);
    filter: brightness(1.2);
  }
  100% {
    box-shadow: none;
    border-color: var(--border);
  }
}

/* Hourly Challenges items */
#challengesPanel {
  max-height: 240px;
}

.challenge-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.challenge-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 0.8rem;
}

.challenge-bar-bg {
  width: 100%;
  height: 8px;
  background: var(--panel-strong);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.challenge-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
  width: 0%;
}

.challenge-item.completed .challenge-bar-fill {
  background: #257a41;
}

.challenge-item.completed {
  border-color: #257a41;
}

/* Floating text modifications */
.floating-text.birdie-gain {
  color: #c99324;
}

.floating-text.seed-gain {
  color: #257a41;
}

/* Small celebration animations */
@keyframes celebrateBlast {
  0% { transform: scale(1); filter: hue-rotate(0deg); }
  50% { transform: scale(1.05); filter: hue-rotate(180deg); }
  100% { transform: scale(1); filter: hue-rotate(360deg); }
}

.celebrating {
  animation: celebrateBlast 0.8s ease-in-out 2;
}

/* Tooltip style for locked items */
.discovery-tooltip {
  font-size: 0.75rem;
  color: var(--muted);
  font-style: italic;
  margin-top: 4px;
}

