* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #14142a; color: #eee;
  font-family: 'Press Start 2P', monospace;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation; overscroll-behavior: none;
}
#app {
  width: 100vw; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#game { display: block; image-rendering: pixelated; background: #000; touch-action: none; }
body:not(.touch) #game {
  width: min(96vw, 720px, calc((100vh - 24px) * 720 / 528)); height: auto;
  border: 6px solid #2a2a44; border-radius: 10px; box-shadow: 0 10px 40px #0008;
}

/* --- kosketusohjaimet --- */
#pad { display: none; }
body.touch #pad { display: flex; align-items: center; justify-content: space-between; touch-action: none; }
#dpad { position: relative; width: 156px; height: 156px; touch-action: none; flex: none; }
#dpad .arm, #dpad .hub { position: absolute; background: #3a3a5a; box-shadow: 0 4px 0 #1e1e33; }
#dpad .up, #dpad .down { left: 52px; width: 52px; height: 58px; }
#dpad .left, #dpad .right { top: 52px; width: 58px; height: 52px; }
#dpad .up { top: 0; border-radius: 10px 10px 0 0; }
#dpad .down { bottom: 0; border-radius: 0 0 10px 10px; }
#dpad .left { left: 0; border-radius: 10px 0 0 10px; }
#dpad .right { right: 0; border-radius: 0 10px 10px 0; }
#dpad .hub { left: 52px; top: 52px; width: 52px; height: 52px; box-shadow: none; }
#dpad .arm.on { background: #5a5a88; }
#dpad .arm::after { content: ''; position: absolute; left: 50%; top: 50%; border: 8px solid transparent; transform: translate(-50%, -50%); }
#dpad .up::after { border-bottom-color: #8888b0; margin-top: -4px; }
#dpad .down::after { border-top-color: #8888b0; margin-top: 4px; }
#dpad .left::after { border-right-color: #8888b0; margin-left: -4px; }
#dpad .right::after { border-left-color: #8888b0; margin-left: 4px; }

.right { display: flex; flex-direction: column; align-items: flex-end; gap: 18px; }
.ab { display: flex; gap: 16px; align-items: center; }
.ab button, .sys button { border: none; font: inherit; color: #fff; touch-action: none; }
.ab button { width: 74px; height: 74px; border-radius: 50%; background: #c03a4e; box-shadow: 0 5px 0 #6a1a28; font-size: 18px; }
.ab button[data-k="b"] { width: 58px; height: 58px; font-size: 14px; background: #8a3a4e; margin-top: 34px; }
.ab button.on { transform: translateY(4px); box-shadow: 0 1px 0 #6a1a28; }
.sys { display: flex; gap: 10px; }
.sys button { height: 30px; min-width: 44px; padding: 0 10px; border-radius: 15px; background: #2a2a44; font-size: 14px; color: #b8b8d8; }
#fs[hidden] { display: none; }

/* pystyasento: ruutu ylhäällä, ohjaimet alla peukaloiden ulottuvilla */
body.portrait #app { justify-content: flex-start; gap: 0; }
body.portrait #pad { flex: 1; width: 100%; padding: 8px 20px 14px; }

/* vaaka-asento: ristiohjain vasemmalla, napit oikealla */
body.landscape #app { flex-direction: row; justify-content: space-between; gap: 0; }
body.landscape #pad { display: contents; }
body.landscape #dpad { order: -1; margin-left: 16px; }
body.landscape .right { order: 2; margin-right: 16px; }

/* --- vapaa vastaus ja yhteenveto --- */
#ask, #results {
  position: fixed; inset: 0; z-index: 10; background: rgba(10, 10, 30, 0.6);
  display: flex; justify-content: center; align-items: flex-start;
  padding: calc(env(safe-area-inset-top) + 16px) 12px 12px;
}
#ask[hidden], #results[hidden] { display: none; }
.card {
  width: min(560px, 100%); max-height: 100%; overflow: auto;
  background: #f8f8f4; color: #383838; border: 5px solid #283050; border-radius: 12px;
  outline: 3px solid #7888b8; outline-offset: -11px;
  padding: 22px 22px 18px; font-size: 13px; line-height: 1.7;
  display: flex; flex-direction: column; gap: 12px;
}
.card .who, .card h2 { color: #3050a0; font-size: 12px; margin: 0; }
.card h2 { font-size: 16px; }
.card .q { margin: 0; }
.card .pic { width: 192px; height: 128px; image-rendering: pixelated; align-self: center; border: 3px solid #283050; border-radius: 6px; }
.card .word { text-align: center; font-size: 16px; letter-spacing: 2px; }
.card .hint { color: #c03a4e; font-size: 11px; }
#ans, #ans2 {
  font: inherit; font-size: 16px; padding: 12px; border: 3px solid #7888b8; border-radius: 8px;
  background: #fff; color: #222; -webkit-user-select: text; user-select: text;
}
.card button { font: inherit; font-size: 14px; padding: 14px; border: none; border-radius: 10px; background: #c03a4e; color: #fff; box-shadow: 0 4px 0 #6a1a28; }
#results .row { border-bottom: 2px dashed #c8c8d8; padding: 6px 0 10px; }
#results .row p { margin: 4px 0; }
#results .row b { color: #c03a4e; }
.card .label1 { font-size: 11px; color: #5a5a6a; margin-bottom: -4px; }
.card .label1[hidden] { display: none; }
.card .extra { display: flex; flex-direction: column; gap: 8px; font-size: 11px; color: #5a5a6a; }
.card .extra[hidden] { display: none; }
