:root {
  color-scheme: dark;
  --ink: #f5f0df;
  --muted: #c8c0a8;
  --panel: rgba(24, 29, 32, 0.86);
  --line: rgba(255, 255, 255, 0.16);
  --accent: #f0c45c;
  --green: #65b96b;
  --red: #d66b5d;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  min-height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(110, 178, 130, 0.25), transparent 28%),
    linear-gradient(135deg, #223239, #13191d 52%, #273128);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:hover,
button.active {
  border-color: rgba(240, 196, 92, 0.8);
  background: rgba(240, 196, 92, 0.18);
}

.shell {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 16px;
  width: min(1280px, calc(100vw - 24px));
  height: 100vh;
  min-height: 100vh;
  max-height: 100vh;
  padding: 12px 0;
}

.mobile-menu-toggle,
.side-backdrop {
  display: none;
}

.tablet-nav-toggle { display: none; }
.tablet-panel-toggle { display: none; }
.touch-action-btn,
.radial-tool-menu { display: none; }

.mobile-joystick {
  position: absolute;
  z-index: 11;
  left: calc(var(--mobile-joystick-left) + env(safe-area-inset-left));
  bottom: calc(var(--mobile-joystick-bottom) + env(safe-area-inset-bottom));
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.orientation-hint {
  display: none;
}

.settings-menu {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(8, 12, 14, 0.45);
  backdrop-filter: blur(3px);
}

.settings-menu.open { display: grid; }

.settings-dialog {
  display: grid;
  gap: 14px;
  width: min(360px, 100%);
  max-height: calc(100dvh - 32px);
  padding: 20px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 29, 32, 0.96);
  box-shadow: 0 24px 55px rgba(0, 0, 0, 0.4);
}

.settings-head,
.audio-setting label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.settings-head h2 { margin: 0; }

/* Compact, scrollable kitchen menu using the existing modal visual language. */
.cooking-menu {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(8, 12, 14, 0.45);
  backdrop-filter: blur(3px);
}

.cooking-menu.open { display: grid; }
.cooking-dialog {
  display: grid;
  gap: 12px;
  width: min(390px, 100%);
  max-height: calc(100dvh - 32px);
  padding: 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 29, 32, 0.96);
  box-shadow: 0 24px 55px rgba(0, 0, 0, 0.4);
}
.cooking-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cooking-head h2 { margin: 0; color: var(--accent); }
.cooking-recipes { display: grid; gap: 10px; }
.cooking-recipe { display: grid; gap: 7px; padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: rgba(255, 255, 255, 0.05); }
.cooking-recipe.unavailable { opacity: 0.62; }
.cooking-recipe-title { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.cooking-recipe p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.35; }
.cooking-recipe-meta { display: grid; gap: 3px; color: var(--muted); font-size: 12px; font-weight: 700; }
.cooking-craft-btn { min-height: 42px; }
.cooking-craft-btn:disabled { cursor: not-allowed; opacity: 0.52; }

.audio-setting {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.audio-setting label { grid-column: 1 / -1; }
.audio-setting output { color: var(--accent); }
.audio-setting input { min-width: 0; width: 100%; min-height: 32px; padding: 0; }
.audio-mute-btn { min-width: 72px; }

.progress-goal,
#quest {
  display: grid;
  gap: 1px;
  margin-top: 8px;
  padding: 6px 8px;
  border: 1px solid rgba(240, 196, 92, 0.42);
  border-radius: 6px;
  background: rgba(240, 196, 92, 0.12);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
}

.goal-label { font-size: 10px; font-weight: 800; letter-spacing: 0.04em; }
.goal-text { color: var(--ink); }

.progress-goal.progress-celebrate { animation: progress-celebrate 700ms ease; }

@keyframes progress-celebrate {
  50% { color: #fff0a8; transform: translateY(-1px); }
}

.progress-menu {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(8, 12, 14, 0.45);
  backdrop-filter: blur(3px);
}

.progress-menu.open { display: grid; }

.progress-dialog {
  display: grid;
  gap: 12px;
  width: min(380px, 100%);
  max-height: calc(100dvh - 32px);
  padding: 20px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 29, 32, 0.96);
  box-shadow: 0 24px 55px rgba(0, 0, 0, 0.4);
}

.progress-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.progress-head h2 { margin: 0; }
.progress-village-status { color: var(--muted); font-size: 13px; font-weight: 700; }
.progress-chapter { color: var(--accent); font-size: 15px; font-weight: 800; }
.progress-bar { height: 9px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,0.1); }
.progress-bar-fill { width: 0; height: 100%; border-radius: inherit; background: var(--green); transition: width 300ms ease; }
.progress-tasks { display: grid; gap: 7px; }
.progress-task { color: var(--muted); font-size: 14px; font-weight: 700; }
.progress-task.done { color: var(--green); }
.progress-reward { padding-top: 8px; border-top: 1px solid var(--line); color: var(--accent); font-size: 13px; font-weight: 700; }
.chronicle-dialog { width: min(520px, 100%); }
.chronicle-dialog .progress-head { position: sticky; top: -20px; z-index: 1; padding: 20px 0 10px; margin-top: -20px; background: rgba(24, 29, 32, 0.98); }
.chronicle-entries { display: grid; gap: 10px; }
.chronicle-entry { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.chronicle-entry:last-child { border-bottom: 0; }
.chronicle-day { grid-row: span 2; min-width: 52px; color: var(--accent); font-size: 12px; font-weight: 800; }
.chronicle-title { color: var(--ink); font-size: 14px; font-weight: 800; }
.chronicle-description { color: var(--muted); font-size: 13px; line-height: 1.4; }
.chronicle-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 18px 0; }

/* ── Dorfbuch ── */
.village-book-dialog { width: min(620px, 100%); }
.village-book-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.village-book-tab,
.village-book-figure-list button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 7px 10px;
  cursor: pointer;
}
.village-book-tab { min-height: 38px; }
.village-book-tab:hover,
.village-book-tab.active,
.village-book-figure-list button:hover,
.village-book-figure-list button.active {
  border-color: var(--accent);
  background: rgba(240, 196, 92, 0.14);
  color: var(--accent);
}
.village-book-content { display: grid; gap: 12px; min-height: 220px; }
.village-book-section-title { margin: 0; color: var(--accent); font-size: 17px; }
.village-book-figures { display: grid; grid-template-columns: minmax(120px, 0.45fr) minmax(0, 1fr); gap: 14px; }
.village-book-figure-list { display: grid; align-content: start; gap: 6px; }
.village-book-figure-list button { text-align: left; }
.village-book-resident-button { display: grid; gap: 3px; }
.village-book-resident-summary { color: var(--muted); font-size: 11px; font-weight: 600; line-height: 1.3; }
.village-book-figure-detail,
.village-book-item { padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: rgba(255, 255, 255, 0.035); }
.village-book-figure-detail { display: grid; align-content: start; gap: 10px; }
.village-book-figure-detail h3,
.village-book-item h4 { margin: 0; color: var(--ink); font-size: 15px; }
.village-book-figure-title,
.village-book-day { color: var(--accent); font-size: 12px; font-weight: 800; }
.village-book-figure-detail section { display: grid; gap: 3px; }
.village-book-figure-detail h4 { margin: 0; color: var(--muted); font-size: 12px; }
.village-book-figure-detail p,
.village-book-item p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.42; }
.village-book-list { display: grid; gap: 8px; }
.village-book-item { display: grid; gap: 5px; }
.village-book-item.unknown { opacity: 0.7; }
.village-book-overview { display: grid; gap: 10px; }
.village-book-card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.village-book-stat { padding: 10px 12px; border: 1px solid var(--line); border-radius: 7px; background: rgba(240, 196, 92, 0.055); }
.village-book-info-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 13px; line-height: 1.35; }
.village-book-info-row strong { color: var(--ink); font-size: 14px; text-align: right; }
.village-book-resource-summary,
.village-book-job-summary,
.village-book-detail-facts { display: grid; gap: 7px; }
.village-book-action { min-height: 38px; padding: 8px 10px; border: 1px solid rgba(240, 196, 92, 0.42); border-radius: 6px; background: rgba(240, 196, 92, 0.13); color: var(--accent); font: inherit; font-size: 13px; font-weight: 800; cursor: pointer; }
.village-book-action:hover { border-color: var(--accent); background: rgba(240, 196, 92, 0.22); }

.game-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: #182026;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.developer-teleport-panel {
  position: absolute;
  z-index: 8;
  width: 230px;
  padding: 8px 10px;
  box-sizing: border-box;
  color: #d9ddd4;
  background: rgba(24, 29, 32, 0.96);
  border: 1px solid rgba(214, 180, 108, 0.56);
  border-radius: 6px;
  font: 11px "Segoe UI", sans-serif;
}

.developer-teleport-title {
  margin-bottom: 6px;
  color: #f1dcaa;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.developer-teleport-inputs,
.developer-teleport-quick {
  display: flex;
  gap: 5px;
}

.developer-teleport-inputs label {
  display: flex;
  align-items: center;
  gap: 3px;
  color: #b9c1bc;
  font-weight: 700;
}

.developer-teleport-inputs input {
  width: 38px;
  min-width: 0;
  padding: 4px;
  color: #f5f0df;
  background: rgba(245, 240, 223, 0.09);
  border: 1px solid rgba(214, 180, 108, 0.42);
  border-radius: 3px;
  font: inherit;
}

.developer-teleport-panel button {
  padding: 4px 5px;
  color: #f5f0df;
  background: rgba(214, 180, 108, 0.16);
  border: 1px solid rgba(214, 180, 108, 0.42);
  border-radius: 3px;
  font: 700 10px "Segoe UI", sans-serif;
  cursor: pointer;
}

.developer-teleport-panel button:hover,
.developer-teleport-panel button:focus-visible {
  background: rgba(214, 180, 108, 0.31);
  outline: none;
}

.developer-teleport-quick {
  flex-wrap: wrap;
  margin-top: 6px;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  touch-action: none;
  cursor: crosshair;
}

.hud {
  position: absolute;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  backdrop-filter: blur(10px);
}

.top-left {
  top: 12px;
  left: 12px;
}

.top-right {
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  max-width: calc(100% - 24px);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.brand {
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.1;
}

.stats {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
}

.status-meta,
.status-climate {
  display: grid;
  grid-template-columns: repeat(2, max-content);
  align-items: center;
  gap: 4px 12px;
}

.stats strong { color: var(--ink); font-weight: 800; }

.status-season { color: var(--accent); font-weight: 700; }
.status-weather { font-weight: 700; }
.weather-sunny { color: #f4cf68; }
.weather-cloudy { color: #d8dce0; }
.weather-rain { color: #8bc5e8; }
.weather-fog { color: #b7bec4; }
.weather-snow { color: #dff4ff; }

.status-details {
  display: grid;
  gap: 3px;
}

.status-item {
  display: grid;
  grid-template-columns: 1.2em 72px max-content;
  align-items: baseline;
  column-gap: 5px;
  white-space: nowrap;
}

.status-item b { color: var(--accent); font-weight: 400; text-align: center; }
.status-label { color: var(--muted); }

.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  max-width: min(520px, calc(100% - 28px));
  padding: 10px 14px;
  transform: translateX(-50%);
  border: 1px solid rgba(240, 196, 92, 0.45);
  border-radius: 8px;
  background: rgba(24, 29, 32, 0.92);
  color: var(--ink);
  opacity: 0;
  transition: opacity 160ms ease;
  z-index: 100;
}

.toast.show {
  opacity: 1;
}

.creator {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(8, 12, 14, 0.45);
  backdrop-filter: blur(3px);
}

.creator.open {
  display: grid;
}

.creator-dialog {
  display: grid;
  gap: 12px;
  width: min(360px, 100%);
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 29, 32, 0.96);
  box-shadow: 0 24px 55px rgba(0, 0, 0, 0.4);
}

.creator-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

h2 {
  margin: 0;
  color: var(--accent);
  font-size: 22px;
}

label,
.creator-row {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font: inherit;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch {
  width: 34px;
  height: 34px;
  min-height: 34px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  padding: 0;
}

.swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(240, 196, 92, 0.18);
}

.appearance-options .swatch {
  width: auto;
  min-width: 34px;
  padding: 0 7px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font: 700 11px/1 system-ui, sans-serif;
}

.preview-wrap {
  display: grid;
  place-items: center;
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

#avatarPreview {
  width: 160px;
  height: 150px;
  cursor: default;
}

/* ── Side panel – flex layout ── */
.side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  min-height: 0;
  padding: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(18, 22, 24, 0.9);
  height: 100%;
}

.side-header {
  flex-shrink: 0;
}

h1 {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 22px;
  line-height: 1.1;
}

p {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
  font-size: 13px;
}

.tool-grid {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.tool-grid button {
  display: grid;
  grid-template-columns: 20px 1fr;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 8px;
  text-align: left;
  font-size: 13px;
}

.tool-icon {
  font-size: 18px;
  text-align: center;
}

.save-actions {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.save-actions button {
  min-height: 34px;
  padding: 6px;
  font-size: 12px;
}

/* ── Fixed resources bar ── */
.resources {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
}

.resource-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  text-align: center;
}

.resource-icon {
  font-size: 16px;
  line-height: 1;
}

.resource-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
}

.resource-value {
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  line-height: 1.2;
}

/* ── Scrollable inventory ── */
.inventory {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 6px;
  overflow-y: auto;
  padding-right: 2px;
}

.storage-section {
  display: grid;
  gap: 4px;
}

.storage-title {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  padding: 3px 0;
}

.inventory-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 0;
}

.inventory hr {
  margin: 6px 0;
  border: none;
  border-top: 1px solid var(--line);
}

.item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 13px;
}

.item strong {
  color: var(--ink);
}

.item-food { align-items: center; }
.inventory-eat-btn { min-height: 28px; padding: 3px 7px; font-size: 11px; white-space: nowrap; }

/* ── Help – stays at bottom ── */
.help {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.help-group {
  display: grid;
  align-content: start;
  gap: 4px;
}

.help-group h3 {
  margin: 0;
  color: var(--ink);
  font-size: 11px;
}

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font: 700 11px ui-monospace, monospace;
}

@media (max-width: 1199px) {
  .shell {
    grid-template-columns: minmax(0, 1fr) 250px;
    gap: 10px;
    width: calc(100vw - 16px);
    padding: 8px 0;
  }

  .top-right {
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    scrollbar-width: thin;
  }

  .top-right button {
    flex: 0 0 auto;
    min-width: 44px;
    min-height: 44px;
  }

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

@media (min-width: 768px) and (max-width: 1023px), (min-width: 768px) and (hover: none) and (pointer: coarse) {
  .top-left {
    padding: 7px 10px;
    max-width: calc(100% - 150px);
  }

  .top-left .brand { margin-bottom: 4px; font-size: 16px; }
  .top-left .stats { gap: 4px; font-size: 12px; }
  .top-left .status-details { gap: 2px; }
  .top-left #progressGoal { margin-top: 6px; padding: 5px 7px; font-size: 11px; }

  .top-right {
    top: calc(10px + env(safe-area-inset-top));
    right: calc(10px + env(safe-area-inset-right));
    left: auto;
    max-width: calc(100% - 20px);
    padding: 0;
    gap: 6px;
    overflow: hidden;
    justify-content: flex-end;
    border-color: transparent;
    background: transparent;
    transition: top 240ms ease, left 240ms ease, padding 240ms ease, background-color 240ms ease, border-color 240ms ease;
  }

  .top-right > button:not(.tablet-nav-toggle):not(.tablet-panel-toggle):not(#settingsBtn) {
    min-width: 0;
    width: 0;
    min-height: 40px;
    padding: 0;
    margin: 0;
    border-width: 0;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-8px);
    transition: width 240ms ease, padding 240ms ease, opacity 180ms ease, transform 240ms ease, border-width 240ms ease;
  }

  .tablet-nav-toggle { display: block; }
  .tablet-panel-toggle { display: block; }
  .mobile-menu-toggle { display: none; }

  .top-right.tablet-nav-open {
    top: calc(58px + env(safe-area-inset-top));
    right: calc(10px + env(safe-area-inset-right));
    left: calc(10px + env(safe-area-inset-left));
    max-width: none;
    padding: 7px;
    justify-content: flex-start;
    flex-wrap: wrap;
    border-color: var(--line);
    background: var(--panel);
  }

  .top-right.tablet-nav-open > button:not(.tablet-nav-toggle):not(.tablet-panel-toggle):not(#settingsBtn) {
    width: auto;
    min-width: 44px;
    padding: 8px 12px;
    border-width: 1px;
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }
}

@media (max-width: 1199px) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  body {
    display: block;
  }

  .shell {
    display: block;
    width: 100vw;
    height: 100dvh;
    min-height: 100dvh;
    max-height: none;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }

  .game-panel {
    width: 100%;
    height: 100%;
    border-radius: 0;
  }

  canvas {
    max-width: 100%;
    max-height: 100%;
  }

  .mobile-menu-toggle {
    position: absolute;
    z-index: 9;
    top: calc(10px + env(safe-area-inset-top));
    right: calc(10px + env(safe-area-inset-right));
    display: block;
    min-width: 44px;
    min-height: 44px;
    padding: 8px 10px;
    pointer-events: auto;
  }

  .hud { pointer-events: none; }
  .hud button { pointer-events: auto; }

  .toast {
    right: calc(14px + env(safe-area-inset-right));
    bottom: calc(14px + env(safe-area-inset-bottom));
    left: calc(14px + env(safe-area-inset-left));
    max-width: none;
    transform: none;
    text-align: center;
    overflow-wrap: anywhere;
    pointer-events: none;
  }

  .top-left {
    top: calc(10px + env(safe-area-inset-top));
    left: calc(10px + env(safe-area-inset-left));
    max-width: calc(100% - 120px);
  }

  .top-right {
    top: calc(68px + env(safe-area-inset-top));
    right: 10px;
    left: 10px;
    max-width: none;
    padding: 6px;
    justify-content: flex-start;
    overflow-x: auto;
    flex-wrap: nowrap;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .top-right::-webkit-scrollbar { display: none; }

  .top-right button {
    min-height: 44px;
    padding: 8px 12px;
  }

  .tool-grid button,
  .market-amount-btn,
  .market-sell-btn,
  .market-buy-btn,
  .filter-btn,
  .change-job-btn,
  .job-item {
    min-height: 44px;
  }

  .side-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(8, 12, 14, 0.52);
    pointer-events: none;
  }

  .side-backdrop.open {
    display: block;
    pointer-events: auto;
  }

  .side {
    position: fixed;
    z-index: 41;
    top: 0;
    right: 0;
    width: min(360px, 88vw);
    height: 100dvh;
    min-height: 0;
    padding: calc(14px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) 14px;
    overflow-y: auto;
    border-radius: 10px 0 0 10px;
    transform: translateX(105%);
    transition: transform 180ms ease;
    overscroll-behavior: contain;
    pointer-events: none;
  }

  .side.open {
    transform: translateX(0);
    pointer-events: auto;
  }

  .inventory {
    flex: none;
    overflow: visible;
  }

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

  .creator,
  .settings-menu,
  .progress-menu,
  .market-menu,
  .job-menu,
  .special-npc-lore-menu,
  .building-menu,
  .residents-menu,
  .storage-menu {
    padding: calc(12px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  }

  .creator-dialog,
  .settings-dialog,
  .progress-dialog,
  .market-dialog,
  .job-dialog,
  .building-dialog,
  .town-hall-dialog,
  .residents-dialog,
  .storage-dialog {
    width: min(100%, 420px);
    max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow-y: auto;
  }

  .settings-head,
  .progress-head,
  .market-head,
  .residents-head,
  .storage-head,
  .creator-head {
    position: sticky;
    top: -1px;
    z-index: 1;
    padding: 4px 0 8px;
    background: rgba(24, 29, 32, 0.98);
  }
}

/* ── Market menu – mirrors residents/storage menu ── */
.market-menu {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(8, 12, 14, 0.45);
  backdrop-filter: blur(3px);
  z-index: 10;
}

.market-menu.open {
  display: grid;
}

.market-dialog {
  display: grid;
  gap: 12px;
  width: min(340px, 100%);
  max-height: min(520px, calc(100vh - 80px));
  padding: 20px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 29, 32, 0.96);
  box-shadow: 0 24px 55px rgba(0, 0, 0, 0.4);
}

.market-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.market-dialog h2 {
  margin: 0;
  color: var(--accent);
  font-size: 22px;
}

.market-balance {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.market-balance span {
  color: var(--ink);
  font-weight: 800;
}

.market-section {
  display: grid;
  gap: 8px;
}

.market-section-title {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  padding: 3px 0;
}

.market-resource-card {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
}

.market-resource-header {
  display: flex;
  align-items: center;
  gap: 6px;
}

.market-resource-icon {
  font-size: 18px;
  line-height: 1;
}

.market-resource-name {
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
}

.market-resource-stock {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.market-resource-stock strong {
  color: var(--ink);
  font-weight: 800;
}

.market-amount-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.market-amount-btn {
  min-height: 32px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.market-amount-btn:hover {
  background: rgba(240, 196, 92, 0.12);
  border-color: rgba(240, 196, 92, 0.4);
}

.market-resource-reward,
.market-resource-price {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.market-sell-btn,
.market-buy-btn {
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(240, 196, 92, 0.12);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.market-sell-btn:hover,
.market-buy-btn:hover {
  background: rgba(240, 196, 92, 0.22);
  border-color: rgba(240, 196, 92, 0.6);
}

/* ── Job menu – mirrors market menu ── */
.job-menu {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(8, 12, 14, 0.45);
  backdrop-filter: blur(3px);
  z-index: 20;
}

.job-menu.open {
  display: grid;
}

/* ── Besonderer Bewohner: Lore ── */
.special-npc-lore-menu {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(8, 12, 14, 0.45);
  backdrop-filter: blur(3px);
  z-index: 20;
}

.special-npc-lore-menu.open {
  display: grid;
}

.special-npc-lore-dialog {
  display: grid;
  gap: 12px;
  width: min(360px, 100%);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 29, 32, 0.96);
  box-shadow: 0 24px 55px rgba(0, 0, 0, 0.4);
}

.special-npc-lore-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.special-npc-lore-head h2,
.special-npc-lore-section h3 {
  margin: 0;
  color: var(--accent);
}

.special-npc-lore-head h2 {
  font-size: 22px;
}

.special-npc-lore-title {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.special-npc-lore-section {
  display: grid;
  gap: 4px;
}

.special-npc-lore-section h3 {
  font-size: 13px;
}

.special-npc-lore-section p {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

.job-dialog {
  display: grid;
  gap: 12px;
  width: min(320px, 100%);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 29, 32, 0.96);
  box-shadow: 0 24px 55px rgba(0, 0, 0, 0.4);
}

.job-dialog h2 {
  text-align: center;
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 22px;
}

.job-info {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.job-items {
  display: grid;
  gap: 6px;
}

.job-item {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.job-item:hover {
  background: rgba(240, 196, 92, 0.12);
  border-color: rgba(240, 196, 92, 0.4);
}

.job-item.selected {
  background: rgba(240, 196, 92, 0.18);
  border-color: var(--accent);
  color: var(--accent);
}

.job-item[data-action="close"] {
  color: var(--muted);
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03);
}

.job-item[data-action="close"]:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.job-item[data-action="close"].selected {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.35);
  color: var(--ink);
}

/* ── Building menu ── */
.building-menu {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(8, 12, 14, 0.45);
  backdrop-filter: blur(3px);
  z-index: 20;
}

.building-menu.open {
  display: grid;
}

.building-dialog {
  display: grid;
  gap: 12px;
  width: min(320px, 100%);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 29, 32, 0.96);
  box-shadow: 0 24px 55px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.building-dialog h2 {
  margin: 0;
  color: var(--accent);
  font-size: 22px;
}

.building-info {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.building-info span {
  color: var(--ink);
  font-weight: 800;
}

.town-hall-dialog {
  width: min(380px, 100%);
  text-align: left;
}

.notice-board-dialog {
  width: min(350px, 100%);
  gap: 10px;
  text-align: left;
  border-color: #9c7549;
  background: linear-gradient(145deg, rgba(57, 39, 29, 0.98), rgba(30, 28, 28, 0.98));
}

.notice-board-dialog .creator-head h2 {
  font-size: 20px;
}

.notice-board-intro {
  margin: 0;
  color: #d8c89e;
  font-size: 13px;
  font-style: italic;
}

.notice-board-paper {
  display: grid;
  gap: 8px;
  padding: 13px 14px;
  border: 2px solid #9b7549;
  border-radius: 4px;
  background: linear-gradient(135deg, #ead6a5, #ddc58e);
  box-shadow: inset 0 0 0 2px rgba(104, 70, 37, 0.13), 0 3px 0 rgba(19, 13, 10, 0.24);
  color: #493525;
}

.notice-board-request {
  padding-bottom: 9px;
  border-bottom: 1px dashed rgba(73, 53, 37, 0.42);
  color: #5c3925;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.notice-board-byline {
  display: grid;
  gap: 1px;
  color: #846044;
  font-size: 11px;
  font-weight: 700;
}

.notice-board-byline strong {
  color: #523625;
  font-size: 15px;
  font-weight: 800;
}

.notice-board-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 8px;
  border: 1px solid rgba(105, 73, 43, 0.24);
  border-radius: 4px;
  background: rgba(255, 246, 213, 0.36);
  color: #73533a;
  font-size: 12px;
  font-weight: 700;
}

.notice-board-status strong {
  color: #6c5a45;
  font-weight: 800;
}

.notice-board-status strong::before {
  margin-right: 4px;
}

.notice-board-status strong[data-status="not-started"] { color: #786956; }
.notice-board-status strong[data-status="not-started"]::before { content: "○"; }
.notice-board-status strong[data-status="in-progress"] { color: #8a6632; }
.notice-board-status strong[data-status="in-progress"]::before { content: "◐"; }
.notice-board-status strong[data-status="ready"] { color: #557343; }
.notice-board-status strong[data-status="ready"]::before { content: "●"; }
.notice-board-status strong[data-status="completed"] { color: #4f7b53; }
.notice-board-status strong[data-status="completed"]::before { content: "✓"; }

.notice-board-section {
  display: grid;
  gap: 5px;
  padding-top: 8px;
  border-top: 1px dashed rgba(73, 53, 37, 0.28);
}

.notice-board-section-title {
  color: #765138;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.notice-board-summary {
  padding-top: 7px;
}

.notice-board-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #73533a;
  font-size: 12px;
  font-weight: 700;
}

.notice-board-row strong {
  color: #493525;
  text-align: right;
  font-weight: 800;
}

.request-conversation-dialog {
  width: min(330px, 100%);
  text-align: left;
}

.request-conversation-text {
  margin: 0;
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.5;
}

.request-conversation-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.town-hall-services {
  display: grid;
  gap: 8px;
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.town-hall-services h3 {
  margin: 0;
  color: var(--accent);
  font-size: 14px;
}

.town-hall-service-actions {
  display: grid;
  gap: 8px;
}

.town-hall-next-level {
  display: grid;
  gap: 4px;
  margin-top: 4px;
  padding: 10px;
  border: 1px solid rgba(240, 196, 92, 0.25);
  border-radius: 6px;
  background: rgba(240, 196, 92, 0.08);
  color: var(--muted);
  font-size: 13px;
}

.town-hall-next-level strong {
  color: var(--accent);
}

.building-actions {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.building-action-btn {
  min-height: 42px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.building-action-btn:hover {
  background: rgba(240, 196, 92, 0.12);
  border-color: rgba(240, 196, 92, 0.4);
}

.building-action-btn.demolish {
  color: var(--red);
  border-color: rgba(214, 107, 93, 0.3);
}

.building-action-btn.demolish:hover {
  background: rgba(214, 107, 93, 0.15);
  border-color: rgba(214, 107, 93, 0.6);
}

.building-action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Residents filter ── */
.residents-filter-info {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  min-height: 16px;
}

.residents-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-btn {
  flex: 1 1 auto;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.filter-btn:hover {
  background: rgba(240, 196, 92, 0.12);
  border-color: rgba(240, 196, 92, 0.4);
  color: var(--ink);
}

.filter-btn.active {
  background: rgba(240, 196, 92, 0.18);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Residents menu – mirrors market/job menu ── */
.residents-menu {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(8, 12, 14, 0.45);
  backdrop-filter: blur(3px);
  z-index: 10;
}

.residents-menu.open {
  display: grid;
}

.residents-dialog {
  display: grid;
  grid-template-rows: auto auto auto auto 1fr;
  gap: 12px;
  width: min(340px, 100%);
  max-height: min(520px, calc(100vh - 80px));
  padding: 20px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 29, 32, 0.96);
  box-shadow: 0 24px 55px rgba(0, 0, 0, 0.4);
}

.residents-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.residents-info {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.residents-info span {
  color: var(--ink);
  font-weight: 800;
}

.residents-list {
  display: grid;
  gap: 8px;
  overflow-y: auto;
  padding-right: 4px;
  min-height: 0;
}

.resident-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.resident-card:hover {
  background: rgba(240, 196, 92, 0.12);
  border-color: rgba(240, 196, 92, 0.4);
}

.resident-name {
  color: var(--accent);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.2;
}

.resident-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
}

.resident-meta span {
  color: var(--ink);
  font-weight: 800;
}

.resident-status {
  line-height: 1.3;
}

.resident-status.status-working {
  color: var(--green);
}

.resident-status.status-storage {
  color: #d4a843;
}

.resident-status.status-idle {
  color: #8a8a8a;
}

.resident-status.status-traveling {
  color: #5b9bd5;
}

.resident-status.status-home {
  color: var(--muted);
}

.resident-status.status-unknown {
  color: var(--red);
}

.change-job-btn {
  min-height: 32px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(240, 196, 92, 0.12);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.change-job-btn:hover {
  background: rgba(240, 196, 92, 0.22);
  border-color: rgba(240, 196, 92, 0.6);
}

/* ── Storage menu – mirrors market/job menu ── */
.storage-menu {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(8, 12, 14, 0.45);
  backdrop-filter: blur(3px);
  z-index: 10;
}

.storage-menu.open {
  display: grid;
}

.storage-dialog {
  display: grid;
  gap: 12px;
  width: min(320px, 100%);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 29, 32, 0.96);
  box-shadow: 0 24px 55px rgba(0, 0, 0, 0.4);
}

.storage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.storage-info {
  display: grid;
  gap: 6px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.storage-level,
.storage-capacity {
  padding: 4px 0;
}

.storage-level span,
.storage-capacity span {
  color: var(--ink);
  font-weight: 800;
}

.upgrade-section {
  display: grid;
  gap: 10px;
}

.upgrade-costs {
  display: grid;
  gap: 6px;
}

.upgrade-cost-item {
  display: grid;
  grid-template-columns: auto auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 4px 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 13px;
  font-weight: 600;
}

.upgrade-cost-item .resource-icon {
  grid-row: 1 / 3;
  font-size: 18px;
}

.upgrade-cost-item .resource-label {
  grid-column: 2 / 4;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.upgrade-cost-details {
  grid-column: 2 / 4;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
}

.upgrade-cost-current {
  color: var(--ink);
  font-weight: 800;
}

.upgrade-cost-separator {
  color: var(--muted);
}

.upgrade-cost-required {
  color: var(--muted);
  font-weight: 600;
}

.upgrade-cost-status {
  grid-column: 1 / 4;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  min-height: 16px;
}

.upgrade-cost-status.ready {
  color: var(--green);
}

.upgrade-cost-status.missing {
  color: var(--red);
}

.upgrade-button {
  min-height: 44px;
  border-color: rgba(240, 196, 92, 0.6);
  background: rgba(240, 196, 92, 0.15);
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
  transition: background 120ms ease, border-color 120ms ease;
}

.upgrade-button:hover {
  background: rgba(240, 196, 92, 0.28);
  border-color: var(--accent);
}

.max-level-message {
  text-align: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 1199px) {
  body { display: block; overflow: hidden; }
  .shell {
    display: block;
    width: 100vw;
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  .game-panel { width: 100%; height: 100%; aspect-ratio: unset; border-radius: 0; }
  canvas { max-width: 100%; max-height: 100%; }
  .side {
    position: fixed;
    z-index: 41;
    top: 0;
    right: 0;
    width: min(360px, 88vw);
    height: 100dvh;
    min-height: 0;
    overflow-y: auto;
    transform: translateX(105%);
  }
  .side.open { transform: translateX(0); }
  .side-backdrop.open { display: block; }
  .mobile-menu-toggle { display: block; }
  .help { grid-template-columns: 1fr; }
}

/* Final responsive overrides: kept last so legacy layout rules cannot override touch layout. */
@media (max-width: 767px) {
  body { display: block; overflow: hidden; }
  .shell {
    display: block;
    width: 100vw;
    height: 100dvh;
    min-height: 100dvh;
    max-height: none;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  .game-panel { width: 100%; height: 100%; border-radius: 0; }

  .top-left {
    top: calc(8px + env(safe-area-inset-top));
    left: calc(8px + env(safe-area-inset-left));
    max-width: calc(100% - 116px);
    padding: 6px 8px;
  }
  .brand { margin-bottom: 1px; font-size: 15px; }
  .stats { gap: 3px; font-size: 11px; }
  .status-meta, .status-climate { gap: 2px 8px; }
  .status-details { gap: 2px; }
  .status-item { grid-template-columns: 1.2em 62px max-content; column-gap: 4px; }
  .progress-goal { margin-top: 5px; padding: 4px 6px; font-size: 10px; }
  .goal-label { font-size: 9px; }

  .top-right {
    top: calc(58px + env(safe-area-inset-top));
    right: 8px;
    left: 8px;
    padding: 4px;
  }
  .top-right button {
    min-width: 44px;
    min-height: 44px;
    padding: 6px 9px;
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
  }
  .mobile-menu-toggle {
    top: calc(8px + env(safe-area-inset-top));
    right: calc(8px + env(safe-area-inset-right));
  }

  .orientation-hint {
    position: absolute;
    z-index: 8;
    right: 12px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    left: 12px;
    display: none;
    padding: 8px 12px;
    border: 1px solid rgba(240, 196, 92, 0.42);
    border-radius: 999px;
    background: rgba(24, 29, 32, 0.9);
    color: var(--ink);
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    pointer-events: none;
  }
  .side {
    position: fixed;
    z-index: 41;
    top: 0;
    right: 0;
    width: min(360px, 88vw);
    height: 100dvh;
    min-height: 0;
    padding: calc(14px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) 14px;
    overflow-y: auto;
    border-radius: 10px 0 0 10px;
    transform: translateX(105%);
  }
  .side.open { transform: translateX(0); }
  .side-backdrop.open { display: block; }
  .mobile-menu-toggle { display: block; }
  .creator,
  .market-menu,
  .job-menu,
  .special-npc-lore-menu,
  .building-menu,
  .residents-menu,
  .storage-menu {
    padding: calc(12px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  }
  .creator-dialog,
  .market-dialog,
  .job-dialog,
  .special-npc-lore-dialog,
  .building-dialog,
  .town-hall-dialog,
  .residents-dialog,
  .storage-dialog {
    width: min(100%, 420px);
    max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow-y: auto;
  }
  .village-book-dialog { width: min(100%, 520px); max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overflow-y: auto; }
  .village-book-figures { grid-template-columns: 1fr; }
  .village-book-figure-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .village-book-figure-list button { min-height: 40px; }
}

@media (max-width: 767px) and (orientation: portrait) {
  .orientation-hint {
    display: block;
    animation: orientation-hint-fade 5s ease forwards;
  }
}

@media (max-width: 359px) {
  .status-meta { grid-template-columns: 1fr; }
}

@media (max-width: 1199px) {
  .radial-tool-menu {
    display: block;
    position: absolute;
    z-index: 10;
    right: calc(18px + env(safe-area-inset-right));
    bottom: calc(18px + env(safe-area-inset-bottom));
    width: 60px;
    height: 60px;
    transition: opacity 180ms ease, transform 180ms ease;
  }
  .radial-tool-trigger,
  .radial-tool-option {
    display: grid;
    place-items: center;
    border: 1px solid rgba(226, 210, 163, 0.72);
    color: #fff7df;
    background: rgba(35, 49, 47, 0.9);
    box-shadow: 0 5px 14px rgba(8, 14, 15, 0.35);
  }
  .radial-tool-trigger {
    position: relative;
    z-index: 2;
    width: 60px;
    height: 60px;
    min-width: 56px;
    min-height: 56px;
    padding: 0;
    border-radius: 50%;
    font-size: 27px;
    line-height: 1;
    touch-action: none;
    transition: transform 160ms ease, background-color 160ms ease;
  }
  .radial-tool-menu.is-open .radial-tool-trigger { transform: scale(0.9); }
  .radial-tool-options { position: absolute; inset: 0; pointer-events: none; }
  .radial-tool-option {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 54px;
    height: 54px;
    margin: -27px;
    padding: 2px;
    border-radius: 50%;
    opacity: 0;
    transform: rotate(var(--radial-angle)) translateX(22px) rotate(var(--radial-inverse-angle)) scale(0.55);
    transition: transform 180ms ease, opacity 140ms ease, background-color 120ms ease, box-shadow 120ms ease;
  }
  .radial-tool-option span { font-size: 21px; line-height: 1; }
  .radial-tool-option small { display: none; }
  .radial-tool-menu.is-open .radial-tool-options { pointer-events: auto; }
  .radial-tool-menu.is-open .radial-tool-option {
    opacity: 1;
    transform: rotate(var(--radial-angle)) translateX(88px) rotate(var(--radial-inverse-angle)) scale(1);
  }
  .radial-tool-option.is-highlighted {
    background: #7d9b63;
    border-color: #fff0b5;
    box-shadow: 0 0 0 4px rgba(240, 196, 92, 0.3), 0 6px 18px rgba(8, 14, 15, 0.45);
    transform: rotate(var(--radial-angle)) translateX(92px) rotate(var(--radial-inverse-angle)) scale(1.12);
  }
  .radial-tool-menu.panel-hidden { opacity: 0; pointer-events: none; transform: scale(0.9); }
  .touch-action-btn {
    position: absolute;
    z-index: 10;
    right: calc(18px + env(safe-area-inset-right));
    bottom: calc(18px + env(safe-area-inset-bottom));
    display: grid;
    place-items: center;
    width: 60px;
    height: 60px;
    min-width: 56px;
    min-height: 56px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid rgba(226, 210, 163, 0.72);
    background: rgba(35, 49, 47, 0.8);
    box-shadow: 0 5px 14px rgba(8, 14, 15, 0.35);
    font-size: 27px;
    line-height: 1;
    transition: transform 180ms ease, opacity 180ms ease;
  }
  .touch-action-btn:active { transform: scale(0.92); }
  .touch-action-btn.panel-hidden { opacity: 0; pointer-events: none; transform: scale(0.9); }
}

/* Tablet navigation override: kept last so it does not alter the desktop or phone layouts. */
@media (min-width: 768px) and (max-width: 1023px), (min-width: 768px) and (hover: none) and (pointer: coarse) {
  .top-right {
    top: calc(10px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); left: auto;
    max-width: calc(100% - 20px); padding: 0; gap: 6px; overflow: hidden; justify-content: flex-end;
    border-color: transparent; background: transparent;
    transition: top 240ms ease, left 240ms ease, padding 240ms ease, background-color 240ms ease, border-color 240ms ease;
  }
  .top-left { padding: 7px 10px; max-width: calc(100% - 150px); }
  .top-left .brand { margin-bottom: 4px; font-size: 16px; }
  .top-left .stats { gap: 4px; font-size: 12px; }
  .top-left .status-details { gap: 2px; }
  .top-left #progressGoal { margin-top: 6px; padding: 5px 7px; font-size: 11px; }
  .tablet-nav-toggle { display: block; }
  .tablet-panel-toggle { display: block; }
  .mobile-menu-toggle { display: none; }
  .top-right #tabletNavBtn,
  .top-right #tabletPanelBtn,
  .top-right #settingsBtn {
    display: inline-flex !important;
    flex: 0 0 44px;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    align-items: center;
    justify-content: center;
    opacity: 1;
    pointer-events: auto;
    transform: none;
  }
  .top-right > button:not(.tablet-nav-toggle):not(.tablet-panel-toggle):not(#settingsBtn) { min-width: 0; width: 0; min-height: 40px; padding: 0; margin: 0; border-width: 0; opacity: 0; pointer-events: none; transform: translateY(-8px); transition: width 240ms ease, padding 240ms ease, opacity 180ms ease, transform 240ms ease, border-width 240ms ease; }
  .top-right.tablet-nav-open { top: calc(58px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); left: calc(10px + env(safe-area-inset-left)); max-width: none; padding: 7px; justify-content: flex-start; flex-wrap: wrap; border-color: var(--line); background: var(--panel); }
  .top-right.tablet-nav-open > button:not(.tablet-nav-toggle):not(.tablet-panel-toggle):not(#settingsBtn) { width: auto; min-width: 44px; padding: 8px 12px; border-width: 1px; opacity: 1; pointer-events: auto; transform: translateY(0); }
}

@keyframes orientation-hint-fade {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; visibility: hidden; }
}
