:root {
  --bg: #141440;
  --ink: #fcfcfc;
  --pad: #bcbcbc;
  --pad-dark: #2c2c2c;
  --red: #d82800;
  --gold: #f8b800;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "DotGothic16", "Hiragino Kaku Gothic ProN", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: normal;
  color: var(--gold);
  letter-spacing: 1px;
}

.mini {
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  background: transparent;
  border: 2px solid #4c4c8c;
  padding: 4px 8px;
  cursor: pointer;
}

.screen-wrap {
  width: 100%;
  border: 4px solid #000;
  outline: 2px solid #4c4c8c;
  background: #000;
  line-height: 0;
}

#screen {
  width: 100%;
  height: auto;
  aspect-ratio: 256 / 240;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  display: block;
}

/* ---------- リザルトのシェアボタン ---------- */
.result-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.result-panel[hidden] { display: none; }
.share-row {
  display: flex;
  gap: 8px;
}
.btn {
  flex: 1;
  font: inherit;
  font-size: 15px;
  padding: 10px 6px;
  border: 3px solid #000;
  box-shadow: 0 4px 0 #000;
  cursor: pointer;
  color: #fff;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #000; }
.btn-x { background: #000; border-color: #fcfcfc; }
.btn-line { background: #06c755; }
.btn-share { background: #0058f8; }
.btn-next { background: var(--red); }
.btn-sub { background: #4c4c4c; flex: 0.5; }
.btn[hidden] { display: none; }
/* 結果画面の下に控えめに置く SNS アイコン */
.follow {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  font-size: 12px;
  color: #8c8cb8;
}
.follow a { color: #8c8cb8; display: flex; padding: 2px; }
.follow a:hover, .follow a:focus-visible { color: var(--ink); }
.follow svg { width: 18px; height: 18px; fill: currentColor; }

/* ---------- ファミコン風コントローラー ---------- */
.pad {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  background: linear-gradient(#d8d8d8, var(--pad));
  border: 3px solid #000;
  border-radius: 10px;
  padding: 14px 12px;
  color: #000;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.dpad {
  position: relative;
  width: 120px;
  height: 120px;
  touch-action: none;
}
.dpad .arm, .dpad .hub {
  position: absolute;
  background: var(--pad-dark);
  border: 2px solid #000;
}
.dpad .up    { left: 40px; top: 0; width: 40px; height: 44px; border-bottom: 0; border-radius: 4px 4px 0 0; }
.dpad .down  { left: 40px; bottom: 0; width: 40px; height: 44px; border-top: 0; border-radius: 0 0 4px 4px; }
.dpad .left  { left: 0; top: 40px; width: 44px; height: 40px; border-right: 0; border-radius: 4px 0 0 4px; }
.dpad .right { right: 0; top: 40px; width: 44px; height: 40px; border-left: 0; border-radius: 0 4px 4px 0; }
.dpad .hub   { left: 40px; top: 40px; width: 40px; height: 40px; border: 0; }
.dpad[data-dir~="up"] .up,
.dpad[data-dir~="down"] .down,
.dpad[data-dir~="left"] .left,
.dpad[data-dir~="right"] .right { background: #000; }

.mid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.pill {
  font: inherit;
  font-size: 11px;
  padding: 6px 12px;
  border-radius: 12px;
  border: 2px solid #000;
  background: #4c4c4c;
  color: #fff;
  touch-action: none;
}
.pill.on { background: #000; }
.brand {
  font-size: 10px;
  color: var(--red);
  text-align: center;
  line-height: 1.1;
}

.ab {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}
.ab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  text-align: center;
  line-height: 1.1;
}
.ab-btn:first-child { margin-top: 22px; }
.round {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 3px solid #000;
  background: var(--red);
  color: #fff;
  font: inherit;
  font-size: 20px;
  box-shadow: 0 4px 0 #6c1000;
  touch-action: none;
}
.round.on { transform: translateY(3px); box-shadow: 0 1px 0 #6c1000; background: #a81000; }

.help {
  margin: 0;
  font-size: 12px;
  line-height: 1.7;
  color: #bcbcf8;
}
kbd {
  font: inherit;
  border: 1px solid #6c6cac;
  padding: 0 4px;
  border-radius: 3px;
}
.foot p {
  margin: 0 0 4px;
  font-size: 11px;
  color: #7c7cbc;
}
.foot a {
  color: #bcbcf8;
}

/* リザルト中はパッドを隠してシェアボタンを押しやすく */
body.result .pad { display: none; }

/* マウス主体の端末ではコントローラーを小さく */
@media (hover: hover) and (pointer: fine) {
  .pad { opacity: 0.9; }
}
@media (pointer: coarse) {
  .keyboard-only { display: none; }
}

/* 横向きスマホ：画面とパッドを横並び */
@media (orientation: landscape) and (max-height: 520px) {
  .app {
    max-width: none;
    display: grid;
    grid-template-columns: 1fr minmax(0, calc((100dvh - 60px) * 256 / 240)) 1fr;
    grid-template-rows: auto 1fr auto;
    align-items: center;
    gap: 8px;
  }
  .topbar { grid-column: 1 / -1; }
  .screen-wrap { grid-column: 2; grid-row: 2; }
  .pad {
    display: contents;
  }
  .dpad { grid-column: 1; grid-row: 2; justify-self: center; }
  .mid { grid-column: 1 / -1; grid-row: 3; flex-direction: row; justify-content: center; }
  .ab { grid-column: 3; grid-row: 2; justify-self: center; }
  .result-panel { grid-column: 2; grid-row: 3; }
  .help, .foot { display: none; }
}
