@font-face {
  font-family: 'Pixelify Sans';
  src: url('fonts/PixelifySans.woff2') format('woff2');
  font-display: swap;
}
:root {
  --ink: #1d1a2b; --paper: #fffaf0; --blue: #2a7de1; --red: #e2574c; --green: #7bc142; --yellow: #ffd23f; --purple: #7b4dd6;
  --px: 3px; /* one art pixel of the UI */
  /* notched pixel frame: four hard shadows instead of a border, so the corners stay cut */
  --frame: 0 calc(-1 * var(--px)) 0 0 var(--ink), 0 var(--px) 0 0 var(--ink), calc(-1 * var(--px)) 0 0 0 var(--ink), var(--px) 0 0 0 var(--ink);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: #e9dfc9; overflow: hidden;
  font-family: 'Pixelify Sans', ui-monospace, monospace; color: var(--ink);
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none; touch-action: manipulation;
}
body {
  background-color: #2b2540;
  background-image: linear-gradient(45deg, rgba(255,255,255,0.04) 25%, transparent 25% 75%, rgba(255,255,255,0.04) 75%), linear-gradient(45deg, rgba(255,255,255,0.04) 25%, transparent 25% 75%, rgba(255,255,255,0.04) 75%);
  background-size: 24px 24px; background-position: 0 0, 12px 12px;
  display: flex; align-items: center; justify-content: center;
}
#stage { position: relative; width: 960px; height: 540px; box-shadow: 0 0 0 4px var(--ink), 8px 8px 0 4px rgba(0,0,0,0.35); overflow: hidden; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; background: #fdf3e1; image-rendering: pixelated; }
#ui { position: absolute; left: 0; top: 0; width: 960px; height: 540px; transform-origin: 0 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
.hidden { display: none !important; }

.card {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  background: var(--paper); border: var(--px) solid var(--ink);
  box-shadow: inset 0 calc(-1 * var(--px)) 0 #e3dcef, 9px 9px 0 rgba(29,26,43,0.55); padding: 14px 22px;
  width: 520px; max-height: 512px; overflow: auto;
  background-image: repeating-linear-gradient(transparent 0 24px, rgba(70,110,200,0.10) 24px 27px);
}
.card.wide { width: 900px; }
.card.tall { height: 512px; display: flex; flex-direction: column; }
.card.small-card { width: 300px; top: 60px; text-align: center; }
.menu-card { width: 470px; text-align: center; padding-top: 6px; top: 10px; background-color: rgba(255,250,240,0.97); }

h1.logo { margin: 6px 0 4px; font-size: 60px; line-height: 1; letter-spacing: 3px; font-weight: normal; }
h1.logo span { display: inline-block; text-shadow: 3px 0 0 var(--ink), -3px 0 0 var(--ink), 0 3px 0 var(--ink), 0 -3px 0 var(--ink), 3px 3px 0 var(--ink), -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 6px 6px 0 var(--ink); }
h1.logo span:nth-child(1) { color: #f39c34; transform: translateY(0px); }
h1.logo span:nth-child(2) { color: var(--yellow); transform: translateY(-3px); }
h1.logo span:nth-child(3) { color: var(--red); transform: translateY(0px); }
h1.logo span:nth-child(4) { color: var(--blue); transform: translateY(3px); }
h1.logo span:nth-child(5) { color: var(--green); transform: translateY(0px); }
h1.logo span:nth-child(6) { color: var(--purple); transform: translateY(-3px); }
h1.logo span:nth-child(7) { color: #f39c34; transform: translateY(0px); }
h1.logo span:nth-child(8) { color: var(--yellow); transform: translateY(3px); }
h1.logo span:nth-child(9) { color: var(--red); transform: translateY(0px); }
h1.logo:hover span { animation: wig 0.3s steps(2) infinite alternate; }
@keyframes wig { to { translate: 0 -6px; } }
.tagline { margin: 4px 0 8px; font-size: 15px; line-height: 1.25; }
h2 { margin: 0; font-weight: normal; font-size: 28px; }

.btn {
  font: inherit; font-size: 22px; color: var(--ink); cursor: pointer;
  background: #fff; border: none; margin: var(--px);
  padding: 4px 18px; box-shadow: var(--frame), inset 0 calc(-1 * var(--px)) 0 #cfc8e0, 6px 6px 0 var(--ink);
}
.btn:hover { transform: translate(-3px, -3px); box-shadow: var(--frame), inset 0 calc(-1 * var(--px)) 0 #cfc8e0, 9px 9px 0 var(--ink); background: #fff7d6; }
.btn:active { transform: translate(3px, 3px); box-shadow: var(--frame), inset 0 var(--px) 0 #cfc8e0; }
.btn:focus-visible, .tab:focus-visible, .link:focus-visible, .map:focus-visible { outline: 3px dashed var(--blue); outline-offset: 6px; }
.btn.primary { background: var(--yellow); box-shadow: var(--frame), inset 0 calc(-1 * var(--px)) 0 #d9a21c, 6px 6px 0 var(--ink); }
.btn.primary:hover { background: #ffe27a; box-shadow: var(--frame), inset 0 calc(-1 * var(--px)) 0 #d9a21c, 9px 9px 0 var(--ink); }
.btn.big { font-size: 28px; padding: 6px 40px; }
.btn.small { font-size: 16px; padding: 2px 12px; }
.btn[disabled] { opacity: 0.5; cursor: default; }
.menu-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin: 0 20px; }
.menu-buttons .big { grid-column: 1 / -1; justify-self: center; }
.menu-buttons.solo [data-act=help] { grid-column: 1 / -1; justify-self: center; }
.who { margin: 8px 0 2px; font-size: 14px; color: #555; min-height: 22px; }
.menu-foot { display: flex; flex-wrap: wrap; gap: 2px 12px; justify-content: center; }
.menu-foot .link { font-size: 14px; }
.link { font: inherit; font-size: 16px; background: none; border: none; color: var(--blue); cursor: pointer; text-decoration: underline 3px rgba(42,125,225,0.35); text-underline-offset: 4px; padding: 2px; }

.bar { display: flex; align-items: center; gap: 16px; margin-bottom: 10px; }
.bar h2 { flex: 1; }
.bar .sum { font-size: 20px; color: #555; }

.map-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.map {
  position: relative; text-align: left; font: inherit; color: var(--ink); cursor: pointer;
  border: var(--px) solid var(--ink); padding: 6px 10px 6px 12px; min-height: 92px;
  box-shadow: inset 0 calc(-1 * var(--px)) 0 rgba(29,26,43,0.18), 6px 6px 0 var(--ink);
}
.map:hover:not(.locked) { transform: translate(-3px, -3px); box-shadow: inset 0 calc(-1 * var(--px)) 0 rgba(29,26,43,0.18), 9px 9px 0 var(--ink); z-index: 1; }
.map.c0 { background-color: #ffe3b3; }
.map.c1 { background-color: #e6dcff; }
.map.c2 { background-color: #d8f5c9; }
.map.c3 { background-color: #efe6d3; }
.map.c4 { background-color: #cdd6f6; }
.map.c5 { background-color: #d3f1f4; }
.map.c6 { background-color: #f3e2c4; }
.map.c7 { background-color: #ffd9c2; }
.map.c8 { background-color: #dde9d3; }
.map.c9 { background-color: #ffeccc; }
.map.c10 { background-color: #fff3b0; }
.map.c11 { background-color: #f8d6e7; }
.map.c12 { background-color: #ffeccc; }
.map.c13 { background-color: #ffd9c2; }
.map.c14 { background-color: #fbf1c6; }
.map.c15 { background-color: #fff3b0; }
.map.c16 { background-color: #f1ece4; }
.map.c17 { background-color: #ecd9c3; }
.map.c18 { background-color: #d6f3ff; }
.map.c19 { background-color: #f8d6e7; }
.world { grid-column: 1 / -1; margin: 6px 0 -4px; font-size: 20px; font-weight: normal; border-bottom: 3px dotted rgba(0,0,0,0.25); }
.map .num { font-size: 26px; line-height: 1; }
.map .name { font-size: 18px; line-height: 1.1; }
.map .meta { font-size: 14px; color: #333; margin-top: 2px; }
.map .badge { position: absolute; right: 8px; top: 4px; font-size: 22px; }
.map.locked { filter: grayscale(0.9); opacity: 0.55; cursor: not-allowed; box-shadow: none; }
.note { font-size: 15px; color: #555; margin: 10px 0 0; line-height: 1.3; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
#board-tabs { display: grid; grid-template-columns: repeat(11, auto); }
.board tr.head td, .board tr.head td.s, .board tr.head td.m { font-size: 13px; opacity: 0.65; border-bottom: 3px dotted rgba(0,0,0,0.2); }
.tab {
  font: inherit; font-size: 15px; cursor: pointer; background: #fff; color: var(--ink);
  border: var(--px) solid var(--ink); padding: 1px 8px;
}
.tab.active { background: var(--yellow); box-shadow: 3px 3px 0 var(--ink); }
.board-wrap { flex: 1; overflow: auto; border-top: 3px dotted rgba(0,0,0,0.25); }
table.board { width: 100%; border-collapse: collapse; font-size: 18px; }
table.board td { padding: 3px 8px; border-bottom: 1px solid rgba(0,0,0,0.1); }
table.board td.r { text-align: right; width: 60px; color: #666; }
table.board td.s { text-align: right; font-size: 20px; }
table.board td.m { text-align: right; color: #666; font-size: 15px; width: 110px; }
table.board td.w { width: 40px; text-align: right; }
table.board td.w .tab { padding: 0 8px; font-size: 13px; }
table.board tr.me { background: rgba(255,210,63,0.45); }
table.board tr:nth-child(1) td.r::before { content: '🥇 '; }
table.board tr:nth-child(2) td.r::before { content: '🥈 '; }
table.board tr:nth-child(3) td.r::before { content: '🥉 '; }

form { display: flex; flex-direction: column; gap: 3px; }
label { display: flex; flex-direction: column; font-size: 17px; }
input {
  font: inherit; font-size: 20px; padding: 4px 10px; border: var(--px) solid var(--ink);
  background: #fff; outline: none; -webkit-user-select: text; user-select: text;
}
input:focus { background: #fffbe6; box-shadow: 3px 3px 0 var(--blue); }
.shop { flex: 1; display: flex; gap: 16px; min-height: 0; }
.shop-side { width: 280px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.shop-side canvas { width: 260px; height: 220px; image-rendering: pixelated; }
.shop-name { font-size: 20px; margin: 2px 0 6px; }
.shop-side .note { font-size: 15px; margin-top: auto; }
.shop-grid { flex: 1; overflow: auto; display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; align-content: start; padding: 4px; }
.sw { position: relative; height: 62px; border: var(--px) solid var(--ink); background: #fffaf0; cursor: pointer; font: inherit; font-size: 13px; padding: 2px; }
.sw i { display: block; width: 30px; height: 30px; margin: 2px auto 1px; border: var(--px) solid var(--ink); }
.sw.sel { box-shadow: 0 0 0 3px var(--blue); }
.shop-group { grid-column: 1 / -1; margin: 6px 0 0; font-size: 16px; font-weight: normal; border-bottom: 3px dotted rgba(0,0,0,0.2); }
.sw.on { background: var(--yellow); }
.sw.own:not(.on) { background: #e9f7e4; }
.err { color: var(--red); min-height: 22px; margin: 0; font-size: 16px; }
.hello { font-size: 24px; margin: 4px 0; }

ul.help { margin: 0; padding-left: 4px; list-style: none; font-size: 17px; line-height: 1.35; }
ul.help li { margin-bottom: 8px; }
kbd { display: inline-block; border: var(--px) solid var(--ink); padding: 0 6px; background: #fff; font: inherit; font-size: 15px; box-shadow: 0 3px 0 var(--ink); }

#scr-results { width: 560px; text-align: center; }
.card.over-card { width: 400px; top: 20px; overflow: hidden; }
.over-title { font-size: 40px; color: var(--red); text-shadow: 3px 3px 0 var(--ink); }
.over-cause { font-size: 22px; margin: 0 0 4px; }
.over-card .lines { width: 320px; }
.result-title { font-size: 36px; color: #2a9d4b; text-shadow: 3px 3px 0 var(--ink); }
.lines { margin: 6px auto; width: 380px; font-size: 19px; }
.lines div { display: flex; justify-content: space-between; border-bottom: 3px dotted rgba(0,0,0,0.15); }
.lines .tot { font-size: 30px; border: none; margin-top: 4px; }
.perfect { font-size: 17px; margin: 4px 0; color: #7b4dd6; }
.hint { font-size: 14px; color: #777; min-height: 18px; }
.hint.bad { color: var(--red); }
.hint.ok { color: #2a9d4b; }
.flag { font-size: 22px; color: var(--red); margin: 4px 0; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.col { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; align-items: center; }
.col .btn { width: 200px; }

.icon-btn {
  position: absolute; right: 10px; top: 10px; width: 46px; height: 46px; font-size: 22px; cursor: pointer;
  background: rgba(255,255,255,0.9); border: var(--px) solid var(--ink); box-shadow: 3px 3px 0 var(--ink);
}
#rotate { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
  #rotate { display: block; position: fixed; left: 0; right: 0; top: 12px; text-align: center; font-size: 22px; color: var(--ink); pointer-events: none; }
}
.icon-btn { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0; }
.icon-btn i { display: block; width: 6px; height: 18px; background: var(--ink); }
