:root {
  --primary-color: #2a9d8f;
  --accent-color: #e76f51;
  --bg-color: #f4f4f9;
  --text-color: #264653;
  --essential-bg: #a8dadc;
  --nonessential-bg: #ffe8d6;
  --event-essential-bg: #fff3cd; /* light amber */
  --event-leisure-bg:   #e9f2ff; /* light blue */
  --event-essential-border: #ffb300; /* amber border */
  --event-leisure-border:   #3b82f6; /* blue border */
}
body {
  font-family: Arial, sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
header, footer {
  background: var(--primary-color);
  color: white;
  padding: 1rem;
  text-align: center;
}
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1rem;
}
.tile-pool {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  flex: 1;
  border: 2px dashed rgba(38,70,83,0.3);
  padding: 1.25rem;
  margin-bottom: 1rem;
  overflow: hidden;
  min-height: 0;
  justify-items: center;
}
.tile {
  display: grid;
  grid-template-rows: auto 1fr auto;
  align-items: center;
  justify-items: center;
  width: var(--tile-size, 112px);
  height: var(--tile-size, 112px);
  min-height: var(--tile-size, 112px);
  max-height: var(--tile-size, 112px);
  padding: 0.45rem;
  box-sizing: border-box;
  text-align: center;
  font-size: 0.82rem;
  border-radius: 10px;
  margin: 0.4rem;
  cursor: grab;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  color: var(--text-color);
}

.tile:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}
.tile .icon {
  font-size: 1.75rem;
  margin-bottom: 0.35rem;
}
.tile span, .tile .tile-text {
  word-break: break-word;
  margin-bottom: 0.25rem;
  text-align: center;
}
.tile .cost {
  font-weight: bold;
  font-size: 0.75rem;
  margin-top: auto;
}
.tile.essential {
  border: 2px solid var(--accent-color);
}
.tile.nonessential {
  border: 2px dashed var(--accent-color);
}
.icon {
  margin-right: 0.25rem;
}
#budget-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#budget-dropzone {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 0.5rem;
  flex: 1;
  min-height: 60px;
  background: white;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  padding: 0.75rem;
}
#budget-dropzone .tile {
  transform: scale(0.9);
}

/* Force dark text for selected tiles inside the budget bar */
#budget-dropzone .tile,
#budget-dropzone .tile * {
  color: var(--text-color) !important;
}
#remaining {
  font-size: 1.75rem;
  font-weight: bold;
  background: var(--accent-color);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

/* Optional wrapper around Remaining pill (used by JS moneyFloat) */
.remaining-badge{
  display:inline-flex; align-items:center; gap:.25rem;
  background: var(--accent-color); color:#fff;
  padding:.45rem .9rem; border-radius:999px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  font-weight:700; font-size:1.1rem; position: relative;
}
.remaining-badge #remaining{ background: transparent; box-shadow:none; padding:0; border-radius:0; }

.screen {
  display: none;
}
.screen.active {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
/* Ensure non-active screens are always hidden */
.screen:not(.active) {
  display: none !important;
}

/* Event panels layout */
#event-panels {
  display: flex;
  gap: 1rem;
  padding: 1rem;
}
.event-box {
  flex: 1;
  border: 2px solid var(--text-color);
  padding: 1rem;
  border-radius: 4px;
  min-height: 150px;
  display: flex;
  flex-direction: column;
}
.event-box h3 {
  margin-top: 0;
  margin-bottom: 0.5rem;
  text-align: center;
}
#essential-events {
  background: var(--essential-bg);
}
#leisure-events {
  background: var(--nonessential-bg);
}

/* Event wrapper to allow separation styles */
.event-wrapper {
  padding: 0.25rem;
  border-radius: 6px;
}

.event-box button {
  margin-top: auto;
  align-self: center;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  cursor: pointer;
}
/* Prominent Submit button */
#submit-btn{
  display:inline-flex; align-items:center; gap:.5rem;
  background: var(--primary-color);
  color:#fff; font-weight:700; font-size:1rem;
  padding:.75rem 1.25rem; border:none; border-radius:10px;
  box-shadow: 0 4px 10px rgba(0,0,0,.15);
  cursor:pointer;
}
#submit-btn::before{ content:'\2713'; font-weight:900; }
#submit-btn:hover{ filter: brightness(1.05); box-shadow:0 6px 14px rgba(0,0,0,.2);} 

#tiles-essential-container,
#tiles-leisure-container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-content: flex-start;
  overflow: auto;
  min-height: 0;
  margin-top: -1.25rem;
}

/* Budget screen only when active */
#budget-screen.screen.active {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  overflow: hidden;
}
#budget-screen.screen.active main {
  padding: .75rem 1rem;
  overflow: hidden;
  background: radial-gradient(rgba(0,0,0,.02) 1px, transparent 1px);
  background-size: 18px 18px;
}

#budget-bar {
  --bar-h: 220px;
  position: sticky;
  bottom: 0;
  z-index: 5;
  min-height: var(--bar-h);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: flex-start;
  gap: 1rem;
}
#budget-dropzone {
  height: calc(var(--bar-h) - 2rem);
  overflow: auto;
}

/* Hero / Title Screen */
#start-screen.hero.active {
  background:
    linear-gradient(rgba(0,0,0,0.2), rgba(0,0,0,0.2)),
    url('media/b_b_background.png') no-repeat center center / cover;
  width: 100vw;
  margin-left: calc(50% - 50vw);
  height: 400px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
#start-screen.hero.active .hero-inner {
  background: url('media/b_b_window.png') no-repeat center center / contain;
  border-radius: 16px;
  width: 85%;
  height: 80%;
  position: absolute;
  top: 10%;
  left: 7.5%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Paper overlay & stack */
.paper-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: none;
  align-items: center; justify-content: center;
  z-index: 1000;
}
.paper-stack {
  position: relative;
  width: min(780px, 92vw);
  min-height: 420px;
  padding: 28px;
  padding-bottom: 56px;
  background: #fffef7;
  border: 2px solid #d7c16f;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
  overflow: hidden;
}
.paper-card {
  position: absolute;
  inset: 0;
  padding: 24px;
  background: #fffdfa;
  border: 1px solid #e9e1b2;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,.15);
  transform: translateY(24px) rotate(-0.4deg);
  opacity: 0; pointer-events: none;
  transition: transform .35s ease, opacity .25s ease;
  z-index: 1;
}
.paper-card.active {
  opacity: 1; pointer-events: auto;
  transform: translateY(0) rotate(0deg);
}
.paper-card.title { text-align: center; }
.paper-card h2#paper-title {
  margin: 0 0 6px 0;
}
.paper-card p { margin: .25rem 0 .75rem; }
.paper-card.stack-1 { transform: translate(10px, 10px) rotate(1.2deg); opacity:.35; }
.paper-card.stack-2 { transform: translate(-12px, 14px) rotate(-1.0deg); opacity:.25; }
.paper-options { display: grid; gap: .5rem; margin-top: .75rem; }
.paper-option {
  display:block; text-align:left;
  background:#fff; border:2px solid var(--primary-color);
  border-radius:6px; padding:.55rem .7rem; cursor:pointer;
}
.paper-option.active { background: var(--primary-color); color: #fff; }
.paper-helper { font-size:.9rem; color:#666; margin-top:.5rem; }
.paper-nav {
  display:flex; gap:.5rem; justify-content:flex-end;
  margin-top: 14px;
}
.paper-btn {
  background:#fff; border:2px solid var(--primary-color);
  border-radius:6px; padding:.55rem 1rem; cursor:pointer;
}
.paper-btn[disabled] { opacity:.5; cursor:not-allowed; }
.paper-stack .paper-btn {
  position: absolute;
  bottom: 16px;
  padding: 0;
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
  background: #fff;
  border: 2px solid var(--primary-color);
  border-radius: 999px;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
  z-index: 5;
}
#paper-back.paper-btn { left: 16px; }
#paper-next.paper-btn { right: 16px; }
.paper-stack .paper-btn:hover { filter: brightness(0.98); }
.paper-stack .paper-btn[disabled] { opacity: .5; cursor: not-allowed; }

/* Savings slider container and slider styling */
#savings-slider-container {
  background: white;
  padding: 1rem 1.25rem;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}
#savings-slider {
  -webkit-appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 6px;
  background: var(--primary-color);
  outline: none;
  cursor: pointer;
  box-shadow: inset 0 0 5px rgba(0,0,0,0.1);
}
/* Slider thumb styling */
#savings-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-color);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  border: none;
  margin-top: -7px; /* center thumb vertically */
  transition: background 0.3s ease;
}
#savings-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-color);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  border: none;
  transition: background 0.3s ease;
}
#savings-slider::-webkit-slider-thumb:hover,
#savings-slider::-moz-range-thumb:hover {
  background: #d65a3d;
}

@media (max-height: 820px){
  :root{ --tile-size: 108px; }
  #budget-bar{ --bar-h: 200px; }
}
@media (max-height: 780px){ :root{ --tile-size: 104px; } }
@media (max-height: 720px){
  :root{ --tile-size: 100px; }
  #budget-bar{ --bar-h: 180px; }
}
@media (max-height: 700px){ :root{ --tile-size: 96px; } }
@media (max-width: 900px){
  #tile-pool{ grid-template-columns: 1fr; }
}
/* Budget Header Layout */
.budget-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: linear-gradient(to right, var(--primary-color), #21867a);
  color: white;
  padding: 1.25rem 2rem;
  gap: 1rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.budget-header h1 {
  margin: 0;
  font-size: 1.8rem;
  font-weight: bold;
  text-align: center;
  letter-spacing: 0.5px;
}
.budget-header p {
  margin: 0;
  font-size: 1rem;
  text-align: center;
  opacity: 1;
}

/* Period tracker styling */
#period-tracker {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 0.25rem;
  text-align: center;
}

.budget-header .left,
.budget-header .right {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 1rem;
  align-items: center;
}
.budget-header .icon-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

/* Step indicator styling */
#step-indicator {
  font-size: 1rem;
  font-weight: bold;
  text-align: center;
  margin-bottom: 0.5rem;
  color: var(--primary-color);
}
.tile-section-title {
  font-size: 1.1rem;
  font-weight: bold;
  border-bottom: 2px solid rgba(38,70,83,0.15);
  padding-bottom: 0.25rem;
  margin-bottom: 0.4rem;
  margin-top: -0.5rem;
}

@keyframes tileIn{ from{opacity:0; transform:translateY(6px);} to{opacity:1; transform:translateY(0);} }
@keyframes tileOut{ from{opacity:1; transform:translateY(0);} to{opacity:0; transform:translateY(6px);} }
.tile-anim-in{ animation: tileIn .18s ease-out; }
.tile-anim-out{ animation: tileOut .15s ease-in forwards; }

#remaining.remaining-spend{ animation: spendFlash .4s ease; }
#remaining.remaining-gain{  animation: gainFlash  .4s ease; }
@keyframes spendFlash{ 0%{transform:scale(1)} 30%{transform:scale(1.1)} 100%{transform:scale(1)} }
@keyframes gainFlash{  0%{transform:scale(1)} 30%{transform:scale(1.1)} 100%{transform:scale(1)} }

.money-float{ position: absolute; right: 10px; top: -8px; font-weight:700; }
.money-float.gain{ color:#16a34a; }
.money-float.spend{ color:#dc2626; }
@keyframes floatUp{ from{opacity:0; transform:translateY(6px)} to{opacity:1; transform:translateY(-6px)} }
.money-float{ animation: floatUp .35s ease; }

.tile.event{
  position:relative;
  border:2px solid #1f2937; /* darker edge */
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.5);
  color: var(--text-color);
}
.tile.event::before{
  content:'Event • Auto';
  position:absolute; left:-6px; top:-8px;
  font-size:.7rem; background:#1f2937; color:#fff;
  padding:2px 6px; border-radius:4px;
}

/* Make multi‑cycle (event) tiles pop and always distinct */
.tile.event.essential {
  background: linear-gradient(180deg, var(--event-essential-bg), #ffe9a6) !important;
  border-color: var(--event-essential-border) !important;
  box-shadow: 0 2px 10px rgba(255, 179, 0, 0.18), inset 0 0 0 2px rgba(255,255,255,.55);
}
.tile.event.nonessential {
  background: linear-gradient(180deg, var(--event-leisure-bg), #dbeafe) !important;
  border-color: var(--event-leisure-border) !important;
  box-shadow: 0 2px 10px rgba(59, 130, 246, 0.18), inset 0 0 0 2px rgba(255,255,255,.55);
}

/* Label ribbons by type; falls back to generic if not matched */
.tile.event.essential::before {
  content: 'Essential • Auto';
  background: #8d6b21;
}
.tile.event.nonessential::before {
  content: 'Leisure • Auto';
  background: #0b5db7;
}

/* Multi-cycle tile styling */
.multi-cycle-tile,
[data-multicycle="true"] {
  background-color: #FFF3CD; /* light amber */
  border: 2px solid #FFB300; /* bold amber border */
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* ===== RESULTS SCREEN LAYOUT (no page scroll) ===== */
#results-screen.screen{
  display:grid;
  grid-template-rows:auto 1fr auto; /* header | content | footer */
  height:100dvh;                    /* full viewport height */
  overflow:hidden;                  /* prevent page scrolling */
}

/* Tighten spacing for blocks on Results */
#allocation-summary,
#allocation-progress,
#tracking-table-container{ margin: .75rem 1rem; }

/* Player Progress content area: internal scroll only when needed */
#tracking-table-container{
  overflow:auto;          /* scroll only inside the table block */
  max-height:100%;
  border:1px solid var(--text-color);
  border-radius:8px;
}

/* Tabs under Player Progress title */
#results-tabs{
  position: sticky;       /* stays visible above scrolled table */
  top: 0;                 /* stick to top of the content block */
  z-index: 2;
  background: var(--bg-color);
  padding: .5rem 0 .25rem;
  margin: 0 1rem .5rem;   /* align with content gutters */
}

/* Chart footprint: compact by default; JS may adjust further */
#results-chart-container{
  height: 200px;
  margin: 0 1rem .75rem;
}

/* Keep Next Round in view */
#results-screen #results-next{
  position: sticky;
  bottom: 12px;
  justify-self: center;
  padding:.65rem 1.25rem;
  font-weight:600;
  border-radius:10px;
}

/* Compact mode for short screens */
@media (max-height: 800px){
  #results-chart-container{ height: 170px; }
  #results-screen h2, #results-screen h3{ margin:.4rem 1rem; }
}