:root {
  --ink: #2d2a32;
  --paper: #f6f0df;
  --paper-2: #fff8e7;
  --wood: #8d5524;
  --wood-dark: #4b3b47;
  --gold: #f6c85f;
  --red: #b13e53;
  --blue: #243b53;
  --shadow: rgba(0, 0, 0, 0.35);
}

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #243b53;
  color: var(--ink);
  font-family: "DotGothic16", monospace;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  min-height: 28px;
  border: 2px solid var(--wood-dark);
  background:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,0.4) 0 1px, transparent 2px),
    linear-gradient(135deg, var(--paper-2), var(--paper));
  color: var(--ink);
  box-shadow: 0 2px 0 var(--wood-dark);
  cursor: pointer;
}

button:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 var(--wood-dark);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

#game {
  position: fixed;
  inset: 0;
  image-rendering: pixelated;
  touch-action: none;
}

.hud {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  align-items: center;
  pointer-events: none;
  z-index: 10;
}

.hud-pill,
.hud-button {
  min-height: 26px;
  padding: 3px 6px;
  border: 2px solid #2b1b14;
  background:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,0.45) 0 1px, transparent 2px),
    linear-gradient(135deg, rgba(255,248,231,0.96), rgba(246,240,223,0.94));
  box-shadow: 0 2px 0 var(--wood-dark);
  white-space: nowrap;
  text-shadow: 0 1px #fff8e7;
}

.hud-pill {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-button {
  margin-left: auto;
  pointer-events: auto;
  width: 32px;
  padding: 0;
}

.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 5px max(7px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(7px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
  background: linear-gradient(180deg, rgba(107,63,36,0.92), rgba(43,27,20,0.94));
  border-top: 2px solid rgba(255, 209, 102, 0.62);
  z-index: 20;
}

.dock-button {
  min-width: 0;
  padding: 3px 2px;
  font-size: 11px;
  line-height: 1.15;
}

.dock-button.active,
.build-card.selected,
.segmented button.active {
  background: var(--gold);
}

.panel,
.inspector {
  position: fixed;
  left: 8px;
  right: 8px;
  z-index: 18;
  border: 3px solid var(--wood-dark);
  background: rgba(255, 248, 231, 0.97);
  box-shadow: 0 6px 0 rgba(75, 59, 71, 0.75);
  max-height: 46vh;
  overflow: hidden;
}

.panel {
  bottom: 54px;
}

.inspector {
  top: 58px;
  right: auto;
  width: min(390px, calc(100vw - 16px));
  padding: 10px;
}

.hidden {
  display: none !important;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 2px solid rgba(75, 59, 71, 0.35);
  background: #f6f0df;
}

.panel-head h2,
.panel-head h3 {
  margin: 0;
  font-size: 16px;
}

.small-button {
  min-height: 28px;
  padding: 2px 8px;
}

.build-grid,
.scroll-list,
.shop-list {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.build-grid {
  max-height: calc(46vh - 46px);
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 8px;
}

.build-card,
.shop-row,
.list-card {
  border: 2px solid var(--wood-dark);
  background: var(--paper-2);
}

.build-card {
  min-height: 74px;
  padding: 6px;
  display: grid;
  gap: 2px;
  text-align: left;
}

.build-card strong,
.list-card strong,
.shop-row strong {
  font-size: 14px;
}

.build-card span,
.list-card span,
.shop-row span,
.build-card small,
.shop-row small {
  font-size: 12px;
}

.premium {
  background: #fff1b8;
}

.scroll-list {
  max-height: calc(46vh - 46px);
  padding: 8px;
  display: grid;
  gap: 8px;
}

.list-card {
  padding: 8px;
}

.list-card p,
.inspector p,
.shop-note {
  margin: 5px 0 0;
  font-size: 13px;
  line-height: 1.45;
}

.diary-page p {
  line-height: 1.65;
}

progress {
  width: 100%;
  height: 12px;
  accent-color: var(--red);
}

.segmented {
  display: flex;
  gap: 4px;
}

.segmented button {
  min-height: 28px;
  padding: 2px 7px;
  font-size: 12px;
}

.shop-note {
  margin: 8px;
  padding: 7px;
  border: 2px dashed var(--wood-dark);
  background: #f6f0df;
}

.shop-list {
  max-height: 22vh;
  padding: 8px;
  display: grid;
  gap: 8px;
}

.shop-row {
  width: 100%;
  min-height: 46px;
  padding: 7px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px;
  align-items: center;
  text-align: left;
}

.shop-row small {
  grid-column: 1 / -1;
}

.setting-row {
  margin: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.building-preview {
  display: block;
  width: 96px;
  height: 72px;
  margin: 8px auto;
  image-rendering: pixelated;
  border: 2px solid var(--wood-dark);
  background: #6fae63;
}

.button-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.button-row button {
  flex: 1 1 94px;
}

.danger {
  border-color: var(--red);
}

.toast-layer {
  position: fixed;
  top: 56px;
  right: 8px;
  z-index: 40;
  display: grid;
  gap: 6px;
  width: min(320px, calc(100vw - 16px));
  pointer-events: none;
}

.toast {
  padding: 8px 10px;
  border: 2px solid var(--wood-dark);
  background: rgba(255, 248, 231, 0.96);
  box-shadow: 0 3px 0 var(--wood-dark);
  animation: toast-in 0.18s steps(2), toast-out 0.3s steps(2) 3.25s forwards;
}

@keyframes toast-in {
  from { transform: translateY(-8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes toast-out {
  to { transform: translateY(-8px); opacity: 0; }
}

.dialogue {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: 76px;
  z-index: 55;
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 8px;
  padding: 10px;
  border: 3px solid var(--wood-dark);
  background: rgba(246, 240, 223, 0.98);
  box-shadow: 0 6px 0 rgba(75, 59, 71, 0.85);
}

.purchase-confirm {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.48);
}

.purchase-dialog {
  width: min(360px, calc(100vw - 32px));
  padding: 14px;
  border: 3px solid var(--wood-dark);
  background: var(--paper-2);
  box-shadow: 0 6px 0 rgba(75, 59, 71, 0.85);
}

.purchase-dialog p {
  margin: 8px 0 12px;
  line-height: 1.45;
}

.portrait {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
  border: 2px solid var(--wood-dark);
  background: var(--paper-2);
}

.dialogue-body strong {
  display: block;
  margin-bottom: 4px;
}

.dialogue-body p {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.55;
}

.spotlight {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.45);
}

.spotlight-text {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 150px;
  padding: 10px;
  border: 3px solid var(--gold);
  background: rgba(255, 248, 231, 0.98);
  box-shadow: 0 4px 0 var(--wood-dark);
  font-size: 14px;
  line-height: 1.5;
}

.spotlight-text.floating {
  bottom: 112px;
}

.arrow {
  text-align: center;
  color: var(--red);
  animation: blink 0.8s steps(2) infinite;
}

.tutorial-target {
  position: relative;
  z-index: 60 !important;
  outline: 4px solid var(--gold);
  animation: blink 0.8s steps(2) infinite;
}

@keyframes blink {
  50% { filter: brightness(1.45); }
}

.empty {
  padding: 12px;
  margin: 0;
}

.fatal {
  padding: 24px;
  color: #f6f0df;
}

@media (max-width: 520px) {
  .hud {
    flex-wrap: wrap;
  }

  .hud-pill {
    font-size: 11px;
    max-width: calc(50vw - 18px);
  }

  /* Keep all six tabs on one row, but make each a comfortable thumb target. */
  .dock {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 3px;
    padding: 6px max(6px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }

  .dock-button {
    min-height: 46px;
    padding: 4px 1px;
    font-size: 11px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
  }

  .panel,
  .inspector {
    bottom: 66px;
    max-height: 52vh;
  }

  .build-grid,
  .scroll-list {
    max-height: calc(52vh - 46px);
  }

  /* Two-across build cards fit small screens without horizontal cramping. */
  .build-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dialogue {
    bottom: 80px;
  }
}

/* Very narrow phones: shrink dock text a touch so labels never clip. */
@media (max-width: 360px) {
  .dock-button {
    font-size: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

button, input, select, textarea {
  font-family: inherit;
}

/* ---- touch quality (mobile) ---- */
* {
  -webkit-tap-highlight-color: transparent;
}

body {
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

button {
  touch-action: manipulation; /* removes 300ms tap delay, prevents double-tap zoom */
}

.dock-button:active,
.build-card:active,
.small-button:active,
.hud-button:active,
.shop-row:active,
.list-card:active {
  transform: scale(0.96);
  filter: brightness(1.08);
}

/* Scrollable lists get momentum + hidden scrollbars for a native feel. */
.build-grid::-webkit-scrollbar,
.scroll-list::-webkit-scrollbar,
.shop-list::-webkit-scrollbar {
  width: 0;
  height: 0;
}

/* Free-tier countdown tag in the HUD date pill. */
.trial-tag {
  display: inline-block;
  margin-left: 4px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--gold);
  color: #4b3b2f;
  font-size: 10px;
}
