:root {
  --ink: #2b1f1a;
  --paper: #fff3d6;
  --sand: #f2c27b;
  --orange: #ff8a1f;
  --blue: #3f86e0;
  --good: #59d96b;
  --bad: #ff5d5d;
  --font: "Trebuchet MS", "Avenir Next Rounded", "Arial Rounded MT Bold", Verdana, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #1a1410; color: #fff; font-family: var(--font);
  user-select: none; -webkit-user-select: none;
  overscroll-behavior: none; touch-action: manipulation;
}
body { display: flex; align-items: center; justify-content: center; }
canvas#game { display: block; background: #000; image-rendering: auto; }
#ui { position: fixed; inset: 0; pointer-events: none; }
.hidden { display: none !important; }

#hayloft-logo {
  position: fixed; left: max(12px, env(safe-area-inset-left)); top: max(12px, env(safe-area-inset-top)); width: 40px; height: 40px;
  pointer-events: auto; opacity: 0.9; z-index: 5; border-radius: 10px;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5));
  transition: transform 0.15s, opacity 0.15s;
}
#hayloft-logo img { width: 100%; height: 100%; display: block; }
#hayloft-logo:hover { transform: scale(1.1); opacity: 1; }
#hayloft-logo.ingame { display: none; }

.screen {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: auto; text-align: center; padding: 20px;
}
.screen.dim { background: rgba(20, 12, 8, 0.62); }

.title-logo {
  font-size: clamp(56px, 11vw, 132px); font-weight: 900; letter-spacing: 4px; line-height: 1;
  color: #ffd23f; margin: 0 0 4px;
  text-shadow: 0 4px 0 #d9702a, 0 8px 0 #a8481c, 0 12px 0 #7a2f12, 0 16px 22px rgba(0,0,0,0.55);
  -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill;
  transform: rotate(-2deg);
}
.subtitle { font-size: clamp(14px, 2.2vw, 22px); color: #fff; margin: 4px 0 22px; text-shadow: 0 2px 4px rgba(0,0,0,0.7); letter-spacing: 1px; }

.menu { display: flex; flex-direction: column; gap: 10px; min-width: min(420px, 86vw); }
.mi {
  padding: 12px 26px; font-size: clamp(16px, 2.2vw, 22px); font-weight: 800; letter-spacing: 1px;
  background: #fff3d6; color: var(--ink); border: 4px solid var(--ink); border-radius: 16px;
  box-shadow: 0 5px 0 rgba(0,0,0,0.55); cursor: pointer; transition: transform 0.08s;
}
.mi.sel { background: #ffd23f; transform: scale(1.06) translateY(-2px); box-shadow: 0 7px 0 rgba(0,0,0,0.6), 0 0 0 4px rgba(255,255,255,0.7); }
.mi.disabled { opacity: 0.5; cursor: default; background: #d8cdb5; }
.mi small { display: block; font-weight: 600; font-size: 0.6em; letter-spacing: 0; opacity: 0.75; margin-top: 2px; }
.hint { margin-top: 18px; font-size: 14px; color: #fff; opacity: 0.85; text-shadow: 0 2px 3px rgba(0,0,0,0.8); max-width: 640px; line-height: 1.5; }
.pad-status { position: fixed; left: 0; right: 0; bottom: 18px; font-size: 13px; opacity: 0.9; text-shadow: 0 2px 3px rgba(0,0,0,0.8); }
.pad-toast {
  position: fixed; top: 74px; left: 50%; transform: translateX(-50%); z-index: 8;
  background: rgba(20,24,34,0.85); border: 2px solid rgba(255,255,255,0.35); border-radius: 999px; padding: 8px 20px; font-size: 15px; font-weight: 700;
}

.card {
  background: var(--paper); color: var(--ink); border: 5px solid var(--ink); border-radius: 22px; padding: 22px 30px;
  box-shadow: 0 8px 0 rgba(0,0,0,0.55); max-width: min(880px, 94vw); text-align: left;
}
.card h2 { margin: 0 0 4px; font-size: clamp(24px, 3.4vw, 36px); letter-spacing: 1px; }
.card .kicker { font-size: 14px; font-weight: 800; letter-spacing: 2px; color: #a8481c; }
.card p { margin: 6px 0; line-height: 1.45; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 28px; margin: 12px 0; }
.grid.three { grid-template-columns: repeat(3, 1fr); }
.stat { display: flex; justify-content: space-between; gap: 14px; border-bottom: 2px dashed rgba(43,31,26,0.25); padding: 4px 0; font-size: 16px; }
.stat b { font-weight: 900; }
.stat.good b { color: #1d8f3a; } .stat.bad b { color: #c93a3a; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.chip { background: #fff; border: 3px solid var(--ink); border-radius: 999px; padding: 4px 12px; font-size: 14px; font-weight: 800; }
.chip.new { background: #ffd23f; }
.chip.medal { background: #d8f5c8; }
.strip { position: relative; height: 54px; margin: 14px 4px 8px; background: linear-gradient(#bfe3f2, #f7d9a0); border: 3px solid var(--ink); border-radius: 12px; overflow: hidden; }
.strip .ground { position: absolute; left: 0; right: 0; bottom: 0; height: 16px; background: #d9a75d; border-top: 3px solid var(--ink); }
.strip .mk { position: absolute; bottom: 12px; transform: translateX(-50%); font-size: 12px; font-weight: 900; padding: 2px 6px; border: 2px solid var(--ink); border-radius: 8px; background: #fff; }
.strip .mk.base { background: var(--blue); color: #fff; }
.strip .mk.camp { background: var(--orange); }
.progress { height: 8px; background: rgba(0,0,0,0.15); border-radius: 4px; overflow: hidden; margin-top: 12px; }
.progress > i { display: block; height: 100%; background: var(--orange); }
table.controls { width: 100%; border-collapse: collapse; font-size: 15px; }
table.controls th { text-align: left; font-size: 12px; letter-spacing: 2px; color: #a8481c; padding: 4px 8px; }
table.controls td { padding: 5px 8px; border-bottom: 2px dashed rgba(43,31,26,0.2); }
table.controls td:first-child { font-weight: 800; }
kbd { background: #fff; border: 2px solid var(--ink); border-radius: 6px; padding: 1px 7px; font-family: var(--font); font-weight: 800; font-size: 13px; box-shadow: 0 2px 0 rgba(0,0,0,0.4); }
.overlay-msg { background: rgba(20,12,8,0.78); border: 4px solid #fff; border-radius: 22px; padding: 26px 40px; max-width: 640px; }
.overlay-msg h2 { margin: 0 0 10px; font-size: 34px; color: #ff8d7d; letter-spacing: 1px; }
.overlay-msg p { margin: 6px 0; line-height: 1.5; font-size: 17px; }

#debug-panel {
  position: fixed; right: 8px; top: 8px; width: 330px; max-height: calc(100vh - 16px); overflow: auto; z-index: 20;
  background: rgba(15, 18, 26, 0.92); border: 2px solid rgba(255,255,255,0.3); border-radius: 12px; padding: 10px 12px; font-size: 12px; user-select: none;
}
#debug-panel h3 { margin: 0 0 6px; font-size: 13px; letter-spacing: 1px; color: #ffd23f; }
#debug-panel .row { display: grid; grid-template-columns: 1fr 70px; align-items: center; gap: 6px; margin: 4px 0; }
#debug-panel .row label { grid-column: 1 / 3; opacity: 0.85; }
#debug-panel .row input[type=range] { width: 100%; }
#debug-panel .row output { text-align: right; font-variant-numeric: tabular-nums; }
#debug-panel button { font-family: var(--font); font-weight: 800; font-size: 12px; padding: 5px 10px; margin: 6px 6px 0 0; border-radius: 8px; border: 2px solid #fff; background: #23314a; color: #fff; cursor: pointer; }
#debug-panel .chk { display: flex; gap: 6px; align-items: center; margin: 4px 0; }

.menu.grid { display: grid; grid-template-columns: repeat(3, minmax(190px, 1fr)); gap: 10px; min-width: min(760px, 92vw); }
.menu.grid .mi { font-size: 0.8em; padding: 8px 12px; }
.menu.compact { gap: 6px; }
.menu.compact .mi { padding: 6px 22px; font-size: clamp(14px, 1.9vw, 19px); }
.menu.compact .mi small { font-size: 0.62em; }
.menu.compact.tight { gap: 3px; }
.menu.compact.tight .mi { padding: 3px 22px; font-size: clamp(13px, 1.7vw, 17px); }
.menu.compact.tight .mi small { font-size: 0.6em; }
/* Long menus (title with every option): only the selected row shows its description. */
.menu.compact.tight .mi small { display: none; }
.menu.compact.tight .mi.sel small { display: block; }
.menu.compact.tight + .hint { margin-top: 10px; }

/* Medals: results row, collection screen */
.medal-row { display: flex; flex-wrap: wrap; gap: 6px 10px; margin: 6px 0 4px; }
.medal-tile { position: relative; display: flex; flex-direction: column; align-items: center; width: 76px; font-size: 10.5px; font-weight: 800; line-height: 1.15; text-align: center;
  animation: medal-pop 0.45s cubic-bezier(.2,1.6,.4,1) both; }
.medal-tile span { margin-top: 2px; }
.medal-tile em { position: absolute; top: -4px; right: 2px; font-style: normal; font-size: 10px; letter-spacing: 1px; background: #ffd23f; border: 2px solid var(--ink); border-radius: 6px; padding: 0 4px; }
.medal-tile.fresh .medal-svg { filter: drop-shadow(0 0 6px rgba(255, 210, 63, 0.95)); }
@keyframes medal-pop { from { transform: scale(0.2) rotate(-25deg); opacity: 0; } to { transform: none; opacity: 1; } }
.medal-svg.locked { opacity: 0.55; }
.medal-screen { display: flex; gap: 18px; align-items: flex-start; max-width: 1180px; }
.menu.grid.boards { grid-template-columns: repeat(2, 250px); min-width: 0; gap: 7px 8px; }
.menu.boards .mi { display: flex; flex-direction: column; align-items: flex-start; gap: 0; padding: 4px 12px; font-size: 14px; text-align: left; border-width: 3px; border-radius: 12px; }
.menu.boards .mi:last-child { grid-column: 1 / 3; align-items: center; }
.menu.boards .mi.sel { transform: scale(1.03); }
.menu.boards .mi .mb-count i { font-style: normal; font-size: 11px; margin-right: 8px; opacity: 0.45; }
.menu.boards .mi .mb-count i.on { opacity: 1; color: #1d6f2a; }
#medal-detail { width: 560px; padding: 14px 20px; }
#medal-detail h2 { font-size: 26px; }
.md-list { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.md-row { display: flex; align-items: center; gap: 10px; padding: 2px 0; border-bottom: 2px dashed rgba(43,31,26,0.15); }
.md-row.dim .md-text { opacity: 0.6; }
.md-text { flex: 1; display: flex; flex-direction: column; font-size: 14px; }
.md-text small { font-size: 11.5px; font-weight: 600; opacity: 0.8; }
.md-diffs i { display: inline-block; width: 20px; height: 20px; line-height: 17px; text-align: center; font-style: normal; font-size: 11px; font-weight: 900; margin-left: 3px;
  border: 2px solid rgba(43,31,26,0.35); border-radius: 50%; color: rgba(43,31,26,0.4); }
.md-diffs i.on { background: #ffd23f; border-color: var(--ink); color: var(--ink); }
/* Long title menu: a smaller logo leaves room for every row. */
.screen:has(.menu.compact.tight:not(.boards)) .title-logo { font-size: clamp(48px, 8.5vw, 104px); }
.screen:has(.menu.compact.tight:not(.boards)) .subtitle { margin: 2px 0 12px; }
/* Results: buttons in one row under the card. */
.menu.row { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 12px; min-width: 0; margin-top: 12px; }
.menu.row .mi { padding: 8px 22px; font-size: 18px; }
.menu.row .mi.sel { transform: scale(1.04) translateY(-2px); }
/* Phones and tablets without a keyboard: Liftback needs a keyboard or a controller. */
.touch-note { max-width: min(560px, 92vw); margin: 0 0 12px; padding: 10px 16px; background: rgba(20,12,8,0.82); border: 3px solid #ffd23f; border-radius: 14px; font-size: 15px; line-height: 1.4; color: #fff; pointer-events: auto; }
.touch-note b { color: #ffd23f; }
/* Short screens (phones in landscape): menus scroll instead of spilling off the screen. */
@media (max-height: 560px) {
  .screen { justify-content: flex-start; overflow-y: auto; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .screen .title-logo { font-size: 44px !important; }
  .subtitle { margin: 2px 0 8px; font-size: 13px; }
  .touch-note { font-size: 13px; padding: 8px 12px; margin-bottom: 8px; }
  .pad-status { display: none; }
}
