/* Reset & base */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: linear-gradient(180deg,#e6dcc3,#cbb992); /* medieval parchment */
  color: #2b1f12;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  overflow: auto; /* allow page scrolling when content exceeds viewport */
  -webkit-overflow-scrolling: touch;
}

/* Canvas fills the viewport properly */
canvas {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  outline: none;
  width: 100vw;
  height: 100vh;
  image-rendering: -moz-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;

  /* Prevent mobile touch behaviors */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
canvas:focus { outline: none; }

/* Utilities */
.hidden { display: none !important; }

/* Game UI - HUD overlay */
.game-ui {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 100;
  pointer-events: none;
  color: #111;
  font-size: 16px;
}
.game-ui .top-row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}
.stat { display:flex; flex-direction:column; gap:6px; width: 13%; }
.stat-label { font-weight:700; font-size:12px; }
.stat-bar { background: rgba(0,0,0,0.08); height: 12px; border-radius: 8px; overflow:hidden; }
.stat-fill { height:100%; background: linear-gradient(90deg,#2b4f7d,#6b4322); width: 50%; transition: width 300ms ease, background 200ms ease; }
.stat-value { font-weight:800; font-size:12px; text-align:right; }
.year { font-weight:900; font-size:18px; width:70px; text-align:right; }

.skills-row { display:flex; gap:10px; margin-top:8px; pointer-events: none; justify-content: flex-start; }
.skill { background: rgba(255,255,255,0.85); padding:6px 10px; border-radius:8px; font-weight:800; font-size:12px; border:1px solid rgba(0,0,0,0.06); }

/* Action buttons top-right */
.action-buttons {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: auto;
  flex-wrap: nowrap;
  max-height: calc(100vh - 24px);
  overflow: auto;
  padding: 8px;
  align-items: flex-end;
  background: transparent;
  -webkit-overflow-scrolling: touch;
  box-shadow: none;
}
.icon-btn {
  min-width: 120px;
  min-height: 72px;
  background: rgba(255,255,255,0.98);
  border-radius: 16px;
  border:1px solid rgba(0,0,0,0.08);
  font-weight:800;
  padding:14px 18px;
  white-space: nowrap;
  text-align:center;
  touch-action: manipulation;
  font-size:18px;
}

.bottom-toolbar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px; /* moved up to make room for choices and provide vertical offset */
  z-index: 300;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 10px;
  pointer-events: auto;
  touch-action: pan-x; /* allow horizontal swipes on the toolbar */
}
.bottom-toolbar-inner {
  display: flex;
  gap: 18px;
  width: 100%;
  align-items: center;
  overflow-x: auto; /* horizontal scrolling */
  -webkit-overflow-scrolling: touch;
  white-space: nowrap;
  padding-bottom: 8px;
  justify-content: flex-start;
}

/* Age button container above toolbar */
.age-container {
  width: 100%;
  display: flex;
  justify-content: center;
  pointer-events: auto;
  margin-bottom: 6px;
}
.age-container .age-btn {
  min-width: 88px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 14px;
}

/* Ensure buttons remain touch-friendly when in a horizontal scroller */
.bottom-toolbar-inner .icon-btn { display: inline-block; margin-right: 18px; }

/* Slightly smaller touch targets for bottom toolbar buttons */
.bottom-toolbar .icon-btn {
  min-width: 110px;
  min-height: 64px;
  padding: 10px 14px;
  font-size: 15px;
  border-radius: 16px;
}

/* Choices */
.choices {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 150px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.choice-btn {
  min-height: 72px; /* larger mobile touch target */
  border-radius: 14px;
  border: 2px solid rgba(0,0,0,0.15);
  background: linear-gradient(180deg,#f6efe0,#e1cfa9);
  padding: 14px 20px;
  font-weight:900;
  font-size:18px;
  text-align:left;
  box-shadow: 0 10px 0 0 rgba(0,0,0,0.08);
  touch-action: manipulation;
}
.choice-btn:active { transform: translateY(2px); box-shadow:none; }
.choice-btn.flash { animation: flash 350ms ease; }
@keyframes flash { 0%{ transform:scale(1); } 50%{ transform:scale(0.98); } 100%{ transform:scale(1); } }

/* Panels (inventory, market, travel, jobs, housing, tavern) */
.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 600;
  width: min(520px, 92vw);
  max-height: 72vh;
  overflow: auto;
  background: linear-gradient(180deg,#fbf5ea,#e6d8bf);
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.4);
  pointer-events: auto;
}
.panel h3 { margin: 0 0 8px 0; }
.inv-list, #market-list, #jobs-list, #home-list, #travel-list, #tavern-list { display:flex; flex-direction:column; gap:8px; }
.inv-item, .market-item, .job-item, .home-item, .travel-item, .tavern-item { display:flex; justify-content:space-between; align-items:center; gap:8px; padding:8px; border-radius:8px; background:rgba(251,245,234,0.95); border:1px solid rgba(58,46,29,0.08); }
.panel-actions { display:flex; justify-content:center; margin-top:12px; gap:8px; }

/* Overlays (Start, Game Over, Loading) */
.screen,
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(0, 0, 0, .6);
}
.screen .screen-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  background: linear-gradient(180deg,#f8f4ea,#e6dbbf);
  padding: 28px;
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.4);
}

/* Titles with overlapping outline/fill */
.title { margin: 0; position: relative; display: inline-block; line-height: 100%; }
.title .title-outline { display: block; font-weight: 950; letter-spacing: .5px; font-size: clamp(16px, 4.5vw, 26px); }
.title .title-fill { display: block; font-weight: 950; letter-spacing: .5px; font-size: clamp(14px, 4vw, 22px); }
.title .title-outline { position: absolute; inset: 0; color: transparent; -webkit-text-stroke-width: 3px; -webkit-text-stroke-color: #8b5e3c; z-index: 0; }
.title .title-fill { color:#3a2b1d; z-index:1; }

/* Buttons */
.btn { cursor: pointer; border: none; padding: 16px 24px; border-radius: 16px; font-weight: 800; display:inline-block; font-size: 18px; min-height: 56px; line-height: 1; }
.btn.primary { border: 3px solid #2b1f12; background: linear-gradient(180deg,#7a4f2a,#2f4a6a); color: #fff; width: auto; padding: 16px 24px; }

/* Loading */
.loading-content { display: flex; flex-direction: column; gap: 12px; width: min(420px, 80vw); }
.loading-bar { width: 100%; height: 12px; border-radius: 999px; background: rgba(0,0,0,.06); overflow: hidden; }
.loading-progress { height: 100%; width: 0%; background: linear-gradient(90deg,#2b4f7d,#6b4322); transition: width .2s ease; }
.loading-text { font-weight: 700; }

/* End summary */
.end-summary { font-weight:700; color:#111; }

/* Small devices adjustments */
@media (max-width: 480px) {
  .stat { width: 22%; }
  .year { font-size: 16px; }
  .choice-btn { font-size:15px; }
  .skills-row { gap:6px; }
  .action-buttons {
    right: 8px;
    top: 8px;
    display: grid;
    grid-template-columns: repeat(2, minmax(64px, 1fr));
    gap: 8px;
    max-height: calc(100vh - 16px);
    overflow: auto;
    align-items: start;
    padding: 6px;
  }
  .icon-btn { min-width: 44px; min-height: 44px; padding:8px 10px; font-size:15px; }
}