:root {
  --gb-bg: #ffffff;
  --gb-mid: #909090;
  --gb-ink: #181818;
  --gb-accent: #f0c840;
  --shell: #14161a;
  --font: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic",
    "Noto Sans JP", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--shell);
  color: #e8e8e0;
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  /* スマホで引っ張ったときのバウンスを止める(ゲーム画面が動くと誤タップになる) */
  overscroll-behavior-y: none;
}

/* ダブルタップ拡大を抑える。canvas以外もタップ操作が主なので全体に効かせる */
button, .chip, label, a { touch-action: manipulation; }

#app {
  max-width: 520px;
  margin: 0 auto;
  padding:
    calc(20px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(40px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
  position: relative;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel.center { align-items: center; text-align: center; }
[hidden] { display: none !important; }

.logo {
  font-size: 30px;
  letter-spacing: 2px;
  margin: 28px 0 0;
  color: var(--gb-accent);
  text-shadow: 3px 3px 0 #000;
}

h2 {
  font-size: 19px;
  margin: 12px 0 0;
  align-self: flex-start;
}

.lead { line-height: 1.9; font-size: 15px; opacity: .92; margin: 0; }
.sub { font-size: 13px; opacity: .7; margin: 0; line-height: 1.7; }
.fineprint { font-size: 11px; opacity: .5; line-height: 1.7; margin: 4px 0 0; }

/* ---- お題チップ ---- */
.presets {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 34vh;
  overflow-y: auto;
  padding: 2px;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}
.chip.preset {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  font-size: 14px;
  padding: 10px 12px;
  min-height: 46px;
  line-height: 1.45;
  background: rgba(255, 255, 255, .05);
  color: #e8e8e0;
  border: 2px solid rgba(255, 255, 255, .16);
  box-shadow: none;
}
.chip.preset:active { background: rgba(255, 255, 255, .12); }
.chip.preset .tag {
  flex: 0 0 auto;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--gb-accent);
  color: #181818;
  font-weight: 700;
}
.chip.preset .body { flex: 1 1 auto; }

/* ---- 入力 ---- */
textarea {
  width: 100%;
  font: inherit;
  font-size: 16px; /* iOSの自動ズーム回避 */
  line-height: 1.7;
  padding: 12px;
  color: var(--gb-ink);
  background: var(--gb-bg);
  border: 3px solid #000;
  border-radius: 6px;
  resize: vertical;
}
textarea::placeholder { color: var(--gb-mid); }
textarea:focus { outline: 3px solid var(--gb-accent); outline-offset: 2px; }

/* ---- ボタン ---- */
button {
  font: inherit;
  font-size: 15px;
  padding: 12px 18px;
  color: var(--gb-ink);
  background: var(--gb-bg);
  border: 3px solid #000;
  border-radius: 6px;
  cursor: pointer;
  min-height: 48px;
  box-shadow: 0 3px 0 #000;
  transition: transform .06s ease, box-shadow .06s ease;
}
button:active:not(:disabled) { transform: translateY(3px); box-shadow: none; }
button:disabled { opacity: .45; cursor: not-allowed; }

button.big { width: 100%; font-size: 18px; font-weight: 700; letter-spacing: 1px; }
button.big.ready { background: var(--gb-accent); }
button.mic { width: 100%; }
button.mic.rec { background: #e04030; color: #fff; }
button.ghost {
  background: transparent;
  color: #e8e8e0;
  border-color: rgba(255, 255, 255, .3);
  box-shadow: none;
}
button.small { font-size: 13px; min-height: 40px; padding: 8px 14px; }

.btn-row { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.btn-pair { display: flex; gap: 10px; }
.btn-pair button { flex: 1; font-size: 13px; padding: 10px 8px; }

.row { display: flex; align-items: center; gap: 12px; width: 100%; }
.row-label { font-size: 13px; opacity: .7; flex: 0 0 auto; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 8px 14px;
  min-height: 44px;
  font-size: 14px;
  background: transparent;
  color: #e8e8e0;
  border-color: rgba(255, 255, 255, .3);
  box-shadow: none;
}
.chip.on { background: var(--gb-accent); color: #181818; border-color: #000; }

/* ---- ゲーム画面 ---- */
/* 右上の丸ボタンが中身に被らないよう、上を空ける */
[data-screen="play"], [data-screen="result"] { padding-top: 44px; }

#screen {
  /* 画面の高さに収める。svh を使うのは iOS の URLバー伸縮で 100vh がズレるため */
  width: min(100%, 480px);
  width: min(100%, 480px, calc((100svh - 190px) * 160 / 144));
  aspect-ratio: 160 / 144;
  image-rendering: pixelated;
  border: 6px solid #000;
  border-radius: 8px;
  background: var(--gb-bg);
  cursor: pointer;
  touch-action: manipulation;
}

.loading { font-size: 16px; letter-spacing: 1px; margin: 60px 0; }

/* ---- 結果カード ---- */
.card-holder { width: 100%; }
.card-holder canvas {
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  border: 6px solid #000;
  border-radius: 8px;
  display: block;
}

/* ---- 隅のボタン ---- */
.corner-btns {
  position: fixed;
  right: calc(12px + env(safe-area-inset-right));
  top: calc(12px + env(safe-area-inset-top));
  display: flex;
  gap: 8px;
  z-index: 10;
}
.corner {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
}

@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
}

/* ---- キャラクター選択 ---- */
h2.self-center { align-self: center; }
.look-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}
.look-grid button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 4px;
  font-size: 12px;
  background: rgba(255, 255, 255, .05);
  color: #e8e8e0;
  border: 2px solid rgba(255, 255, 255, .16);
  box-shadow: none;
  min-height: 92px;
}
.look-grid button.on {
  background: var(--gb-accent);
  color: #181818;
  border-color: #000;
}
.look-grid canvas {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
}
.name-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}
.name-row input {
  flex: 1;
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  color: var(--gb-ink);
  background: var(--gb-bg);
  border: 3px solid #000;
  border-radius: 6px;
  min-height: 48px;
}
.name-row input:focus { outline: 3px solid var(--gb-accent); outline-offset: 2px; }

/* ---- スマホ ---- */
@media (max-width: 430px) {
  .logo { font-size: 26px; margin-top: 16px; }
  .lead { font-size: 14px; line-height: 1.8; }
  h2 { font-size: 17px; }
  .presets { max-height: 30vh; }
  .chip.preset { font-size: 13px; padding: 9px 10px; }
  .look-grid { gap: 8px; }
  .look-grid button { min-height: 84px; font-size: 11px; }
  .btn-pair button { font-size: 12px; }
}

/* 横向き: 画面の高さが足りないので canvas を高さ基準にし、余白を詰める */
@media (orientation: landscape) and (max-height: 500px) {
  #app { padding-top: calc(8px + env(safe-area-inset-top)); }
  .panel { gap: 8px; }
  #screen { width: min(100%, calc((100svh - 96px) * 160 / 144)); }
  .presets { max-height: 40vh; }
  .logo { margin-top: 4px; font-size: 22px; }
  .lead { display: none; }
}

/* ホーム画面から起動したとき(standalone)は上下の余白を少し足す */
@media (display-mode: standalone) {
  #app { padding-top: calc(28px + env(safe-area-inset-top)); }
}

/* ---- 共有 ---- */
.center-row { justify-content: center; }
.btn-pair .big { font-size: 15px; letter-spacing: 0; }
button.brand-x { background: #111; color: #fff; border-color: #000; }
button.brand-ig {
  background: linear-gradient(45deg, #f9ce34 0%, #ee2a7b 55%, #6228d7 100%);
  color: #fff;
  border-color: #000;
}
.card-holder canvas { max-height: 46svh; width: auto; margin: 0 auto; }
.result-lead { opacity: .6; margin: 0; }

@media (max-width: 430px) {
  .btn-pair .big { font-size: 14px; padding: 12px 6px; }
}

/* ---- 作者の他プロダクト ---- */
.products {
  width: 100%;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, .12);
}
.products-head { margin: 0 0 8px; font-size: 12px; opacity: .55; text-align: center; }
.products-list { display: flex; flex-direction: column; gap: 6px; }
.product {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  min-height: 46px;
  border: 2px solid rgba(255, 255, 255, .14);
  border-radius: 6px;
  color: #e8e8e0;
  text-decoration: none;
  background: rgba(255, 255, 255, .04);
}
.product:active { background: rgba(255, 255, 255, .1); }
.product-icon { font-size: 20px; flex: 0 0 auto; }
.product-body { display: flex; flex-direction: column; text-align: left; min-width: 0; }
.product-name { font-size: 14px; }
.product-desc { font-size: 11px; opacity: .6; }

/* PCでインスタに送るときのQR。ドットを潰さないよう拡大は整数倍で */
.qr-holder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 4px 0 12px;
}
.qr-canvas {
  width: 168px;
  height: 168px;
  image-rendering: pixelated;
  border: 4px solid #fff;
  border-radius: 4px;
  background: #fff;
}
.qr-url {
  font-size: 0.72rem;
  word-break: break-all;
  opacity: 0.8;
}

/* ストーリー動画のボタン。撮影中は押せないので見た目も落とす */
.brand-reel {
  background: linear-gradient(135deg, #6b3fa0, #c13584 60%, #f56040);
  color: #fff;
}
.brand-reel:disabled {
  filter: saturate(0.4) brightness(0.8);
  cursor: progress;
}
