/* Layout and controls follow Clap to Image. */
:root {
      --warm-panel: #f6f2e8;
      --warm-panel-soft: #edf4e7;
      --warm-line: #95ad89;
      --warm-line-soft: #bfd0b6;
      --warm-text: #273528;
      --warm-text-soft: #53634f;
      --warm-muted: #73806f;
      --warm-accent: #6f8f5f;
      --warm-accent-soft: #4f7044;
      --warm-accent-quiet: rgba(111, 143, 95, 0.14);
      --warm-rose: #b87362;
      --warm-record: #c76f58;
    }

    .page-container {
      max-width: 1300px !important;
      margin: 20px auto 48px !important;
      padding: 0 24px !important;
      display: flex !important;
      flex-direction: column !important;
      align-items: center !important;
    }

    .main-wrap {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 10px;
      width: 100%;
    }

.stage {
      width: 100%;
      display: flex;
      justify-content: center;
    }

    .col-view {
      display: flex;
      flex-direction: column;
      gap: 10px;
      align-items: center;
    }
    .preview-tip {
      width: 405px;
      max-width: calc(100vw - 24px);
      box-sizing: border-box;
      margin: 0;
      padding: 8px 10px;
      border: 1px solid var(--warm-line-soft);
      border-radius: 8px;
      background: rgba(246,242,232,0.72);
      color: var(--warm-text-soft);
      font-size: 0.82rem;
      font-weight: 800;
      line-height: 1.4;
      text-align: center;
    }
    .preview-tip[hidden] { display: none; }

    .ctrl-panel {
      width: 405px;
      max-width: calc(100vw - 24px);
      box-sizing: border-box;
      background: transparent;
      border: 0;
      border-radius: 0;
      padding: 0;
      display: flex;
      flex-direction: column;
      gap: 10px;
    }

.capture-zone {
      position: relative; width: 405px; height: 720px; background: #ffffff;
      display: flex; flex-direction: column; align-items: center; overflow: visible;
      transition: width 0.25s ease, height 0.25s ease;
    }
    .render-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
    .recording-indicator {
      position: absolute; top: 34px; left: 12px; z-index: 5; display: none;
      align-items: center; gap: 5px; color: var(--warm-record);
      font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em;
      pointer-events: none;
    }
    .capture-zone.recording .recording-indicator { display: flex; animation: recording-blink 1s ease-in-out infinite; }
    .recording-indicator-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warm-record); }
    @keyframes recording-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.2; } }
    .empty-image-source {
      position: absolute; left: 50%; top: 0; z-index: 4;
      width: 95%; transform: translateX(-50%);
    }
    .empty-image-source[hidden] { display: none; }
    .empty-image-picker {
      width: 100%; min-height: 170px;
      padding: 18px; border: 3px dashed var(--warm-accent); border-radius: 18px;
      background: var(--warm-accent-quiet); color: var(--warm-accent-soft);
      display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
      cursor: pointer; touch-action: manipulation;
      transition: border-color 0.15s, background 0.15s, transform 0.15s;
    }
    .empty-image-picker:hover { border-color: var(--warm-accent-soft); background: rgba(111,143,95,0.24); }
    .empty-image-picker.drag-over {
      border-color: var(--warm-record); background: rgba(199,111,88,0.14);
      box-shadow: 0 0 0 5px rgba(199,111,88,0.12);
    }
    .empty-image-picker:active { transform: scale(0.97); }
    .empty-image-picker:focus-visible { outline: 4px solid rgba(75,141,255,0.5); outline-offset: 3px; }
    .empty-image-picker-plus { font-size: 5rem; font-weight: 200; line-height: 0.8; }
    .empty-image-picker-text { font-size: 1.05rem; font-weight: 800; }
    .empty-image-drag-hint { display: none; color: var(--warm-muted); font-size: 0.84rem; font-weight: 700; }
    @media (hover: hover) and (pointer: fine) {
      .empty-image-drag-hint { display: block; }
    }

.sound-toggle {
      position: absolute; top: 5px; right: 5px; z-index: 6;
      width: 38px; height: 38px; padding: 0; border: 3px solid var(--warm-line-soft);
      border-radius: 50%; background: rgba(246,242,232,0.88); color: var(--warm-muted);
      font-size: 1.25rem; line-height: 1; cursor: pointer;
      display: flex; align-items: center; justify-content: center;
      transition: border-color 0.15s, background 0.15s, opacity 0.15s, transform 0.1s;
    }
    .sound-toggle:active { transform: scale(0.92); }
    .sound-toggle.on { border-color: var(--warm-record); background: #ffffff; color: var(--warm-text-soft); }
    .sound-toggle:not(.on) { background: #ffffff; color: var(--warm-text-soft); }
    .sound-toggle:not(.on)::after {
      content: ''; position: absolute; width: 26px; height: 3px; border-radius: 3px;
      background: var(--warm-record); transform: rotate(-45deg); pointer-events: none;
    }

.time-gauge { width: 405px; }
    .time-gauge-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; color: var(--warm-muted); font-size: 0.68rem; font-weight: 700; }
    .time-gauge-track { height: 6px; overflow: hidden; border: 1px solid var(--warm-line-soft); border-radius: 999px; background: #cfe1c7; }
    .time-gauge-fill { width: 0%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--warm-record), var(--warm-accent-soft)); transition: width 0.08s linear; }

    .action-row { display: flex; gap: 10px; width: 405px; max-width: calc(100vw - 24px); }
    .btn { min-width: 0; padding: 13px 16px; border: none; border-radius: 10px; font-size: 0.95rem; font-weight: 600; line-height: 1.15; cursor: pointer; transition: opacity 0.15s, transform 0.1s; white-space: normal; overflow-wrap: anywhere; }
    .btn:active { transform: scale(0.96); }
    .btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
    .btn-start { background: var(--warm-accent); color: #f8f5eb; flex: 1; }
    .btn-start:hover:not(:disabled) { background: var(--warm-accent-soft); }
    .btn-rec { background: var(--warm-record); color: #fffaf3; flex: 1; }
    .btn-rec:hover:not(:disabled) { background: #d9826a; }
    .btn-rec-stop { background: #73806f; color: #fffaf3; flex-shrink: 0; }
    .btn-rec-stop:hover:not(:disabled) { background: #657360; }

    .opt-row { display: flex; gap: 10px; width: 100%; }
    .opt-group { display: flex; flex-direction: column; flex: 1; min-width: 0; }
    .opt-label { display: none; }
    .ratio-select { display: flex; gap: 7px; width: 100%; }
    .ratio-btn {
      flex: 1; min-width: 0; min-height: 46px; padding: 10px 5px;
      border: 3px solid var(--warm-line-soft); border-radius: 10px;
      background: rgba(246,242,232,0.72); color: var(--warm-text-soft);
      font-size: 0.98rem; font-weight: 800; cursor: pointer;
      transition: border-color 0.15s, background 0.15s, color 0.15s, transform 0.1s;
      text-align: center;
    }
    .ratio-btn:active { transform: scale(0.96); }
    .ratio-btn.active { border-color: var(--warm-record); color: var(--warm-text-soft); background: rgba(246,242,232,0.72); }
    .setting-row {
      display: grid; grid-template-columns: 118px minmax(0, 1fr) 58px;
      align-items: center; gap: 10px; min-height: 54px; box-sizing: border-box;
      padding: 9px 12px; border: 2px solid var(--warm-line-soft); border-radius: 10px;
      background: rgba(246,242,232,0.72);
    }
    .setting-row label { min-width: 0; color: var(--warm-text-soft); font-size: 0.9rem; font-weight: 800; line-height: 1.15; white-space: normal; overflow-wrap: anywhere; }
    .setting-row input[type=range] { width: 100%; accent-color: var(--warm-accent); cursor: pointer; height: 26px; }
    .val-display { color: var(--warm-accent-soft); font-size: 0.9rem; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

    /* Recording/export progress follows Clap's centered loading treatment. */
    .saving-overlay { position: fixed; inset: 0; z-index: 9999; display: none; align-items: center; justify-content: center; background: rgba(39,53,40,0.42); backdrop-filter: blur(4px); pointer-events: none; }
    .saving-overlay.active { display: flex; }
    .saving-panel { width: min(300px,calc(100vw - 32px)); padding: 20px 18px 18px; border: 1px solid var(--warm-line); border-radius: 10px; background: var(--warm-panel); box-shadow: 0 20px 60px rgba(0,0,0,0.45); text-align: center; }
    .saving-track { height: 16px; overflow: hidden; border-radius: 999px; background: #cfe1c7; border: 1px solid var(--warm-line-soft); }
    .saving-fill { width: 0%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--warm-accent), var(--warm-rose)); transition: width 0.12s ease; }
    .saving-percent { margin-top: 8px; color: var(--warm-text-soft); font-size: 1.4rem; font-weight: 700; overflow-wrap: anywhere; }

    @media (max-width: 360px) {
      .ratio-btn { min-height: 42px; padding: 8px 3px; font-size: 0.86rem; }
      .setting-row { grid-template-columns: 104px minmax(0, 1fr) 48px; padding: 8px; gap: 7px; }
      .setting-row label { font-size: 0.8rem; }
    }

/* Hand Ta-Da uses Clap's preview column and action/control spacing. */
.game-title { margin: 0; color: var(--warm-text); font-size: 1.35rem; }
.main-wrap { max-width: 405px; }
.col-view { width: 100%; }
.capture-zone { width: 100%; height: auto; aspect-ratio: 1; overflow: hidden; transition: none; }
#previewCanvas { display: block; width: 100%; height: 100%; touch-action: none; }
#previewCanvas:focus-visible { outline: 3px solid var(--warm-accent); outline-offset: -3px; }
.preview-watermark {
  position: absolute; top: 10px; left: 12px; z-index: 7;
  color: #111; opacity: 0.5; pointer-events: none; user-select: none;
  font: 800 clamp(12px, 3.2vw, 16px)/1 Arial, Helvetica, sans-serif;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.9);
}
.capture-zone.drag-over { outline: 3px dashed var(--warm-record); }
.empty-image-source { top: 12px; width: calc(100% - 24px); }
.empty-image-picker { min-height: 145px; }
.preview-tip, .time-gauge, .action-row, .ctrl-panel { width: 100%; }
.upload-row { width: 100%; display: flex; gap: 8px; align-items: center; }
.upload-row .ratio-btn { flex: 1; font-size: 0.8rem; }
button:disabled { cursor: not-allowed; opacity: 0.4; }
[hidden] { display: none !important; }
.time-gauge-top { gap: 8px; min-height: 1.5em; }
#timeText { white-space: nowrap; }

/* Image selection controls match Clap. */
    .drag-wrap { position: absolute; cursor: grab; user-select: none; touch-action: none; z-index: 2; }
    .drag-wrap.dragging { cursor: grabbing; }
    .drag-wrap.selected { z-index: 3; outline: 2px solid #4b8dff; outline-offset: 2px; }
    .resize-handle {
      position: absolute; display: none; width: 18px; height: 18px; z-index: 4;
      border: 2px solid #fff; border-radius: 2px; background: #4b8dff;
      box-shadow: 0 0 0 1px rgba(27,66,128,0.65); touch-action: none;
    }
    .drag-wrap.selected .resize-handle { display: block; }
    .resize-handle[data-corner="nw"] { left: -11px; top: -11px; cursor: nwse-resize; }
    .resize-handle[data-corner="ne"] { right: -11px; top: -11px; cursor: nesw-resize; }
    .resize-handle[data-corner="sw"] { left: -11px; bottom: -11px; cursor: nesw-resize; }
    .resize-handle[data-corner="se"] { right: -11px; bottom: -11px; cursor: nwse-resize; }
    .rotate-handle {
      position: absolute; left: -13px; top: -13px; z-index: 5; display: none;
      width: 26px; height: 26px; padding: 0; border: 2px solid #fff; border-radius: 50%;
      background: #4b8dff; color: #fff; box-shadow: 0 0 0 1px rgba(27,66,128,0.65);
      font-size: 18px; font-weight: 700; line-height: 22px; text-align: center;
      cursor: grab; touch-action: none;
    }
    .rotate-handle:active { cursor: grabbing; }
    .drag-wrap.selected .rotate-handle { display: block; }
    .object-toolbar {
      position: absolute; left: 50%; bottom: calc(100% + 10px); z-index: 6;
      display: none; gap: 5px; transform: translateX(-50%); white-space: nowrap;
    }
    .drag-wrap.selected .object-toolbar { display: flex; }
    .object-toolbar button {
      padding: 4px 7px; border: 1px solid #4b8dff; border-radius: 5px;
      background: #fff; color: #2f67bd; font-size: 0.68rem; font-weight: 700;
      line-height: 1; cursor: pointer; box-shadow: 0 2px 7px rgba(27,66,128,0.2);
    }
    .object-toolbar button:hover { background: #edf4ff; }

.capture-zone { overflow: visible; }

/* Promotional cards and support button follow Clap. */
    .video-panel {
      width: min(360px, calc(100vw - 24px));
      margin: 58px auto 0;
      display: grid;
      grid-template-columns: 1fr;
      gap: 10px;
      padding: 14px;
      border: 1px solid var(--warm-line);
      border-radius: 16px;
      background: var(--warm-panel);
      box-shadow: 0 14px 36px rgba(39, 53, 40, 0.2);
      opacity: 0;
      visibility: hidden;
      pointer-events: none;
      transform: translateX(48px);
      transition:
        transform 0.7s cubic-bezier(0.22, 1, 0.36, 1),
        opacity 0.45s ease,
        visibility 0s linear 0.7s;
    }
    .video-panel.is-visible {
      opacity: 1;
      visibility: visible;
      pointer-events: auto;
      transform: translateX(0);
      transition-delay: 0s;
    }
    .video-panel-title {
      margin: 0 0 2px;
      color: var(--warm-text);
      font-size: 1.5rem;
      font-weight: 900;
      text-align: center;
    }
    .video-panel-link {
      display: block;
      overflow: hidden;
      border: 2px solid var(--warm-line-soft);
      border-radius: 12px;
      background: var(--warm-panel);
      box-shadow: 0 8px 22px rgba(39, 53, 40, 0.15);
      transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
    }
    .video-panel-link[hidden] {
      display: none;
    }
    .video-panel-item-title {
      display: flex;
      align-items: center;
      justify-content: center;
      flex-wrap: wrap;
      gap: 6px;
      padding: 8px 10px;
      color: var(--warm-text);
      font-size: 1.32rem;
      font-weight: 800;
      text-align: center;
    }
    .video-panel-shortcut {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      line-height: 1;
    }
    .video-panel-shortcut-icon {
      display: block;
      width: 1.15em;
      height: 1.15em;
      flex: 0 0 auto;
    }
    .video-panel-shortcut-text {
      font-size: 0.72em;
      font-weight: 900;
      line-height: 1;
      white-space: nowrap;
    }
    .video-panel-link:hover {
      border-color: var(--warm-accent);
      transform: translateY(-2px);
      box-shadow: 0 12px 28px rgba(39, 53, 40, 0.22);
    }
    .video-panel-link:focus-visible {
      outline: 3px solid rgba(75, 141, 255, 0.55);
      outline-offset: 3px;
    }
    .video-panel-media {
      display: block;
      width: 100%;
      height: auto;
      max-height: calc((100vh - 110px) / 2);
      object-fit: contain;
      background: #151a16;
      pointer-events: none;
    }
    @media (max-width: 899px) {
      .page-container {
        margin-bottom: 0 !important;
      }
      .video-panel {
        margin-top: 10px;
      }
    }
    @media (min-width: 900px) {
      .video-panel {
        position: fixed;
        top: 20px;
        right: 16px;
        z-index: 20;
        width: min(
          clamp(150px, 24vw, 420px),
          calc((100vw - 520px) / 2 - 20px)
        );
        margin: 0;
      }
    }
.game-support-button { display: flex; justify-content: center; width: 100%; }
