/* ===========================================================================
   Stable Keeper - styles
   Retro-but-cute layout: square corners, chunky borders, hard offset shadows.
   Four switchable themes (Western / English / Farmhouse / Unicorn) built from
   the "Pro Color Palette 2026" shades. Each theme sets its own matching fonts.
   =========================================================================== */

/* ---- default theme variables (Western) ------------------------------------ */
:root {
  --bg:        #ebdaba;
  --bg-2:      #e0cca6;
  --panel:     #fbf1db;
  --panel-2:   #f3e6c8;
  --ink:       #43301c;
  --ink-soft:  #7a6242;
  --line:      #5c4126;
  --accent:    #b0703c;   /* Safari Sun */
  --accent-ink:#fff7e9;
  --accent-2:  #e6c152;   /* Gold Strand */
  --danger:    #c23b2e;   /* Chuckles */
  --danger-ink:#fff;
  --shadow-ink:#43301c;
  --gauge-bg:  #e3d2ae;

  --font-head: "Rye", "Bitter", serif;
  --font-body: "Bitter", Georgia, serif;
  --font-num:  "VT323", "Bitter", monospace;

  --border-w: 3px;
  --hard:    4px 4px 0 var(--shadow-ink);
  --hard-lg: 6px 6px 0 var(--shadow-ink);
  --hard-sm: 3px 3px 0 var(--shadow-ink);
}

/* ---- English: slate classic, pro serif fonts ------------------------------ */
[data-theme="english"] {
  --bg:        #dde3e4;
  --bg-2:      #ccd6d8;
  --panel:     #fafbf9;
  --panel-2:   #eef1f1;
  --ink:       #2b2a27;   /* Subway */
  --ink-soft:  #5e6b6e;
  --line:      #3d4e52;
  --accent:    #3f608b;   /* Honky Tonk Blue */
  --accent-ink:#fff;
  --accent-2:  #587578;   /* Bowman Blue */
  --danger:    #b23b2f;
  --danger-ink:#fff;
  --shadow-ink:#2b2a27;
  --gauge-bg:  #d6dedf;

  --font-head: "Playfair Display", Georgia, serif;
  --font-body: "Lora", Georgia, serif;
  --font-num:  "Lora", Georgia, serif;
}

/* ---- Farmhouse: warm, cozy, white ----------------------------------------- */
[data-theme="farmhouse"] {
  --bg:        #edeadd;   /* Whitewash */
  --bg-2:      #e4decb;
  --panel:     #fffdf6;
  --panel-2:   #f5f0e2;
  --ink:       #3b352b;
  --ink-soft:  #7c6f58;
  --line:      #6e5b45;   /* Terra Pin */
  --accent:    #5e9e5f;   /* Wildness Mint */
  --accent-ink:#fff;
  --accent-2:  #d6c2a1;   /* Baguette */
  --danger:    #c5503c;
  --danger-ink:#fff;
  --shadow-ink:#6e5b45;
  --gauge-bg:  #e7e0cf;

  --font-head: "Fraunces", Georgia, serif;
  --font-body: "Karla", system-ui, sans-serif;
  --font-num:  "Karla", system-ui, sans-serif;
}

/* ---- Unicorn: pink pastels ------------------------------------------------ */
[data-theme="unicorn"] {
  --bg:        #fbe7f0;
  --bg-2:      #f3d9ec;
  --panel:     #fff8fc;
  --panel-2:   #fbeaf4;
  --ink:       #5a2e5e;
  --ink-soft:  #9a6aa0;
  --line:      #c07fd0;
  --accent:    #e87aa8;
  --accent-ink:#fff;
  --accent-2:  #9aa6e6;   /* Calamities / Luna mix */
  --danger:    #e0566f;
  --danger-ink:#fff;
  --shadow-ink:#9a5fae;
  --gauge-bg:  #f1dcec;

  --font-head: "Pixelify Sans", system-ui, sans-serif;
  --font-body: "Quicksand", system-ui, sans-serif;
  --font-num:  "VT323", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background:
    repeating-linear-gradient(0deg, transparent 0 38px, rgba(0,0,0,0.012) 38px 39px),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font-body);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-family: var(--font-head); font-weight: 800; }
p { margin: 0; }

/* ---------------------------------------------------------------- Topbar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: var(--border-w) solid var(--ink);
  box-shadow: 0 4px 0 rgba(0,0,0,0.08);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  font-size: 26px;
  background: var(--accent);
  color: var(--accent-ink);
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border: var(--border-w) solid var(--ink);
  box-shadow: var(--hard-sm);
}
.brand h1 { font-size: 24px; color: var(--ink); line-height: 1; }
.tagline { font-size: 12px; color: var(--ink-soft); margin-top: 3px; letter-spacing: .02em; }

.resources { display: flex; gap: 10px; margin-left: auto; flex-wrap: wrap; }
.res {
  display: grid;
  grid-template-columns: auto auto; grid-template-rows: auto auto;
  align-items: center; column-gap: 8px;
  background: var(--panel-2);
  border: var(--border-w) solid var(--ink);
  box-shadow: var(--hard-sm);
  padding: 7px 13px; min-width: 90px;
}
.res-icon { font-size: 22px; grid-row: 1 / span 2; }
.res-val { font-family: var(--font-num); font-weight: 800; font-size: 26px; line-height: .8; }
.res-label { font-size: 10.5px; color: var(--ink-soft); grid-column: 2; text-transform: uppercase; letter-spacing: .06em; }

.topbar-actions { display: flex; gap: 8px; align-items: stretch; }

/* theme dropdown */
.theme-pick {
  display: flex; flex-direction: column; justify-content: center;
  border: var(--border-w) solid var(--ink); background: var(--panel-2);
  box-shadow: var(--hard-sm); padding: 4px 10px; cursor: pointer;
}
.theme-pick-lbl { font-size: 9.5px; letter-spacing: .12em; color: var(--ink-soft); font-weight: 700; }
#themeSelect {
  border: none; background: transparent; font-family: var(--font-body);
  font-weight: 700; font-size: 14px; color: var(--ink); cursor: pointer; padding: 2px 0;
}
#themeSelect:focus { outline: none; }

/* ---------------------------------------------------------------- Buttons */
.btn {
  font-family: var(--font-head); font-size: 14px; font-weight: 800;
  letter-spacing: .01em;
  border: var(--border-w) solid var(--ink);
  background: var(--panel);
  color: var(--ink);
  padding: 9px 16px;
  cursor: pointer;
  box-shadow: var(--hard-sm);
  transition: transform .05s ease, box-shadow .05s ease, filter .12s ease;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.03); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--shadow-ink); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-danger  { background: var(--danger); color: var(--danger-ink); }
.btn-ghost   { background: var(--panel-2); padding-left: 12px; padding-right: 12px; }
.btn:disabled { opacity: .42; cursor: not-allowed; transform: none; box-shadow: var(--hard-sm); filter: none; }

.icon-btn {
  border: none; background: transparent; font-size: 24px; line-height: 1;
  color: var(--ink-soft); cursor: pointer; padding: 2px 8px;
}
.icon-btn:hover { color: var(--ink); }

/* ---------------------------------------------------------------- Layout */
main { max-width: 1240px; margin: 0 auto; padding: 24px 22px; }

.herd-summary { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 20px; }
.summary-card {
  background: var(--panel);
  border: var(--border-w) solid var(--ink);
  box-shadow: var(--hard);
  padding: 12px 18px; flex: 1 1 150px;
}
.summary-card .big { font-family: var(--font-num); font-size: 34px; font-weight: 800; line-height: .9; }
.summary-card .lbl { font-size: 11.5px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .07em; margin-top: 4px; }

/* ---------------------------------------------------------------- Stable grid */
.stable-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(335px, 1fr)); gap: 20px; }

.horse-card {
  background: var(--panel);
  border: var(--border-w) solid var(--ink);
  box-shadow: var(--hard-lg);
  display: flex; flex-direction: column; position: relative;
}
.horse-card.attention { box-shadow: 5px 5px 0 var(--danger), var(--hard-lg); }

.card-top { display: flex; gap: 14px; align-items: center; padding: 14px 14px 8px; }
.sprite-stage {
  width: 100px; height: 100px; flex: none;
  display: grid; place-items: end center;
  background:
    repeating-linear-gradient(45deg, rgba(0,0,0,0.04) 0 6px, transparent 6px 12px),
    var(--panel-2);
  border: var(--border-w) solid var(--ink);
  overflow: hidden;
}
.sprite-canvas {
  width: 92px; height: 92px;
  image-rendering: pixelated; image-rendering: crisp-edges;
  animation: bob 2.4s steps(2, end) infinite;
}
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

.card-id { min-width: 0; flex: 1; }
.card-id h3 { font-size: 21px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-id .breed { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.rating-pill {
  display: inline-block; margin-top: 7px;
  font-family: var(--font-num); font-weight: 800; font-size: 14px;
  background: var(--accent-2); color: var(--ink);
  padding: 2px 10px; border: 2px solid var(--ink);
}
.badge {
  position: absolute; top: -3px; right: -3px;
  background: var(--danger); color: var(--danger-ink);
  font-family: var(--font-head); font-size: 10.5px; font-weight: 800;
  padding: 5px 9px; border: var(--border-w) solid var(--ink); box-shadow: var(--hard-sm);
  text-transform: uppercase; letter-spacing: .04em;
}

/* ---------------------------------------------------------------- Bars (segmented retro meters) */
.bars { padding: 4px 14px 8px; display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 92px 1fr 34px; align-items: center; gap: 8px; }
.bar-row .bl { font-size: 11.5px; color: var(--ink-soft); display: flex; align-items: center; gap: 5px; font-weight: 700; }
.bar-track {
  position: relative; height: 14px; background: var(--gauge-bg);
  border: 2px solid var(--ink); overflow: hidden;
}
.bar-fill { height: 100%; transition: width .35s steps(10, end); }
/* notches give the meter a chunky pixel-segment look on any theme */
.bar-track::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(90deg, transparent 0 9px, var(--panel) 9px 11px);
  opacity: .55;
}
.bar-row .bv { font-family: var(--font-num); font-size: 16px; font-weight: 800; text-align: right; color: var(--ink); }

/* ---------------------------------------------------------------- Actions */
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 8px 14px 14px; margin-top: auto; }
.act {
  border: 2px solid var(--ink); background: var(--panel-2);
  padding: 8px 6px 6px; cursor: pointer; text-align: center;
  font-family: var(--font-body); box-shadow: var(--hard-sm);
  transition: transform .05s ease, box-shadow .05s ease, background .12s;
}
.act:hover { background: var(--panel); }
.act:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--shadow-ink); }
.act:disabled { opacity: .38; cursor: not-allowed; transform: none; box-shadow: var(--hard-sm); }
.act .ai { font-size: 20px; display: block; line-height: 1.15; }
.act .al { font-size: 10.5px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .03em; }
.act.groom { grid-column: 1 / -1; background: var(--accent-2); }
.act.groom .ai { font-size: 22px; }
.act.groom .al { color: var(--ink); }

/* ---------------------------------------------------------------- Empty / footer */
.empty-state {
  text-align: center; padding: 60px 24px; color: var(--ink-soft);
  background: var(--panel); border: var(--border-w) dashed var(--ink); box-shadow: var(--hard-lg);
}
.empty-art { font-size: 60px; }
.empty-state h2 { color: var(--ink); margin: 10px 0 6px; }
.empty-state .btn { margin-top: 18px; }
.sitefoot { text-align: center; color: var(--ink-soft); font-size: 12px; padding: 26px 16px 40px; letter-spacing: .02em; }

/* ---------------------------------------------------------------- Floating points + toast */
.float-layer { position: fixed; inset: 0; pointer-events: none; z-index: 60; }
.floaty {
  position: absolute; font-family: var(--font-num); font-weight: 800; font-size: 22px;
  color: var(--accent); text-shadow: 2px 2px 0 var(--ink);
  animation: floatUp .9s steps(8, end) forwards;
}
@keyframes floatUp { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-48px); } }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: var(--panel);
  padding: 11px 18px; border: var(--border-w) solid var(--ink); box-shadow: var(--hard);
  z-index: 80; font-family: var(--font-body); font-weight: 700; font-size: 14px;
}

/* ---------------------------------------------------------------- Modals */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 14, 8, 0.5);
  display: grid; place-items: center; z-index: 100; padding: 18px;
}
/* the hidden attribute must win over the display:grid above */
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--panel);
  width: min(560px, 100%); max-height: 90vh; overflow: auto;
  border: var(--border-w) solid var(--ink); box-shadow: var(--hard-lg);
}
.modal-narrow { width: min(420px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: var(--border-w) solid var(--ink); background: var(--panel-2); }
.modal-head h2 { font-size: 20px; color: var(--ink); }
.modal-body { padding: 18px; display: grid; gap: 14px; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-top: var(--border-w) solid var(--ink); }
.spacer { flex: 1; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 12px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .05em; }
.field input, .field textarea, .field select {
  font-family: var(--font-body); font-size: 15px; color: var(--ink);
  border: 2px solid var(--ink); padding: 10px 12px; background: var(--panel); resize: vertical;
}
.field select { cursor: pointer; }
.field input:focus, .field textarea:focus, .field select:focus { outline: 3px solid var(--accent); outline-offset: -1px; }

.sprite-gallery {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px; max-height: 270px; overflow: auto; padding: 8px;
  background: var(--panel-2); border: 2px solid var(--ink);
}
.swatch {
  background:
    repeating-linear-gradient(45deg, rgba(0,0,0,0.04) 0 6px, transparent 6px 12px),
    var(--panel);
  border: 2px solid var(--ink); padding: 3px; cursor: pointer;
  display: grid; place-items: center; transition: transform .06s;
}
.swatch:hover { transform: translate(-1px, -1px); box-shadow: var(--hard-sm); }
.swatch.sel { outline: 3px solid var(--accent); box-shadow: var(--hard-sm); }
.swatch canvas { width: 54px; height: 54px; image-rendering: pixelated; }
.gallery-group-label { grid-column: 1 / -1; font-size: 11px; font-weight: 800; color: var(--ink-soft); padding: 6px 2px 0; text-transform: uppercase; letter-spacing: .06em; }

/* ---------------------------------------------------------------- Shop */
.shop-balance { font-size: 15px; color: var(--ink-soft); }
.shop-balance strong { font-family: var(--font-num); font-size: 20px; color: var(--ink); }
.shop-list { display: grid; gap: 10px; }
.shop-item {
  display: flex; align-items: center; gap: 14px;
  border: 2px solid var(--ink); padding: 11px 14px; background: var(--panel-2); box-shadow: var(--hard-sm);
}
.shop-item .si-icon { font-size: 30px; width: 40px; text-align: center; }
.shop-item .si-info { flex: 1; min-width: 0; }
.shop-item .si-info b { font-family: var(--font-head); font-size: 15px; }
.shop-item .si-info p { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.shop-item .si-cost { font-family: var(--font-num); font-weight: 800; font-size: 18px; color: var(--ink); white-space: nowrap; }

.settings-actions { display: grid; gap: 10px; margin: 4px 0 14px; }
.muted { color: var(--ink-soft); font-size: 13.5px; }
.muted.small { font-size: 12.5px; }

/* ---------------------------------------------------------------- Calendar / Journal */
.modal-cal { width: min(680px, 100%); }
.cal-nav { display: flex; align-items: center; gap: 8px; }
.cal-nav .cal-month { font-family: var(--font-head); font-size: 20px; font-weight: 800; flex: 1; text-align: center; }
.cal-nav .btn-ghost { font-size: 22px; padding: 4px 14px; line-height: 1; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-dow {
  text-align: center; font-size: 11px; font-weight: 800; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .04em; padding: 2px 0;
}
.cal-cell {
  position: relative; min-height: 46px; cursor: pointer;
  border: 2px solid var(--ink); background: var(--panel-2);
  display: flex; align-items: flex-start; justify-content: flex-start;
  transition: transform .05s, background .12s;
}
.cal-cell.empty { border: none; background: transparent; cursor: default; }
.cal-cell:not(.empty):hover { background: var(--panel); transform: translate(-1px, -1px); box-shadow: var(--hard-sm); }
.cal-cell .cd { font-family: var(--font-num); font-size: 16px; font-weight: 800; padding: 2px 5px; }
.cal-cell .cdot {
  position: absolute; right: 3px; bottom: 3px;
  font-family: var(--font-num); font-size: 12px; font-weight: 800; line-height: 1;
  background: var(--accent); color: var(--accent-ink);
  min-width: 16px; height: 16px; padding: 0 3px; display: grid; place-items: center;
  border: 1.5px solid var(--ink);
}
.cal-cell.today { background: var(--accent-2); }
.cal-cell.sel { outline: 3px solid var(--accent); outline-offset: -2px; }

.cal-day { margin-top: 16px; border-top: 2px dashed var(--ink); padding-top: 12px; }
.cal-day h3 { font-family: var(--font-head); font-size: 17px; margin-bottom: 8px; }

.entry-list { display: grid; gap: 6px; margin-bottom: 10px; }
.entry-item {
  display: grid; grid-template-columns: 58px 26px 1fr auto auto; align-items: center; gap: 8px;
  border: 2px solid var(--ink); background: var(--panel-2); padding: 6px 8px;
}
.entry-item.routine { background: var(--panel); border-style: dashed; }
.entry-item .ei-time { font-family: var(--font-num); font-size: 15px; font-weight: 800; color: var(--ink-soft); }
.entry-item .ei-kind { font-size: 18px; text-align: center; }
.entry-item .ei-text { font-size: 14px; min-width: 0; overflow-wrap: anywhere; }
.entry-item .ei-tag {
  font-size: 9.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em;
  background: var(--accent-2); color: var(--ink); border: 1.5px solid var(--ink); padding: 2px 6px;
}
.entry-item .ei-del { font-size: 20px; padding: 0 6px; }

.entry-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.entry-form input[type="time"], .entry-form select, .entry-form input[type="text"] {
  font-family: var(--font-body); font-size: 14px; color: var(--ink);
  border: 2px solid var(--ink); padding: 8px 10px; background: var(--panel);
}
.entry-form input[type="text"] { flex: 1; min-width: 150px; }
.entry-form .repeat-check { font-size: 12.5px; font-weight: 700; color: var(--ink-soft); display: flex; align-items: center; gap: 5px; cursor: pointer; }

.cal-routines { margin-top: 16px; border-top: 2px dashed var(--ink); padding-top: 12px; }
.cal-routines h3 { font-family: var(--font-head); font-size: 16px; margin-bottom: 4px; }
.routine-list { display: grid; gap: 6px; margin: 8px 0 10px; }

@media (max-width: 640px) {
  .entry-item { grid-template-columns: 48px 22px 1fr auto auto; }
  .entry-item .ei-tag { display: none; }
}

/* ---------------------------------------------------------------- Responsive */
@media (max-width: 640px) {
  .topbar { gap: 10px; padding: 12px 14px; }
  .resources { order: 3; width: 100%; margin-left: 0; justify-content: space-between; }
  .res { flex: 1; min-width: 0; padding: 6px 8px; }
  .topbar-actions { margin-left: auto; flex-wrap: wrap; }
  .brand h1 { font-size: 20px; }
  .stable-grid { grid-template-columns: 1fr; }
}
