:root {
  --field-h: 48px;          
  --item-h: 46px;           

  --bg: #F6F1E4;           /* graph paper */
  --panel: #FFFCF4;        /* writing paper */
  --text: #251C34;         /* pen ink */
  --muted: #6C6277;
  --border: #251C34;
  --accent: #4E2A84;       /* purple felt-tip */
  --accent-text: #ffffff;
  --marker: rgba(255, 213, 64, 0.62);   /* yellow highlighter */
  --tint: rgba(255, 213, 64, 0.45);
  --dot: #9D93AA;
  --warn: #A8460A;
  --stairs: rgba(255, 140, 60, 0.50);   /* orange highlighter: stairs on the map */
  --map-bg: #FBF7EB;
  --notecard-bg: #f5f0d7;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
  color: var(--text);
  font-family: "Patrick Hand", "Comic Sans MS", cursive;
  font-size: 18px;
  font-weight: 400;
}
/* graph paper */
html {
  background-color: var(--bg);
  background-image:
    linear-gradient(to right,  rgba(70, 60, 140, 0.20) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(70, 60, 140, 0.20) 1px, transparent 1px),
    linear-gradient(to right,  rgba(70, 60, 140, 0.09) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(70, 60, 140, 0.09) 1px, transparent 1px);
  background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:focus-visible { outline: 2px dashed var(--accent); outline-offset: 3px; }
.field input:focus-visible { outline: none; }

[data-sketch] {
  --sk-fill: var(--panel);
  --sk-fill-style: solid;
  --sk-stroke: var(--border);
  --sk-w: 2;
  --sk-rough: 1;
  --sk-r: 14;
  --sk-img: none;
}
/* fallback */
html:not(.hm-ready) :is([data-sketch="panel"], [data-sketch="pill"], [data-sketch="round"]) {
  border: 1.5px solid var(--border);
  background-color: var(--panel);
}

#app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 9px;
}
#app > * { flex: 0 0 auto; }

#app.routing:not(.editing) {
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
}
#app.routing:not(.editing) > :is(h1, .field, .options-row) { display: none; }

h1[data-sketch] {
  --sk-fill: none;
  --sk-stroke: var(--accent);
  --sk-w: 3;
  --sk-rough: 1.3;
  align-self: flex-start;
  margin: 2px 6px 2px;
  padding: 0 4px 12px;
  font-family: "Caveat Brush", "Patrick Hand", cursive;
  font-weight: 400;
  font-size: 42px;
  line-height: 1;
  color: var(--accent);
  transform: rotate(-1.5deg);
  transform-origin: left center;
  background: var(--sk-img) left bottom / 100% 14px no-repeat;
}

.field { position: relative; }
.field-row {
  display: flex;
  align-items: center;
  height: var(--field-h);
}
.field input {
  --sk-r: 14;
  --sk-w: 2;
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  padding: 0 18px;
  font-size: 19px;                
  background: var(--sk-img) 0 0 / 100% 100% no-repeat;
  background-origin: border-box;
  border: 0;
  border-radius: 14px;
  outline: none;
}
.field input::placeholder { color: var(--muted); }

.check {
  --sk-fill: var(--accent);
  --sk-stroke: var(--border);
  --sk-size: 40;
  flex: 0 0 auto;
  width: 0;
  height: 40px;
  margin-left: 0;
  padding: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  border: 0;
  border-radius: 50%;
  background: var(--sk-img) center / 40px 40px no-repeat;
  color: var(--accent-text);
  transition: width 0.2s ease, margin-left 0.2s ease, opacity 0.2s ease;
}
.check svg { width: 22px; height: 22px; display: block; margin: 0 auto; stroke-width: 2.4; }
.field.active .check {
  width: 40px;
  margin-left: 6px;
  opacity: 1;
  pointer-events: auto;
}

.dropdown {
  --sk-r: 14;
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: calc(var(--field-h) + 6px);
  max-height: calc(var(--item-h) * 4.5 + 20px);
  margin: 0;
  padding: 10px 10px;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--sk-img) 0 0 / 100% 100% no-repeat;
  background-origin: border-box;
  border: 0;
}
.dropdown::-webkit-scrollbar { display: none; }
.dropdown[hidden] { display: none; }
.dropdown li {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--item-h);
  padding: 0 12px;
  border-radius: 14px 5px 12px 6px / 7px 12px 5px 14px;
  cursor: pointer;
}
.dropdown li.hl, .dropdown li:hover { background: var(--tint); }
.dropdown li.empty { color: var(--muted); cursor: default; }
.opt-icon { flex: 0 0 22px; height: 22px; color: var(--accent); }
.opt-icon svg { width: 24px; height: 24px; display: block; margin: -1px 0 0 -1px; }
.opt-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opt-true { color: var(--muted); }
.opt-sub { flex: 0 0 auto; font-size: 15px; color: var(--muted); }

.options-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
#edit-done { display: none; transform: rotate(1.5deg); margin: 0 4px 0 0; }
#app.routing.editing #edit-done { display: block; }
.chip {
  --sk-w: 1.8;
  align-self: flex-start;
  margin-left: 4px;
  padding: 6px 18px;
  font-size: 17px;
  border: 0;
  border-radius: 999px;
  background: var(--sk-img) 0 0 / 100% 100% no-repeat;
  background-origin: border-box;
  transform: rotate(-1.5deg);
  transition: color 0.15s;
}
.chip[aria-pressed="true"] {
  --sk-fill: var(--accent);
  --sk-stroke: var(--accent);
  color: var(--accent-text);
}

#map-box {
  --sk-fill: none;
  --sk-w: 2.6;
  --sk-r: 12;
  position: relative;
  flex: 1 1 0;
  min-height: calc(var(--field-h) * 3);
  overflow: hidden;
  background: var(--map-bg);
  border: 0;
  border-radius: 12px;
}

#map-box::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  background: var(--sk-img) 0 0 / 100% 100% no-repeat;
  background-origin: border-box;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#floor-scroller {
  --sk-r: 10;
  --sk-w: 2;
  position: absolute;
  z-index: 4;
  left: 12px;
  top: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 5px 3px;
  background: var(--sk-img) 0 0 / 100% 100% no-repeat;
  background-origin: border-box;
  border: 0;
  transform: rotate(-2deg);
}
#floor-scroller button {
  width: 38px;
  height: 30px;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--text);
}
#floor-scroller button svg { width: 22px; height: 22px; display: block; margin: 0 auto; }
#floor-scroller button:disabled { opacity: 0.28; cursor: default; }
#floor-label { min-width: 38px; text-align: center; font-size: 20px; line-height: 22px; }

#fit-toggle, #compass {
  --sk-w: 2;
  position: absolute;
  z-index: 4;
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  background: var(--sk-img) 0 0 / 100% 100% no-repeat;
  background-origin: border-box;
  border: 0;
  border-radius: 50%;
  color: var(--text);
}
#fit-toggle { right: 12px; top: 12px; transform: rotate(3deg); }
#fit-toggle[aria-pressed="true"] { --sk-fill: var(--accent); --sk-stroke: var(--accent); color: var(--accent-text); }
#compass { right: 16px; top: 64px; width: 40px; height: 40px; }
#fit-toggle svg, #compass svg { width: 22px; height: 22px; }
#compass[hidden], #fit-toggle[hidden] { display: none; }

#trip-slip {
  --sk-r: 8;
  --sk-w: 1.8;
  position: absolute;
  z-index: 5;
  top: 12px;
  left: 50%;
  display: none;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100% - 136px);
  padding: 8px 6px 8px 14px;
  background: var(--sk-img) 0 0 / 100% 100% no-repeat;
  background-origin: border-box;
  transform: translateX(-50%) rotate(-1deg);
}
#app.routing:not(.editing) #trip-slip { display: flex; }
.slip-lines { min-width: 0; display: grid; grid-template-columns: 12px minmax(0, 1fr); column-gap: 5px; row-gap: 1px; }
.slip-row { grid-column: 2; display: flex; align-items: center; gap: 9px; min-width: 0; height: 27px; font-size: 16px; line-height: 1.4; }
.slip-icon { flex: 0 0 16px; width: 16px; height: 16px; color: var(--accent); }
.slip-icon svg { width: 16px; height: 16px; display: block; stroke-width: 2.4; }
.slip-text { min-width: 0; padding: 1px 2px 3px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slip-arrow { grid-column: 1; grid-row: 1 / 3; align-self: center; width: 12px; height: 28px; color: var(--muted); }
.slip-arrow svg { width: 12px; height: 28px; display: block; overflow: visible; }
.slip-arrow svg path { stroke-width: 2.6; }
#slip-from-icon svg path { stroke-width: 3.4; }
#slip-edit {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  border-radius: 50%;
  color: var(--accent);
}
#slip-edit svg { width: 22px; height: 22px; }

.grip {
  display: block;
  position: relative;
  width: 84px;
  height: 18px;
  margin: 0 auto;
  padding: 0;
  background: none;
  border: 0;
  cursor: grab;
}
.grip::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 7px;
  width: 42px;
  height: 5px;
  margin-left: -21px;
  background: var(--dot);
  border-radius: 3px;
  transform: rotate(-1deg);
}

#card {
  position: absolute;
  z-index: 20;
  left: 24px;
  right: 24px;
  bottom: 0;
  height: 0;
  overflow: hidden;
  background: var(--notecard-bg);
  box-shadow: 0 -4px 0 rgba(37, 28, 52, 0.10), -3px 0 0 rgba(37, 28, 52, 0.06), 3px 0 0 rgba(37, 28, 52, 0.06);
  transition: height 0.32s ease;
}
#card.dragging { transition: none; }
#card[hidden] { display: none; }

.edge {
  --sk-fill: none;
  --sk-stroke: var(--border);
  --sk-w: 2.6;
  --sk-rough: 1.4;
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
  background: var(--sk-img) 0 0 / 100% 100% no-repeat;
}

.rule {
  --sk-fill: none;
  --sk-stroke: #D4574E;
  --sk-w: 2;
  --sk-rough: 1.2;
  flex: 0 0 auto;
  height: 8px;
  margin: 6px 0 0;
  background: var(--sk-img) 0 0 / 100% 100% no-repeat;
}

.card-front {
  position: relative;
  display: flex;
  flex-direction: column;
  height: min(20vh, 190px);
  height: min(20dvh, 190px);
  padding-top: 14px;
  touch-action: none;
  transition: opacity 0.2s ease, visibility 0s;
}
#card-grip { position: absolute; top: 0; left: 50%; margin: 0 0 0 -42px; }
.card-head { flex: 1 1 auto; min-height: 0; overflow: hidden; display: flex; gap: 10px; margin: 2px 16px 0; }
.card-head > * { margin-block: auto; }
.step-icon { position: relative; flex: 0 0 30px; width: 30px; height: 30px; color: var(--accent); }
.step-icon > svg { width: 30px; height: 30px; display: block; stroke-width: 2.2; }
.bang {
  position: absolute;
  right: -8px;
  top: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--panel);
  color: var(--warn);
}
.bang svg { width: 20px; height: 20px; display: block; stroke-width: 2.4; }
#card-title { flex: 1 1 auto; min-width: 0; margin: auto 0; font-weight: 400; line-height: 1.1; }
#card-title .t {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-family: "Caveat Brush", "Patrick Hand", cursive;
  font-size: 24px;
  color: var(--text);
}
#card-title .d {                  
  display: block;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: "Patrick Hand", cursive;
  font-size: 15px;
  line-height: 1.25;
  color: var(--muted);
}
#card-title .d:empty { display: none; }
#card-warn {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  align-items: center;
  margin: 2px 16px 0;
  font-size: 14px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  color: var(--warn);
}
#card-warn span { overflow: hidden; text-overflow: ellipsis; }
#card-warn[hidden] { display: none; }
#card-warn svg { flex: 0 0 16px; width: 16px; height: 16px; margin-top: 1px; }

.card-lines {
  --sk-fill: none;
  --sk-stroke: rgba(70, 110, 190, 0.40);
  --sk-w: 1.5;
  --sk-gap: 30;
  --sk-rough: 0.9;
  flex: 0 0 auto;
  padding: 7px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--sk-img) 0 0 / 100% 100% no-repeat;
}
#card-sub { flex: 0 0 auto; padding-top: 0; font-size: 14px; line-height: 1.2; white-space: nowrap; color: var(--muted); }

#card-actions { display: flex; gap: 10px; align-items: stretch; }
#back, #next {
  --sk-r: 12;
  --sk-w: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 4px 14px;
  font-size: 17px;
  line-height: 1.15;
  background: var(--sk-img) 0 0 / 100% 100% no-repeat;
  background-origin: border-box;
  border: 0;
}
#back {                           /* grayish */
  --sk-fill: var(--panel);
  --sk-stroke: #8E869B;
  flex: 0 0 auto;
  color: #6F6679;
}
#back:disabled { opacity: 0.4; cursor: default; }
#next {
  --sk-fill: var(--accent);
  --sk-stroke: var(--accent);
  flex: 1 1 auto;
  color: var(--accent-text);
  text-align: center;
}
#next-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-icon { flex: 0 0 22px; height: 22px; }
.btn-icon svg { width: 22px; height: 22px; display: block; stroke-width: 2.4; }

/* the extended card */
.card-pad {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}
#card.extended .card-pad, #card.dragging .card-pad {
  visibility: visible;
  transition: opacity 0.25s ease 0.05s;
}
#card.extended .card-pad { opacity: 1; }
#card.extended .card-front {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}
.pad-head {
  position: relative;
  flex: 0 0 auto;
  padding: 16px 20px 0;
  touch-action: none;
  cursor: grab;
}
.pad-head .grip { position: absolute; top: 4px; left: 50%; margin: 0 0 0 -42px; }
.pad-head h2 {
  margin: 4px 0 0;
  font-family: "Caveat Brush", "Patrick Hand", cursive;
  font-weight: 400;
  font-size: 32px;
  line-height: 1.1;
  color: var(--accent);
}

.pad-body { position: relative; flex: 1 1 0; min-height: 0; display: flex; }
.pad-body::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 54px;
  width: 2px;
  background: rgba(212, 87, 78, 0.5);
  pointer-events: none;
}
#steps {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: 2px 18px calc(16px + env(safe-area-inset-bottom)) 14px;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
#steps::-webkit-scrollbar { display: none; }

.step {
  --sk-fill: var(--marker);
  --sk-stroke: none;
  --sk-r: 10;
  --sk-rough: 1.4;
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: 34px 30px 1fr;
  column-gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(70, 110, 190, 0.32);
  cursor: pointer;
}
.step .num { text-align: right; font-size: 19px; line-height: 1.3; color: var(--muted); }
.step .icon { position: relative; width: 30px; height: 30px; color: var(--accent); }
.step .icon > svg { width: 30px; height: 30px; display: block; stroke-width: 2.2; }
.step .icon .bang { right: -7px; top: -7px; width: 16px; height: 16px; }
.step .icon .bang svg { width: 16px; height: 16px; }
.step .text { display: flex; flex-direction: column; justify-content: center; font-size: 18px; line-height: 1.3; }
.step.active::before {
  content: "";
  position: absolute;
  inset: 2px -10px;
  z-index: -1;
  background: var(--sk-img) 0 0 / 100% 100% no-repeat;
}
.step .warn {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  margin-top: 3px;
  font-size: 15px;
  line-height: 1.25;
  color: var(--warn);
}
.step .warn svg { flex: 0 0 16px; width: 16px; height: 16px; margin-top: 1px; }

#card.failed .step-icon, #card.failed .grip, #card.failed .rule, #card.failed .card-lines, #card.failed #card-warn, #card.failed #card-sub { display: none; }
#card.failed .card-front { height: auto; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
#card.failed #card-title .t { font-family: "Patrick Hand", cursive; font-size: 21px; line-height: 1.25; color: var(--warn); }