:root {
  --cream: #fdf6e9;
  --cream-deep: #f5e6cf;
  --card-bg: rgba(255, 250, 241, 0.95);
  --espresso: #4d382e;
  --espresso-soft: #7b6052;
  --yarn: #d95b72;
  --yarn-dark: #b64359;
  --oyen: #e89248;
  --sage: #7ea883;
  --sage-dark: #5f8764;
  --butter: #f7cf78;
  --border: #d9c3a7;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--cream);
  color: var(--espresso);
  font-family: 'Quicksand', 'Fredoka', system-ui, -apple-system, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hidden {
  display: none !important;
}

/* Camera Flash */
.camera-flash {
  position: fixed;
  inset: 0;
  background: #fffdf7;
  z-index: 95;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.45s ease-out;
}

.camera-flash.flash {
  opacity: 0.92;
  transition: opacity 0.05s ease-in;
}

/* Storybook Page Transition */
.page-transition {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle, #fff8eb 0%, #f5e2c6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease;
}

.page-transition.active {
  opacity: 1;
  pointer-events: auto;
}

.transition-badge {
  font-size: 3rem;
  animation: spinBounce 0.6s ease infinite alternate;
}

@keyframes spinBounce {
  from { transform: scale(0.92) rotate(-10deg); }
  to { transform: scale(1.08) rotate(12deg); }
}

/* HUD */
.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  z-index: 20;
}

.hud-left,
.hud-center,
.hud-right {
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}

.pill-btn,
.level-badge,
.fish-counter,
.chaos-counter,
.timer-pill,
.mode-pill,
.emote-strip {
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: 999px;
  color: var(--espresso);
  box-shadow: 0 3px 0 rgba(77, 56, 46, 0.12);
  font-family: 'Fredoka', 'Quicksand', sans-serif;
  font-weight: 600;
  font-size: 0.85rem;
}

.level-badge,
.fish-counter,
.chaos-counter,
.timer-pill,
.mode-pill {
  padding: 5px 11px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.fish-counter {
  background: #fff7df;
  border-color: #e6c478;
}

.chaos-counter {
  background: #ffecee;
  border-color: #eab3bc;
  color: #a13a4d;
}

.timer-pill {
  font-variant-numeric: tabular-nums;
  color: var(--espresso-soft);
}

.emote-strip {
  display: inline-flex;
  align-items: center;
  padding: 2px 5px;
  gap: 2px;
}

.emote-mini {
  background: none;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.92rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, background 0.12s ease;
}

.emote-mini:hover {
  background: #fff1dc;
  transform: scale(1.15);
}

.emote-mini:active {
  transform: scale(0.92);
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.94rem;
  transition: transform 0.12s ease, background 0.15s ease;
}

.icon-btn:hover {
  background: #fff;
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(77, 56, 46, 0.12);
}

.icon-btn.active-toggle {
  background: #ffe9ec;
  border-color: var(--yarn);
}

/* Desktop keyboard hint bar */
.controls-bar {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 250, 241, 0.88);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 5px 15px;
  font-size: 0.77rem;
  font-weight: 700;
  color: var(--espresso-soft);
  box-shadow: 0 3px 10px rgba(77, 56, 46, 0.08);
  pointer-events: none;
  z-index: 15;
  white-space: nowrap;
}

.controls-bar kbd,
.help-box kbd {
  display: inline-block;
  padding: 1px 6px;
  margin: 0 1px;
  border-radius: 6px;
  background: #fff;
  border: 1.5px solid var(--border);
  box-shadow: 0 1.5px 0 var(--border);
  font-family: 'Fredoka', sans-serif;
  font-size: 0.75rem;
  color: var(--espresso);
}

/* Overlay Screens */
.overlay-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(77, 56, 46, 0.24);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 40;
}

.storybook-card {
  background: var(--card-bg);
  border: 3px solid #cbb190;
  border-radius: 28px;
  padding: 18px 22px;
  max-width: 660px;
  width: 100%;
  max-height: 94vh;
  overflow-y: auto;
  box-shadow:
    0 14px 36px rgba(77, 56, 46, 0.22),
    inset 0 0 0 4px rgba(255, 255, 255, 0.68);
  text-align: center;
  animation: popIn 0.25s cubic-bezier(0.22, 1.25, 0.36, 1);
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.title-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.yarn-ribbon,
.win-badge,
.total-fish-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 4px 13px;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
}

.yarn-ribbon,
.win-badge {
  background: #ffe6ea;
  color: var(--yarn-dark);
  border: 2px solid #f0b6c2;
}

.total-fish-badge {
  background: #fff6d9;
  color: #8f631b;
  border: 2px solid #e6c478;
}

.game-title {
  margin: 2px 0 6px;
  font-family: 'Fredoka', sans-serif;
  font-size: clamp(1.65rem, 3.8vw, 2.2rem);
  color: var(--espresso);
}

.game-subtitle {
  margin: 0 auto 12px;
  max-width: 520px;
  font-size: 0.86rem;
  line-height: 1.4;
  color: var(--espresso-soft);
}

.section-label {
  font-family: 'Fredoka', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--espresso-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.mode-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin-bottom: 12px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 7px;
  border-radius: 16px;
  border: 2.5px solid var(--border);
  background: #fffdf9;
  color: var(--espresso);
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.14s ease, border-color 0.15s ease, background 0.15s ease;
}

.mode-card:hover {
  transform: translateY(-2px);
  border-color: var(--oyen);
}

.mode-card.selected {
  background: #fff3e4;
  border-color: var(--oyen);
  box-shadow: 0 3px 0 rgba(232, 146, 72, 0.28);
}

.mode-emoji {
  font-size: 1.2rem;
}

.mode-card strong {
  font-family: 'Fredoka', sans-serif;
  font-size: 0.9rem;
}

.mode-card small {
  font-size: 0.7rem;
  color: var(--espresso-soft);
  line-height: 1.2;
}

/* Wardrobe Panel */
.wardrobe-panel {
  background: #fffcf6;
  border: 2px solid #e4d1b9;
  border-radius: 18px;
  padding: 9px 12px;
  margin-bottom: 12px;
  text-align: left;
}

.wardrobe-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
}

.wardrobe-tabs {
  display: inline-flex;
  gap: 6px;
}

.wtab {
  font-family: 'Fredoka', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 11px;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: #fff;
  color: var(--espresso-soft);
  cursor: pointer;
}

.wtab.active {
  background: #ffe9ed;
  border-color: var(--yarn);
  color: var(--yarn-dark);
}

.wardrobe-tip {
  font-size: 0.72rem;
  color: var(--espresso-soft);
}

.wardrobe-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.wardrobe-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-tag {
  font-family: 'Fredoka', sans-serif;
  font-size: 0.73rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

.p1-tag {
  background: #ffe9d2;
  color: #b45d17;
  border: 1.5px solid #e8aa73;
}

.p2-tag {
  background: #e7e5ee;
  color: #453f4d;
  border: 1.5px solid #b5afc0;
}

.skin-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.skin-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: #fff;
  color: var(--espresso);
  font-family: 'Fredoka', sans-serif;
  font-size: 0.73rem;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease;
}

.skin-pill:hover:not(.locked) {
  transform: translateY(-1px);
  border-color: var(--yarn);
}

.skin-pill.selected {
  background: #ffeef1;
  border-color: var(--yarn);
  box-shadow: 0 2px 0 rgba(217, 91, 114, 0.22);
}

.skin-pill.locked {
  opacity: 0.55;
  cursor: not-allowed;
  background: #f5efe6;
}

.skin-swatch {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid var(--espresso);
  flex-shrink: 0;
}

/* Chapter Map */
.level-picker {
  margin-bottom: 13px;
}

.level-picker .section-label {
  display: block;
  margin-bottom: 6px;
}

.level-buttons {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
}

.lvl-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 5px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: #fff;
  color: var(--espresso);
  cursor: pointer;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.78rem;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.lvl-btn:hover {
  transform: translateY(-1px);
  border-color: var(--sage);
}

.lvl-btn.selected {
  background: #eef6ee;
  border-color: var(--sage-dark);
  box-shadow: 0 3px 0 rgba(95, 135, 100, 0.24);
}

.lvl-btn .lvl-sub {
  font-family: 'Quicksand', sans-serif;
  font-size: 0.67rem;
  font-weight: 700;
  color: var(--espresso-soft);
  line-height: 1.15;
}

.lvl-btn .lvl-stars {
  font-size: 0.7rem;
}

.lvl-btn .lvl-time {
  font-size: 0.63rem;
  color: #8f7768;
  font-variant-numeric: tabular-nums;
}

/* Buttons */
.primary-btn,
.secondary-btn {
  font-family: 'Fredoka', sans-serif;
  font-weight: 600;
  font-size: 1rem;
  border-radius: 999px;
  padding: 11px 26px;
  cursor: pointer;
  border: 2.5px solid transparent;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.15s ease;
}

.small-btn {
  padding: 8px 16px;
  font-size: 0.86rem;
}

.primary-btn {
  background: linear-gradient(180deg, #e76c82 0%, #d45269 100%);
  color: #fff;
  border-color: #b43d52;
  box-shadow: 0 4px 0 #a33448;
}

.primary-btn:hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

.primary-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #a33448;
}

.secondary-btn {
  background: #fff9ef;
  color: var(--espresso);
  border-color: var(--border);
  box-shadow: 0 4px 0 rgba(77, 56, 46, 0.14);
}

.secondary-btn:hover {
  background: #fff;
}

.secondary-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(77, 56, 46, 0.14);
}

/* Online Lobby */
.online-card {
  max-width: 560px;
}

.online-cosmetics-note {
  background: #fff9ee;
  border: 1.5px solid #e3cfb6;
  border-radius: 12px;
  padding: 7px 12px;
  margin-bottom: 12px;
  font-size: 0.8rem;
  color: var(--espresso-soft);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.online-cosmetics-note strong {
  color: var(--espresso);
}

.online-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.online-box {
  background: #fffdf8;
  border: 2px solid var(--border);
  border-radius: 18px;
  padding: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.online-box h3 {
  margin: 0;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.98rem;
}

.online-box p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--espresso-soft);
}

.join-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.room-input {
  width: 96px;
  padding: 7px 10px;
  border-radius: 12px;
  border: 2.5px solid var(--border);
  background: #fff;
  font-family: 'Fredoka', sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  text-transform: uppercase;
  text-align: center;
  letter-spacing: 0.12em;
  color: var(--espresso);
}

.room-input:focus {
  outline: none;
  border-color: var(--yarn);
}

.online-waiting {
  background: #fff9ee;
  border: 2px dashed #d5b895;
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 14px;
}

.room-code-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 10px;
}

.room-code-display span {
  font-size: 0.78rem;
  color: var(--espresso-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.room-code-display strong {
  font-family: 'Fredoka', sans-serif;
  font-size: 2.3rem;
  letter-spacing: 0.18em;
  color: var(--yarn-dark);
}

.online-status {
  margin: 10px 0 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--sage-dark);
}

.online-error {
  margin: 0 0 12px;
  font-size: 0.84rem;
  font-weight: 700;
  color: #c23c4e;
}

/* Pause Settings */
.pause-card {
  max-width: 460px;
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fffdf8;
  border: 2px solid var(--border);
  border-radius: 18px;
  padding: 14px 16px;
  margin: 12px 0 18px;
  text-align: left;
}

.slider-row,
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.9rem;
}

.slider-row input[type="range"] {
  width: 145px;
  accent-color: var(--yarn);
  cursor: pointer;
}

.toggle-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--yarn);
  cursor: pointer;
}

/* Polaroid Win Screen */
.win-card {
  max-width: 480px;
  padding: 16px 20px;
}

.win-card h2 {
  margin: 4px 0 10px;
  font-family: 'Fredoka', sans-serif;
  font-size: 1.5rem;
}

.polaroid-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.polaroid-canvas {
  width: min(290px, 72vw);
  height: auto;
  border-radius: 6px;
  box-shadow: 0 10px 24px rgba(77, 56, 46, 0.24);
  transform: rotate(-1.5deg);
  transition: transform 0.2s ease;
}

.polaroid-canvas:hover {
  transform: rotate(0deg) scale(1.02);
}

.unlock-banner {
  margin-bottom: 12px;
  background: #eef8ee;
  border: 1.5px solid var(--sage);
  color: var(--sage-dark);
  border-radius: 12px;
  padding: 6px 10px;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.84rem;
}

.win-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Help Modal */
.help-card {
  max-width: 650px;
}

.help-card h2 {
  margin: 0 0 12px;
  font-family: 'Fredoka', sans-serif;
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  text-align: left;
  margin-bottom: 16px;
}

.help-box {
  background: #fffdf8;
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px;
}

.help-box h3 {
  margin: 0 0 8px;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.96rem;
}

.help-box ul {
  margin: 0;
  padding-left: 16px;
  font-size: 0.81rem;
  line-height: 1.58;
  color: var(--espresso-soft);
}

/* Mobile Virtual Thumbstick + Action Cluster */
.touch-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 25;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.touch-left,
.touch-right {
  pointer-events: auto;
}

.joystick-zone {
  width: 128px;
  height: 128px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.joystick-base {
  position: relative;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: rgba(255, 250, 241, 0.74);
  border: 3px solid rgba(77, 56, 46, 0.22);
  backdrop-filter: blur(4px);
  box-shadow: inset 0 3px 10px rgba(77, 56, 46, 0.08), 0 4px 0 rgba(77, 56, 46, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
}

.joystick-arrows {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-size: 0.78rem;
  color: rgba(77, 56, 46, 0.35);
  pointer-events: none;
}

.joystick-knob {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(180deg, #fffdf8 0%, #f9e8d2 100%);
  border: 2.5px solid #c99c74;
  box-shadow: 0 3px 8px rgba(77, 56, 46, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  pointer-events: none;
  transition: transform 0.04s linear;
}

.touch-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 9px;
}

.touch-row-top,
.touch-row-bottom {
  display: flex;
  gap: 8px;
  align-items: center;
}

.touch-btn {
  border-radius: 22px;
  border: 2.5px solid rgba(77, 56, 46, 0.25);
  background: rgba(255, 250, 241, 0.8);
  backdrop-filter: blur(4px);
  color: var(--espresso);
  font-family: 'Fredoka', sans-serif;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 0 rgba(77, 56, 46, 0.16);
  touch-action: none;
  cursor: pointer;
}

.touch-btn.pressed {
  transform: translateY(3px) scale(0.95);
  background: rgba(255, 232, 210, 0.94);
  border-color: var(--oyen);
  box-shadow: 0 1px 0 rgba(77, 56, 46, 0.16);
}

.action-btn {
  width: 66px;
  height: 66px;
  font-size: 1.25rem;
  gap: 1px;
}

.action-btn small,
.mini-btn small {
  font-size: 0.62rem;
  line-height: 1;
}

.jump-btn {
  background: rgba(255, 230, 234, 0.86);
  border-color: rgba(217, 91, 114, 0.45);
}

.anchor-btn.pressed {
  background: rgba(224, 242, 224, 0.95);
  border-color: var(--sage-dark);
}

.mini-btn {
  width: 50px;
  height: 46px;
  border-radius: 15px;
  font-size: 0.94rem;
}

.rotate-tip {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #4d382e;
  color: #fdf6e9;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 60;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}

.rotate-tip button {
  background: none;
  border: none;
  color: #f7cf78;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.95rem;
}

@media (max-width: 980px) {
  .emote-strip {
    display: none;
  }

  .level-badge,
  .fish-counter,
  .chaos-counter,
  .timer-pill,
  .mode-pill {
    padding: 4px 9px;
    font-size: 0.78rem;
  }
}

@media (max-width: 760px), (max-height: 520px) {
  .hud {
    padding: 6px 10px;
  }

  .level-badge,
  .fish-counter,
  .chaos-counter,
  .timer-pill,
  .mode-pill {
    padding: 4px 8px;
    font-size: 0.72rem;
  }

  .hud-center,
  .emote-strip {
    display: none;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 0.85rem;
  }

  .storybook-card {
    padding: 14px 16px;
    border-radius: 22px;
  }

  .level-buttons {
    grid-template-columns: repeat(3, 1fr);
  }

  .help-grid,
  .online-grid {
    grid-template-columns: 1fr;
  }

  .joystick-zone {
    width: 108px;
    height: 108px;
  }

  .joystick-base {
    width: 96px;
    height: 96px;
  }

  .joystick-knob {
    width: 44px;
    height: 44px;
  }

  .action-btn {
    width: 58px;
    height: 58px;
  }

  .mini-btn {
    width: 44px;
    height: 40px;
  }
}
