/* Festival Mobile Controls — coarse pointer + landscape only. */
#festival-mobile-controls,
#festival-start-overlay,
#festival-orientation-guide {
  display: none;
}

@media (pointer: coarse) {
  html,
  body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
  }

  #scene {
    touch-action: none;
  }

  /* iOS Safari の長押し Callout / Text Selection は、操作UIだけでなく
     Canvas上の表示テキストや報酬パネルからも起動し得る。
     Festival内の明示したゲーム領域だけを対象にし、Desktopへは適用しない。 */
  #scene,
  #flash,
  #loading,
  #fest-hud,
  #fest-say,
  #fest-prompt,
  #fest-hint,
  #fest-reward,
  #fest-dl,
  #fest-tag,
  #festival-mobile-controls,
  #festival-start-overlay,
  #festival-orientation-guide {
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  /* Start Cardの実tap targetにも明示し、後段buttonのmanipulationを上書きする。 */
  #festival-start-overlay.is-visible,
  #festival-start-overlay.is-visible * {
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  #fest-hint,
  #fest-prompt {
    display: none;
  }

  #fest-tag {
    top: calc(10px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
    bottom: auto;
    max-width: 42vw;
    font-size: 10px;
  }
}

@media (pointer: coarse) and (orientation: landscape) {
  #festival-start-overlay.is-visible {
    position: fixed;
    inset: 0;
    z-index: 45;
    display: grid;
    place-items: center;
    padding:
      calc(18px + env(safe-area-inset-top))
      calc(24px + env(safe-area-inset-right))
      calc(18px + env(safe-area-inset-bottom))
      calc(24px + env(safe-area-inset-left));
    background:
      radial-gradient(circle at 50% 45%, rgba(137, 76, 31, .24), transparent 48%),
      rgba(11, 16, 32, .90);
    color: #fff1d9;
    text-align: center;
    pointer-events: auto;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  .festival-start-card {
    display: grid;
    justify-items: center;
    gap: 12px;
    width: min(430px, 72vw);
    padding: 24px 34px 22px;
    border: 1px solid rgba(235, 192, 126, .34);
    border-radius: 16px;
    background: rgba(24, 14, 9, .70);
    box-shadow: 0 14px 44px rgba(0, 0, 0, .48), inset 0 0 28px rgba(255, 173, 72, .04);
    backdrop-filter: blur(5px);
  }

  .festival-start-card strong {
    color: #ffe6bd;
    font: 650 21px/1.25 ui-sans-serif, system-ui, -apple-system, sans-serif;
    letter-spacing: .15em;
    text-shadow: 0 2px 12px rgba(0, 0, 0, .72);
  }

  #festival-start-button,
  #festival-start-without-sound {
    appearance: none;
    min-height: 52px;
    border-radius: 999px;
    font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  #festival-start-button {
    width: min(270px, 58vw);
    padding: 0 24px;
    border: 1px solid rgba(255, 233, 196, .70);
    background: linear-gradient(180deg, rgba(180, 105, 41, .96), rgba(113, 60, 24, .96));
    color: #fff8ed;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .38), 0 0 18px rgba(255, 180, 88, .10);
    font-size: 15px;
    font-weight: 750;
    letter-spacing: .13em;
  }

  #festival-start-button:active {
    transform: scale(.98);
  }

  #festival-start-status {
    min-height: 18px;
    color: #d9bd98;
    font: 500 12px/1.5 ui-sans-serif, system-ui, -apple-system, sans-serif;
    letter-spacing: .06em;
  }

  #festival-start-without-sound {
    display: none;
    min-height: 38px;
    padding: 0 18px;
    border: 1px solid rgba(226, 201, 169, .32);
    background: rgba(12, 8, 6, .48);
    color: #e0c7a8;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .08em;
  }

  #festival-start-without-sound.is-visible {
    display: block;
  }

  #festival-mobile-controls.is-enabled {
    position: fixed;
    inset: 0;
    z-index: 23;
    display: block;
    pointer-events: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  .festival-joystick,
  .festival-action,
  .festival-zoom button {
    pointer-events: auto;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
  }

  .festival-joystick {
    position: absolute;
    left: calc(16px + env(safe-area-inset-left));
    bottom: calc(14px + env(safe-area-inset-bottom));
    width: 116px;
    height: 116px;
    border-radius: 50%;
    background: rgba(10, 7, 5, .44);
    border: 1px solid rgba(255, 229, 190, .38);
    box-shadow: 0 5px 22px rgba(0, 0, 0, .34), inset 0 0 22px rgba(255, 190, 100, .05);
    backdrop-filter: blur(4px);
  }

  .festival-joystick-ring {
    position: absolute;
    inset: 20px;
    border-radius: 50%;
    border: 1px solid rgba(255, 233, 202, .2);
  }

  .festival-joystick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 48px;
    height: 48px;
    margin: -24px 0 0 -24px;
    border-radius: 50%;
    background: rgba(255, 225, 184, .86);
    border: 1px solid rgba(255, 255, 255, .62);
    box-shadow: 0 3px 13px rgba(0, 0, 0, .45);
    transition: background 100ms ease, box-shadow 100ms ease;
    will-change: transform;
  }

  .festival-joystick.is-pressed .festival-joystick-knob {
    background: rgba(255, 239, 215, .97);
    box-shadow: 0 2px 10px rgba(0, 0, 0, .48), 0 0 15px rgba(255, 196, 112, .3);
  }

  .festival-action,
  .festival-zoom button {
    appearance: none;
    border: 1px solid rgba(255, 231, 196, .44);
    color: #fff3df;
    background: rgba(18, 11, 7, .62);
    box-shadow: 0 4px 18px rgba(0, 0, 0, .35);
    backdrop-filter: blur(4px);
    font-family: ui-sans-serif, system-ui, -apple-system, "Hiragino Sans", sans-serif;
  }

  .festival-action {
    position: absolute;
    right: calc(18px + env(safe-area-inset-right));
    bottom: calc(14px + env(safe-area-inset-bottom));
    width: 84px;
    height: 62px;
    border-radius: 999px;
    display: none;
    font-size: 13px;
    font-weight: 750;
    letter-spacing: .1em;
  }

  .festival-action.is-available {
    display: block;
  }

  .festival-zoom {
    position: absolute;
    right: calc(24px + env(safe-area-inset-right));
    bottom: calc(94px + env(safe-area-inset-bottom));
    display: grid;
    gap: 8px;
  }

  .festival-zoom button {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    font: 400 28px/1 ui-sans-serif, system-ui, sans-serif;
  }

  .festival-action.is-pressed,
  .festival-zoom button.is-pressed {
    color: #fff;
    background: rgba(128, 77, 32, .84);
    border-color: rgba(255, 226, 178, .8);
    transform: scale(.96);
  }
}

@media (pointer: coarse) and (orientation: portrait) {
  /* SafariはDouble Tapの実targetになった子要素側のtouch-actionを参照する場合がある。
     Guide表示中だけrootから全テキストまで明示し、通常ゲームUIには広げない。 */
  #festival-orientation-guide.is-visible,
  #festival-orientation-guide.is-visible * {
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  #festival-orientation-guide.is-visible .festival-orientation-card {
    pointer-events: none;
  }

  #festival-orientation-guide.is-visible {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding:
      calc(24px + env(safe-area-inset-top))
      calc(24px + env(safe-area-inset-right))
      calc(24px + env(safe-area-inset-bottom))
      calc(24px + env(safe-area-inset-left));
    background:
      radial-gradient(circle at 50% 42%, rgba(78, 45, 22, .28), transparent 48%),
      rgba(11, 16, 32, .94);
    color: #f3dfc2;
    text-align: center;
    pointer-events: auto;
  }

  .festival-orientation-card {
    display: grid;
    gap: 10px;
    padding: 24px 30px;
    border: 1px solid rgba(230, 190, 130, .28);
    border-radius: 14px;
    background: rgba(20, 12, 8, .58);
    box-shadow: 0 12px 38px rgba(0, 0, 0, .42);
  }

  .festival-orientation-card strong {
    font: 600 19px/1.3 ui-sans-serif, system-ui, -apple-system, sans-serif;
    letter-spacing: .06em;
  }

  .festival-orientation-card span {
    font: 500 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Hiragino Sans", sans-serif;
  }

  .festival-orientation-card small {
    color: #d8b892;
    font: 400 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
    letter-spacing: .08em;
  }
}

@media (pointer: coarse) and (max-height: 410px) and (orientation: landscape) {
  .festival-start-card {
    gap: 8px;
    padding: 16px 28px 14px;
  }

  #festival-start-button {
    min-height: 48px;
  }

  .festival-joystick {
    width: 108px;
    height: 108px;
  }

  .festival-joystick-ring {
    inset: 18px;
  }

  .festival-action {
    width: 80px;
    height: 58px;
  }

  .festival-zoom {
    bottom: calc(88px + env(safe-area-inset-bottom));
  }

  .festival-zoom button {
    width: 50px;
    height: 50px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .festival-joystick-knob {
    transition: none;
  }
}
