/* Sketchy Service — hand-drawn webcomic UI */
@font-face {
  font-family: "Patrick Hand";
  src: url("PatrickHand-Regular.ttf") format("truetype");
  font-display: swap;
}
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ink: #26241f;
  --bg: #efe9dd;
  --paper: #faf7f2;
  --blue: #3a6ea5;
  --teal: #2a9d8f;
  --red: #e05252;
  --gray: #b9b4a8;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Patrick Hand", "Comic Sans MS", "Chalkboard SE", "Segoe Print", "Comic Neue", cursive, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

body.hc {
  --ink: #000;
  --bg: #fff;
  --paper: #fff;
  --gray: #767676;
}

#stage {
  position: relative;
  width: min(100vw, calc(100dvh * 16 / 9));
  aspect-ratio: 16 / 9;
  max-height: 100dvh;
  font-size: clamp(11px, 1.4vw, 18px);
}

#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- HUD buttons ---------- */
#hudBtns {
  position: absolute; top: 1%; right: 0.8%;
  display: flex; gap: 0.4em; z-index: 30;
}
#hudBtns button {
  width: 2.4em; height: 2.4em;
  font-size: 1.1em; line-height: 1;
}

#controlGuide {
  position: absolute; bottom: 0.6%; left: 50%;
  transform: translateX(-50%);
  font-size: 0.85em; color: var(--ink); opacity: 0.65;
  white-space: nowrap; z-index: 5; pointer-events: none;
}

/* ---------- Buttons: hand-drawn look ---------- */
button {
  font-family: inherit;
  font-size: 1em;
  color: var(--ink);
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 14px 5px 16px 6px / 6px 15px 5px 14px;
  padding: 0.45em 1.1em;
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(38,36,31,0.35);
  transition: transform 0.08s, box-shadow 0.08s;
}
button:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 rgba(38,36,31,0.4); }
button:active { transform: translate(2px,2px); box-shadow: 0 0 0 rgba(0,0,0,0); }
button:focus-visible { outline: 3px dashed var(--teal); outline-offset: 3px; }
button.big { font-size: 1.25em; background: #e7f2ef; }
button.danger { background: #f7e3e3; }
body.rm button { transition: none; }

/* ---------- Screens ---------- */
.screen {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 40;
  background: rgba(38, 36, 31, 0.18);
}
.screen.hidden, .hidden { display: none !important; }

.panel {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 22px 8px 24px 10px / 10px 22px 8px 24px;
  box-shadow: 6px 6px 0 rgba(38,36,31,0.3);
  padding: 1.4em 2em;
  max-width: 82%;
  max-height: 88%;
  overflow-y: auto;
  text-align: center;
}

.menu-panel {
  width: 26em;
  max-width: 82%;
}

.title {
  font-size: 3em; line-height: 0.95; letter-spacing: 0.06em;
  transform: rotate(-1.5deg);
}
.subtitle { margin: 0.7em 0 1em; font-style: italic; opacity: 0.8; min-height: 2.4em; }

.menu-buttons { display: flex; flex-direction: column; gap: 0.55em; align-items: stretch; }

h2 { margin-bottom: 0.5em; transform: rotate(-0.8deg); }
h3 { margin: 0.7em 0 0.3em; }
.small { font-size: 0.8em; opacity: 0.75; }
.row { display: flex; gap: 0.8em; justify-content: center; margin-top: 1em; flex-wrap: wrap; }

.howcols { display: flex; gap: 2em; text-align: left; margin-bottom: 1em; }
.howcols ul { padding-left: 1.2em; }
.howcols li { margin: 0.25em 0; }

/* Settings grid */
.setgrid {
  display: grid; grid-template-columns: auto 1fr;
  gap: 0.55em 1em; align-items: center; text-align: left;
  margin-bottom: 0.6em;
}
.setgrid input[type=range] { width: 100%; accent-color: var(--teal); }
.setgrid input[type=checkbox] { width: 1.3em; height: 1.3em; accent-color: var(--teal); justify-self: start; }
.setgrid select {
  font-family: inherit; font-size: 1em; padding: 0.2em;
  border: 2px solid var(--ink); border-radius: 8px 3px 9px 4px; background: var(--paper); color: var(--ink);
}
input:focus-visible, select:focus-visible { outline: 3px dashed var(--teal); outline-offset: 2px; }

#scoreList { text-align: left; margin: 0 auto 0.6em; display: inline-block; min-width: 14em; }
#scoreList li { margin: 0.15em 0; font-variant-numeric: tabular-nums; }

#overStats, #levelStats { margin: 0.6em 0 1em; line-height: 1.6; }
#shareCardImg {
  display: block;
  width: 100%;
  max-width: 24em;
  margin: 0 auto 0.8em;
  border: 2.5px solid var(--ink);
  border-radius: 10px 4px 12px 5px;
  box-shadow: 3px 3px 0 rgba(38,36,31,0.3);
}
.row.tight { margin-top: 0; gap: 0.5em; }
.row.tight button { flex: 1 1 auto; }
#nameEntry { margin-bottom: 1em; }
#nameInput {
  font-family: inherit; font-size: 1.3em; width: 3.2em; text-align: center;
  text-transform: uppercase; border: 2.5px solid var(--ink);
  border-radius: 10px 4px 11px 5px; background: var(--paper); color: var(--ink);
  margin: 0 0.4em; padding: 0.15em;
}

/* ---------- Tutorial banner ---------- */
#tutBanner {
  position: absolute; top: 12%; left: 50%; transform: translateX(-50%);
  background: var(--paper); border: 2.5px solid var(--ink);
  border-radius: 14px 5px 16px 6px / 6px 15px 5px 14px;
  box-shadow: 4px 4px 0 rgba(38,36,31,0.3);
  padding: 0.6em 1em; z-index: 25; max-width: 80%;
  display: flex; gap: 1em; align-items: center; font-size: 1.05em;
}
#tutSkip { font-size: 0.75em; padding: 0.3em 0.7em; flex-shrink: 0; }

/* ---------- Toast ---------- */
#toast {
  position: absolute; bottom: 14%; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  border-radius: 10px; padding: 0.5em 1.2em; z-index: 60;
  animation: toastpop 0.2s ease-out;
}
@keyframes toastpop { from { transform: translateX(-50%) scale(0.7); opacity: 0; } }
body.rm #toast { animation: none; }

/* ---------- Touch controls ---------- */
#touchControls { position: absolute; inset: 0; z-index: 20; pointer-events: none; }
#touchControls button {
  pointer-events: auto; position: absolute;
  font-size: 1.3em; font-weight: bold;
  background: rgba(250,247,242,0.85);
  min-width: 3.4em; min-height: 3.4em;
  touch-action: none;
}
#tUp    { left: 2%;  bottom: 26%; }
#tDown  { left: 2%;  bottom: 8%; }
#tCatch { right: 2%; bottom: 26%; background: rgba(231,242,239,0.9) !important; }
#tServe { right: 2%; bottom: 8%;  background: rgba(227,236,247,0.9) !important; }

/* Portrait: all four buttons along the bottom row, thumb-reachable */
body.portrait #tUp    { left: 2%;   bottom: calc(1.5% + env(safe-area-inset-bottom, 0px)); }
body.portrait #tDown  { left: 24%;  bottom: calc(1.5% + env(safe-area-inset-bottom, 0px)); }
body.portrait #tCatch { right: 24%; bottom: calc(1.5% + env(safe-area-inset-bottom, 0px)); }
body.portrait #tServe { right: 2%;  bottom: calc(1.5% + env(safe-area-inset-bottom, 0px)); }
body.portrait #controlGuide { display: none; }

@media (max-width: 700px) {
  .panel { padding: 1em; max-width: 94%; }
  .howcols { flex-direction: column; gap: 0.5em; }
  .title { font-size: 2.2em; }
  #touchControls button { min-width: 4em; min-height: 4em; }
}
