:root {
  --ink: #1B1A2E;
  --ink-2: #2A2742;
  --crimson: #B3202A;
  --crimson-dark: #6E1219;
  --mustard: #E8A317;
  --cream: #F4E6C8;
  --teal: #1F7A72;
  --green: #5BBF3A;
  --display: "Rye", Georgia, serif;
  --body: "Bricolage Grotesque", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--ink); }

body {
  margin: 0;
  color: var(--cream);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.5;
  background:
    radial-gradient(1200px 500px at 70% -10%, rgba(179, 32, 42, 0.35), transparent 60%),
    repeating-conic-gradient(from 0deg at 50% -40vh, #211F36 0 6deg, #1B1A2E 6deg 12deg);
  min-height: 100vh;
}

/* ---------------------------------------------------------------- otsake */
.masthead {
  position: relative;
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 24px 10px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  color: inherit;
  text-decoration: none;
  transform: rotate(-2deg);
}

.brand img { filter: drop-shadow(3px 4px 0 rgba(0, 0, 0, 0.5)); }

.brand__text { display: flex; flex-direction: column; line-height: 0.9; }
.brand__text small {
  font-family: var(--display);
  font-size: 18px;
  color: var(--cream);
  letter-spacing: 0.08em;
}
.brand__text strong {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(38px, 6vw, 56px);
  color: var(--mustard);
  text-shadow: 3px 3px 0 var(--crimson), 6px 6px 0 rgba(0, 0, 0, 0.5);
}

.masthead__tag {
  margin: 0 0 6px;
  text-align: right;
  font-size: 15px;
  color: rgba(244, 230, 200, 0.8);
}
.masthead__tag em { color: var(--green); font-style: normal; font-weight: 700; }

/* krypta.gg-pelisivuston paluulinkki */
.all-games {
  position: absolute;
  top: 8px;
  right: 24px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 800;
  color: rgba(244, 230, 200, 0.75);
  text-decoration: none;
  letter-spacing: 0.02em;
}
.all-games:hover, .all-games:focus-visible { color: var(--mustard); text-decoration: underline; }

/* ---------------------------------------------------------------- näyttämö */
main { max-width: 1180px; margin: 0 auto; padding: 0 24px; }

.stage {
  position: relative;
  margin: 8px auto 0;
  padding: 14px 46px 18px;
  background: var(--crimson-dark);
  border: 4px solid var(--ink);
  border-radius: 18px 18px 6px 6px;
  box-shadow: 10px 12px 0 rgba(0, 0, 0, 0.45);
}

.curtain {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 46px;
  background: repeating-linear-gradient(90deg, #8E1720 0 8px, #B3202A 8px 14px, #6E1219 14px 18px);
  pointer-events: none;
}
.curtain--l { left: 0; border-radius: 14px 0 0 4px; }
.curtain--r { right: 0; border-radius: 0 14px 4px 0; }

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #0E0D1A;
  border: 3px solid var(--ink);
  border-radius: 6px;
  outline: none;
  touch-action: none;
  cursor: pointer;
}
canvas:focus-visible { box-shadow: 0 0 0 3px var(--mustard); }

.stage__tools {
  position: absolute;
  right: 56px;
  bottom: -18px;
  display: flex;
  gap: 10px;
}

.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font: 700 13px var(--body);
  color: var(--ink);
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
}
.tool:hover { background: var(--mustard); }
.tool:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.tool[aria-pressed="true"] { background: #d8c9a8; }

/* Ennätyksen nimikysely */
.name-prompt {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(14, 13, 26, 0.6);
  z-index: 5;
}
.name-prompt[hidden] { display: none; }
.name-prompt__card {
  width: min(380px, 86%);
  padding: 22px 24px 20px;
  background: var(--cream);
  color: var(--ink);
  border: 4px solid var(--ink);
  border-radius: 10px;
  box-shadow: 8px 8px 0 var(--crimson);
  transform: rotate(-1deg);
  text-align: center;
}
.name-prompt__card svg { color: var(--mustard); filter: drop-shadow(1px 1px 0 var(--ink)); }
.name-prompt h2 { margin: 4px 0 2px; font: 400 30px var(--display); color: var(--crimson); }
.name-prompt p { margin: 0 0 14px; font-weight: 700; }
.name-prompt label { display: block; font-size: 13px; font-weight: 800; text-align: left; margin-bottom: 4px; }
.name-prompt input {
  width: 100%;
  padding: 10px 12px;
  font: 700 20px var(--body);
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 8px;
}
.name-prompt input:focus { outline: 3px solid var(--mustard); outline-offset: 1px; }
.name-prompt__actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.tool--primary { background: var(--mustard); }

/* Täysi näyttö */
.stage:fullscreen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #000;
}
.stage:fullscreen canvas { width: min(100vw, 177.78vh); border: 0; border-radius: 0; }
.stage:fullscreen .curtain, .stage:fullscreen .stage__tools { display: none; }
.stage:fullscreen .name-prompt { position: fixed; }

/* ---------------------------------------------------------------- kosketusohjaimet */
.touch, .rotate-hint { display: none; }

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 60px);
  grid-template-rows: repeat(3, 54px);
  gap: 4px;
}
.pad {
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--cream);
  color: var(--ink);
  font: 800 18px var(--body);
  box-shadow: 3px 4px 0 var(--ink);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.pad svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.pad.is-down { transform: translate(2px, 3px); box-shadow: 1px 1px 0 var(--ink); background: var(--mustard); }
.pad--up { grid-area: 1 / 2; }
.pad--left { grid-area: 2 / 1; }
.pad--right { grid-area: 2 / 3; }
.pad--down { grid-area: 3 / 2; }
.pad--small { width: 52px; height: 52px; border-radius: 50%; }
.pad--action {
  width: 124px;
  height: 124px;
  border-radius: 50%;
  background: var(--crimson);
  color: var(--cream);
  font-family: var(--display);
  font-weight: 400;
  font-size: 30px;
}
.pad--action.is-down { background: var(--mustard); color: var(--ink); }

/* ---------------------------------------------------------------- kosketuslaitteen pelitila
   body.is-touch asetetaan JS:ssä (karkea osoitin). Peli täyttää näytön kuin sovellus. */
body.is-touch { overflow: hidden; overscroll-behavior: none; }
body.is-touch .masthead,
body.is-touch .playbill,
body.is-touch .foot,
body.is-touch .curtain { display: none; }
body.is-touch main { max-width: none; padding: 0; }
body.is-touch .stage {
  position: fixed;
  inset: 0;
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: #07060D;
  display: flex;
  flex-direction: column;
  align-items: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
body.is-touch canvas { border: 0; border-radius: 0; width: 100%; flex: none; }
body.is-touch .stage__tools {
  top: calc(6px + env(safe-area-inset-top));
  right: calc(6px + env(safe-area-inset-right));
  bottom: auto;
  gap: 6px;
  z-index: 3;
}
body.is-touch .tool { padding: 6px 8px; opacity: 0.8; }
body.is-touch .tool span { display: none; }
body.is-touch .touch { display: flex; z-index: 2; }

/* jongleeraus ym.: näytön puoliskot ovat kädet → ristiohjain piiloon */
body.is-touch.zone-controls .dpad { visibility: hidden; }

/* pysty: peli ylhäällä, isot napit alla */
@media (orientation: portrait) {
  body.is-touch .stage__tools { top: auto; bottom: calc(8px + env(safe-area-inset-bottom)); right: 50%; transform: translateX(50%); }
  body.is-touch .touch {
    flex: 1;
    width: 100%;
    max-width: 520px;
    padding: 18px 22px 64px;
    align-items: center;
    justify-content: space-between;
  }
  /* napit maltillisen kokoisiksi: peukalolle riittävät, mutta eivät vie koko ruutua */
  body.is-touch .dpad { grid-template-columns: repeat(3, min(46px, 12vw)); grid-template-rows: repeat(3, min(42px, 11vw)); gap: 3px; }
  body.is-touch .pad svg { width: 22px; height: 22px; }
  body.is-touch .pad--small { width: 40px; height: 40px; font-size: 15px; }
  body.is-touch .pad--action { width: min(88px, 23vw); height: min(88px, 23vw); font-size: 22px; }
  body.is-touch .tool { padding: 5px 7px; }
  body.is-touch .rotate-hint {
    display: flex;
    align-items: center;
    gap: 6px;
    position: absolute;
    left: 0;
    right: 0;
    justify-content: center;
    top: calc(56.25vw + 8px + env(safe-area-inset-top));
    margin: 0;
    font-size: 13px;
    font-weight: 700;
    color: rgba(244, 230, 200, 0.6);
  }
}

/* vaaka: peli näytön korkuinen, läpikuultavat napit kulmissa pelin päällä */
@media (orientation: landscape) {
  body.is-touch .stage { justify-content: center; }
  /* työkalunapit pystyriviin reunaan, ettei yläpalkin teksti peity */
  body.is-touch .stage__tools { flex-direction: column; top: calc(44px + env(safe-area-inset-top)); }
  body.is-touch .tool { opacity: 0.6; }
  body.is-touch canvas { width: min(100%, calc((100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 16 / 9)); }
  body.is-touch .touch {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0 calc(10px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
    align-items: flex-end;
    justify-content: space-between;
    pointer-events: none;
  }
  body.is-touch .touch > * { pointer-events: auto; }
  body.is-touch .pad { opacity: 0.55; box-shadow: 2px 2px 0 var(--ink); }
  body.is-touch .pad.is-down { opacity: 0.85; }
  body.is-touch .dpad { grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(3, 44px); }
  body.is-touch .pad svg { width: 24px; height: 24px; }
  /* tauko vasempaan yläreunaan, ettei peitä ruudun alalaidan ohjetekstiä */
  body.is-touch .pad--small { position: fixed; top: calc(44px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left)); width: 42px; height: 42px; }
  body.is-touch .pad--action { width: 96px; height: 96px; font-size: 24px; }
}

/* ---------------------------------------------------------------- ohjelmalehtinen */
.playbill {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.5fr);
  gap: 40px;
  margin: 70px 0 40px;
  align-items: start;
}

.playbill__intro {
  position: sticky;
  top: 20px;
  padding: 26px 26px 20px;
  background: var(--cream);
  color: var(--ink);
  border: 4px solid var(--ink);
  box-shadow: 8px 8px 0 var(--crimson);
  transform: rotate(-1.5deg);
  margin-top: -20px;
}
.playbill__intro h2 {
  margin: 0 0 10px;
  font: 400 34px/1 var(--display);
  color: var(--crimson);
}
.playbill__intro p { margin: 0 0 12px; }
.keys { font-size: 14px; color: #4A4560; }
kbd {
  display: inline-block;
  min-width: 26px;
  padding: 1px 6px;
  margin: 0 2px 4px 0;
  font: 700 13px var(--body);
  text-align: center;
  background: var(--ink);
  color: var(--mustard);
  border-radius: 5px;
}

.acts {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: act;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px 30px;
}
.acts li { position: relative; padding: 0 0 0 64px; }
.acts li:nth-child(even) { transform: translateY(26px); }
.acts span {
  position: absolute;
  left: 0;
  top: -4px;
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  font: 400 20px var(--display);
  color: var(--ink);
  background: var(--mustard);
  border: 3px solid var(--ink);
  border-radius: 50%;
  box-shadow: 3px 3px 0 var(--crimson);
}
.acts h3 { margin: 0 0 4px; font: 400 22px var(--display); color: var(--cream); }
.acts p { margin: 0; font-size: 15px; color: rgba(244, 230, 200, 0.78); }

/* ---------------------------------------------------------------- alatunniste */
.foot {
  max-width: 1180px;
  margin: 40px auto 0;
  padding: 24px;
  border-top: 2px dashed rgba(232, 163, 23, 0.4);
  font-size: 14px;
  color: rgba(244, 230, 200, 0.6);
}

@media (max-width: 820px) {
  .masthead { flex-direction: column; align-items: flex-start; }
  .masthead__tag { text-align: left; }
  .stage { padding: 8px 14px 14px; }
  .curtain { width: 14px; }
  .stage__tools { right: 20px; }
  .playbill { grid-template-columns: 1fr; margin-top: 50px; }
  .playbill__intro { position: static; }
  .acts { grid-template-columns: 1fr; }
  .acts li:nth-child(even) { transform: none; }
  main { padding: 0 12px; }
}
