:root {
  --ink: #f2e4cd;
  --muted: #b9a68c;
  --amber: #f0bd7d;
  --amber-deep: #c98a45;
  --bg: #0a0810;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
}

#game {
  display: block;
  position: fixed;
  inset: 0;
}

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 26px;
  background:
    radial-gradient(ellipse at 50% 12%, rgba(130, 76, 38, 0.34), transparent 55%),
    radial-gradient(ellipse at 50% 105%, rgba(84, 52, 26, 0.4), transparent 62%),
    rgba(7, 6, 12, 0.84);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: overlay-in 0.6s ease both;
}

.overlay.hidden { display: none; }

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.card {
  position: relative;
  width: 100%;
  max-width: 620px;
  padding: clamp(28px, 5vw, 52px);
  text-align: center;
  background: linear-gradient(180deg, rgba(33, 25, 31, 0.94), rgba(16, 12, 19, 0.96));
  border: 1px solid rgba(240, 189, 125, 0.16);
  border-radius: 26px;
  box-shadow:
    0 40px 120px rgba(0, 0, 0, 0.66),
    inset 0 1px 0 rgba(255, 235, 205, 0.06);
}

.glow {
  width: 46px;
  height: 46px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #ffe9bd 0%, #ffc977 34%, rgba(255, 160, 70, 0.22) 62%, transparent 72%);
  box-shadow: 0 0 42px 12px rgba(255, 170, 90, 0.26);
  animation: breathe 4.5s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(1.08); opacity: 1; }
}

.kicker {
  margin: 0 0 10px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--amber);
  opacity: 0.85;
}

h1 {
  margin: 0 0 16px;
  font-size: clamp(40px, 8vw, 68px);
  font-weight: 500;
  line-height: 0.98;
  letter-spacing: 0.005em;
  color: #f8eacd;
  text-shadow: 0 0 50px rgba(255, 170, 80, 0.22);
}

.blurb {
  max-width: 440px;
  margin: 0 auto;
  font-size: 16px;
  line-height: 1.62;
  color: var(--muted);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px 18px;
  margin: 26px 0 30px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 12px;
  color: #a9977f;
}

.controls em {
  font-style: normal;
  opacity: 0.5;
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.05);
  color: #ecd9bc;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10.5px;
  line-height: 1.5;
}

.btn {
  padding: 14px 32px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #f7cf92, #d99a55);
  color: #241407;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow:
    0 10px 30px rgba(221, 150, 70, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow:
    0 14px 38px rgba(221, 150, 70, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.btn:active { transform: translateY(0); }

.btn:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 4px;
}

.btn.ghost {
  background: transparent;
  color: var(--amber);
  border: 1px solid rgba(240, 189, 125, 0.3);
  box-shadow: none;
}

.btn.ghost:hover {
  background: rgba(240, 189, 125, 0.07);
  box-shadow: none;
}

.hint {
  margin: 16px 0 0;
  font-size: 12px;
  letter-spacing: 0.03em;
  color: #8d7e69;
}

.row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
  margin: 28px 0 30px;
  text-align: left;
}

.stats div {
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
}

.stats dt {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #a08d74;
}

.stats dd {
  margin: 5px 0 0;
  font-size: 22px;
  color: #f4e2c3;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 520px) {
  .card { padding: 26px 20px; }
  .stats { grid-template-columns: 1fr; }
  .controls { gap: 8px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .overlay { animation: none; }
  .glow { animation: none; }
}

/* keep tall cards usable on short screens */
.overlay { overflow-y: auto; }
@media (max-height: 740px) {
  .overlay { align-items: start; }
}

/* ---------- phones & touch ---------- */

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

canvas {
  touch-action: none;
}

#safe-probe {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  visibility: hidden;
  pointer-events: none;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

.overlay {
  padding-top: max(26px, env(safe-area-inset-top));
  padding-right: max(26px, env(safe-area-inset-right));
  padding-bottom: max(26px, env(safe-area-inset-bottom));
  padding-left: max(26px, env(safe-area-inset-left));
}

.btn {
  min-height: 48px;
  touch-action: manipulation;
}

.touch {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: none;
  pointer-events: none;
}

.touch.show { display: block; }

.dpad {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 54px);
  gap: 6px;
  pointer-events: none;
}

.dpad .up { grid-column: 2; grid-row: 1; }
.dpad .left { grid-column: 1; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }
.dpad .down { grid-column: 2; grid-row: 3; }

.actions {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}

.tbtn {
  appearance: none;
  -webkit-appearance: none;
  width: 54px;
  height: 54px;
  padding: 0;
  display: grid;
  place-items: center;
  pointer-events: auto;
  border: 1px solid rgba(255, 235, 205, 0.18);
  border-radius: 15px;
  background: rgba(18, 13, 24, 0.64);
  color: rgba(246, 232, 208, 0.92);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  transition: transform 0.08s ease, background 0.08s ease, border-color 0.08s ease;
}

.tbtn.pressed {
  transform: scale(0.92);
  background: rgba(240, 189, 125, 0.22);
  border-color: rgba(240, 189, 125, 0.5);
}

.actions .act {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  font-size: 10px;
  letter-spacing: 0.12em;
}

.actions .primary {
  width: 70px;
  height: 70px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, #f6cd8f, #d99a55);
  color: #241407;
  font-size: 10.5px;
  font-weight: 700;
  box-shadow:
    0 10px 28px rgba(220, 150, 70, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

#touch-tea {
  color: #c9e0b5;
  border-color: rgba(160, 200, 140, 0.28);
}

.touch-note {
  display: none;
  max-width: 370px;
  margin: 18px auto 26px;
  color: #c3b096;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 12.5px;
  line-height: 1.65;
}

.touch-note b {
  color: var(--amber);
  font-weight: 600;
}

@media (hover: none) and (pointer: coarse) {
  .keyboard-controls { display: none; }
  .touch-note { display: block; }
}

@media (max-width: 520px) {
  .overlay {
    padding-top: max(16px, env(safe-area-inset-top));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    padding-left: max(16px, env(safe-area-inset-left));
  }

  .card { padding: 28px 22px; border-radius: 22px; }

  h1 { font-size: clamp(38px, 12vw, 54px); }

  .blurb { font-size: 15px; }

  #begin { width: 100%; max-width: 320px; }

  .row .btn { flex: 1 1 170px; }
}

@media (max-width: 380px) {
  .dpad {
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(3, 48px);
    gap: 5px;
  }

  .actions .act { width: 56px; height: 56px; }
  .actions .primary { width: 62px; height: 62px; }
}

@media (max-height: 500px) {
  .dpad {
    grid-template-columns: repeat(3, 46px);
    grid-template-rows: repeat(3, 46px);
    gap: 4px;
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  .actions { bottom: max(14px, env(safe-area-inset-bottom)); }
  .actions .act { width: 54px; height: 54px; }
  .actions .primary { width: 60px; height: 60px; }
}

/* grid -> flex so tall cards top-align and scroll instead of clipping */
.overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow-y: auto;
}

.card {
  margin: auto 0;
  flex: 0 0 auto;
}

.dpad .tbtn {
  width: 100%;
  height: 100%;
}

/* ---------- companion dialog ---------- */

.dialog {
  z-index: 20;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(110, 70, 45, 0.25), transparent 60%),
    rgba(7, 6, 12, 0.62);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.pet-card {
  max-width: 500px;
  border-color: rgba(240, 189, 125, 0.24);
}

.pet-card h2,
.fire-card h2,
.shop-card h2,
.favor-card h2,
.journal-card h2,
.meta-card h2 {
  margin: 0 0 14px;
  font-size: clamp(30px, 6vw, 46px);
  font-weight: 500;
  line-height: 1.05;
  color: #f8eacd;
  text-shadow: 0 0 40px rgba(255, 170, 80, 0.2);
}

.pet-card .blurb {
  max-width: 400px;
}

.pet-card .row {
  margin-top: 28px;
}

.pet-card .hint {
  margin-top: 18px;
}

/* ---------- campfire brewing ---------- */

.fire-card {
  max-width: 540px;
}

.brew-list {
  display: grid;
  gap: 8px;
  margin: 22px 0 6px;
}

.brew-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1px 14px;
  align-items: center;
  padding: 12px 15px;
  text-align: left;
  border: 1px solid rgba(255, 235, 205, 0.1);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.brew-row:hover:not(:disabled) {
  background: rgba(240, 189, 125, 0.09);
  border-color: rgba(240, 189, 125, 0.28);
}

.brew-row:active:not(:disabled) {
  transform: scale(0.99);
}

.brew-row:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.brew-name {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 17px;
  color: #f4e3c4;
}

.brew-effect {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 11px;
  letter-spacing: 0.02em;
  color: #b9a68c;
}

.brew-cost {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 10.5px;
  line-height: 1.5;
  text-align: right;
  color: #d8b88a;
}

.brew-row.short .brew-cost {
  color: #e08a7a;
}

.brew-note {
  min-height: 18px;
  margin: 6px 0 18px;
  font-size: 13px;
  color: #d8c3a4;
}

@media (max-width: 520px) {
  .brew-row {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .brew-cost {
    grid-column: 1;
    grid-row: auto;
    text-align: left;
    margin-top: 3px;
  }
}

/* ---------- merchant & favors ---------- */

.shop-card,
.favor-card {
  max-width: 540px;
}

.shop-list {
  display: grid;
  gap: 8px;
  margin: 20px 0 22px;
}

.shop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 235, 205, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
}

.shop-row.sold {
  opacity: 0.45;
}

.shop-item-name {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 16px;
  color: #f4e3c4;
}

.shop-item-desc {
  margin-top: 2px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 10.5px;
  color: #b9a68c;
}

.shop-buy {
  flex: 0 0 auto;
  min-width: 64px;
  padding: 9px 13px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #f6cd8f, #d99a55);
  color: #241407;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 11px;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
}

.shop-buy:disabled {
  background: rgba(255, 255, 255, 0.08);
  color: #8d7e69;
  cursor: not-allowed;
}

.favor-track {
  height: 8px;
  margin: 20px 0 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

#favor-bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #c98a45, #ffd89a);
  transition: width 0.3s ease;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.favor-card .hint {
  margin: 10px 0 22px;
}

@media (max-width: 520px) {
  .shop-row { gap: 8px; }
  .shop-buy { min-width: 54px; padding: 9px 10px; }
}

/* ---------- sunroom meta ---------- */

.sunroom-link {
  display: block;
  margin: 10px auto 0;
  padding: 10px 22px;
  font-size: 13px;
}

.meta-card {
  max-width: 560px;
  max-height: 86vh;
  overflow-y: auto;
  background: linear-gradient(180deg, #221a21, #110d14);
}

.meta-tabs {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin: 16px 0 14px;
}

.meta-panel.hidden {
  display: none;
}

#home-canvas {
  display: block;
  width: 100%;
  max-width: 480px;
  height: auto;
  margin: 0 auto;
  border-radius: 14px;
  background: #120d16;
}

.decor-list {
  display: grid;
  gap: 10px;
  margin: 16px 0 10px;
  text-align: left;
}

.decor-slot {
  display: grid;
  gap: 6px;
}

.decor-label {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #a08d74;
}

.decor-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.decor-chip {
  padding: 7px 11px;
  border: 1px solid rgba(255, 235, 205, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.035);
  color: #cbb89e;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 10.5px;
  cursor: pointer;
}

.decor-chip.selected {
  border-color: rgba(240, 189, 125, 0.4);
  background: rgba(240, 189, 125, 0.16);
  color: #f4e3c4;
}

.decor-chip:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.unlock-list {
  display: grid;
  gap: 8px;
  margin: 20px 0 12px;
}

.meta-card .hint {
  min-height: 18px;
  margin: 4px 0 18px;
}

/* ---------- journal ---------- */

.journal-btn {
  position: absolute;
  top: max(58px, env(safe-area-inset-top));
  right: max(18px, env(safe-area-inset-right));
  width: auto;
  min-width: 68px;
  height: 38px;
  padding: 0 14px;
  border-radius: 19px;
  font-size: 9px;
  letter-spacing: 0.14em;
}

.journal-card {
  max-width: 660px;
  max-height: 86vh;
  overflow-y: auto;
}

.journal-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin: 18px 0 16px;
}

.tab {
  padding: 8px 14px;
  border: 1px solid rgba(255, 235, 205, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.035);
  color: #b9a68c;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.tab.active {
  background: rgba(240, 189, 125, 0.16);
  border-color: rgba(240, 189, 125, 0.35);
  color: #f4e3c4;
}

.journal-body {
  min-height: 220px;
  text-align: left;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 12.5px;
  line-height: 1.5;
  color: #cbb89e;
}

.journal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.journal-stat {
  padding: 9px 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}

.journal-stat span {
  display: block;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #a08d74;
}

.journal-stat strong {
  display: block;
  margin-top: 3px;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 20px;
  font-weight: 500;
  color: #f4e2c3;
}

.journal-section {
  margin: 16px 0 6px;
}

.journal-section h3 {
  margin: 0 0 7px;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 16px;
  font-weight: 500;
  color: #f0dfc0;
}

.journal-entry {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 10px;
  margin-bottom: 5px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.022);
}

.journal-entry.unknown {
  opacity: 0.36;
}

.journal-entry .name {
  color: #e9d7ba;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 14px;
}

.journal-entry .tag {
  color: #a08d74;
  font-size: 10px;
  letter-spacing: 0.03em;
  text-align: right;
}

@media (min-width: 760px) {
  .journal-btn {
    top: 140px;
  }
}

/* ---------- settings ---------- */

.settings-panel {
  display: grid;
  gap: 8px;
  margin: 4px 0 10px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.025);
}

.setting-label {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 14px;
  color: #e9d7ba;
}

.setting-desc {
  margin-top: 2px;
  font-size: 10px;
  color: #a08d74;
}

.setting-row input[type="range"] {
  flex: 0 0 160px;
  accent-color: #d99a55;
}

.toggle {
  flex: 0 0 auto;
  min-width: 58px;
  padding: 7px 12px;
  border: 1px solid rgba(255, 235, 205, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: #b9a68c;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.toggle.on {
  background: linear-gradient(180deg, #f6cd8f, #d99a55);
  border-color: transparent;
  color: #241407;
}

body.high-contrast .journal-entry,
body.high-contrast .journal-stat,
body.high-contrast .setting-row,
body.high-contrast .shop-row {
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.06);
}

body.high-contrast .journal-entry .name,
body.high-contrast .setting-label {
  color: #fff6e6;
}

body.high-contrast .tab.active {
  background: #f0bd7d;
  border-color: #f0bd7d;
  color: #1a1014;
}

body.high-contrast .journal-entry.unknown {
  opacity: 0.55;
}
