:root {
  --petal-bg: #fdfaf6;
  --petal-surface: #ffffff;
  --petal-ink: #3a2e2e;
  --petal-muted: #8a7d7d;
  --petal-primary: #d96c9c;
  --petal-primary-dark: #b84f80;
  --petal-primary-light: #f4c6dc;
  --petal-bud: #f6c94c;
  --petal-bud-dark: #e0a92a;
  --petal-leaf: #7fb37a;
  --petal-border: #f0d9e4;
  --petal-shadow: 0 4px 14px rgba(217, 108, 156, 0.15);
  --radius-lg: 20px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--petal-bg);
  color: var(--petal-ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: env(safe-area-inset-top, 16px) 16px env(safe-area-inset-bottom, 16px);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 12px;
  flex-shrink: 0;
}

.app-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0;
  color: var(--petal-primary-dark);
}

.score-badge {
  font-family: inherit;
  background: var(--petal-primary-light);
  color: var(--petal-primary-dark);
  font-weight: 700;
  padding: 8px 16px;
  border: none;
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.score-badge:focus-visible {
  background: var(--petal-primary);
  color: #fff;
}

/* Real hover only applies on devices with an actual pointer (mouse/trackpad).
   Touch browsers simulate :hover on tap and never fire a "leave" event, so
   scoping this out avoids buttons getting stuck highlighted after a tap. */
@media (hover: hover) and (pointer: fine) {
  .score-badge:hover {
    background: var(--petal-primary);
    color: #fff;
  }
}

.game-screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 12px;
}

.game-screen[hidden] {
  display: none;
}

.word-display {
  min-height: 2.4em;
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--petal-primary-dark);
  flex-shrink: 0;
}

.board-wrap {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  flex: 1;
  min-height: 0;
}

.mult-tracker {
  position: absolute;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 52px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: var(--petal-primary-light);
  color: var(--petal-primary-dark);
}

.mult-tracker-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.mult-tracker-value {
  font-size: 1.4rem;
  font-weight: 800;
  transition: transform 0.15s ease;
}

.msg-area {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.6em;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--petal-primary-dark);
  background: transparent;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  transition: background-color 0.15s ease;
  flex-shrink: 0;
}

.msg-area.has-message {
  background: var(--petal-primary-light);
}

.hint-area {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.6em;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--petal-bud-dark);
  background: transparent;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  transition: background-color 0.15s ease;
  flex-shrink: 0;
}

.hint-area.has-hint {
  background: #fbf1d3;
}

.controls-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 14px 20px;
  min-height: 48px;
  border-radius: var(--radius-md);
  border: 2px solid var(--petal-border);
  background: var(--petal-surface);
  color: var(--petal-ink);
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s ease, transform 0.05s ease;
}

.btn:active {
  background: var(--petal-primary-light);
  transform: scale(0.97);
}

.btn-primary {
  background: var(--petal-primary);
  border-color: var(--petal-primary);
  color: #fff;
}

.btn-primary:active {
  background: var(--petal-primary-dark);
}

/* Real hover only applies on devices with an actual pointer (mouse/trackpad).
   Touch browsers simulate :hover on tap and never fire a "leave" event, so
   scoping this out avoids buttons getting stuck highlighted after a tap. */
@media (hover: hover) and (pointer: fine) {
  .btn:hover {
    background: var(--petal-primary-light);
  }

  .btn-primary:hover {
    background: var(--petal-primary-dark);
  }
}

.btn-secondary {
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 16px;
  min-height: 40px;
  color: var(--petal-ink);
  background: var(--petal-surface);
}

.win-screen {
  background: var(--petal-surface);
  border: 2px solid var(--petal-border);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  text-align: center;
  box-shadow: var(--petal-shadow);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.win-screen[hidden] {
  display: none;
}

.win-screen h2 {
  margin-top: 0;
  color: var(--petal-primary-dark);
}

.ranked-words-list {
  list-style: none;
  margin: 20px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  max-height: 50vh;
  overflow-y: auto;
}

.ranked-words-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--petal-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--petal-border);
}

.rw-word {
  font-weight: 700;
  letter-spacing: 0.03em;
}

.rw-points {
  color: var(--petal-primary-dark);
  font-weight: 700;
}

.ranked-words-list li.rw-empty {
  justify-content: center;
  color: var(--petal-muted);
  font-weight: 600;
}

.win-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}

.share-feedback {
  color: var(--petal-primary-dark);
  font-weight: 600;
  font-size: 0.85rem;
  min-height: 1.2em;
}

.countdown-wrap {
  margin: 20px 0;
  padding: 16px;
  background: var(--petal-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--petal-border);
}

.countdown-label {
  margin: 0 0 4px;
  color: var(--petal-muted);
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.countdown-value {
  font-size: 1.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--petal-primary-dark);
}

#countdown-ready {
  margin-top: 10px;
}

.stats-block {
  margin-top: 12px;
}

.stats-summary {
  color: var(--petal-muted);
  font-weight: 600;
  font-size: 0.9rem;
  margin: 0 0 10px;
}

.histogram {
  max-width: 320px;
  margin: 0 auto;
}

.histogram-svg {
  width: 100%;
  height: auto;
}

.hist-bar {
  fill: var(--petal-primary-light);
}

.hist-bar.is-player {
  fill: var(--petal-primary);
  stroke: var(--petal-primary-dark);
  stroke-width: 2px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(58, 46, 46, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-panel {
  background: var(--petal-surface);
  border: 2px solid var(--petal-border);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  text-align: center;
  box-shadow: var(--petal-shadow);
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-panel h2 {
  margin-top: 0;
  color: var(--petal-primary-dark);
}

@media (min-width: 640px) {
  .app-header h1 {
    font-size: 1.3rem;
  }

  .word-display {
    font-size: 2.4rem;
  }
}
