:root {
  --primary: #ff5722; /* 燃えるような練習のオレンジ */
  --bg: #202020;
  --panel: #2d2d2d;
  --text: #ffffff;
  --accent: #00bcd4;
}

/* --- Responsive (Tablet: keep side-by-side panels, allow toggle) --- */
@media (max-width: 1366px) and (min-width: 769px) {
  header {
    flex-wrap: wrap;
    gap: 6px;
    height: auto;
    padding: 10px;
  }
  .controls {
    flex-wrap: wrap;
    gap: 6px;
    row-gap: 4px;
  }
  button,
  label.file-btn {
    padding: 5px 10px;
    min-height: 30px;
    font-size: 12px;
    white-space: nowrap;
  }
  select {
    padding: 5px 8px;
    font-size: 12px;
    white-space: nowrap;
  }
  .pen-controls {
    gap: 4px;
    flex-wrap: nowrap;
  }
  .pen-width-display {
    font-size: 11px;
  }
  .timer-display {
    margin: 0 6px;
  }
  #top-control-group {
    display: none;
    flex-wrap: wrap;
    width: 100%;
  }
  body.top-controls-open #top-control-group {
    display: flex;
  }
  #top-controls-toggle {
    display: flex;
  }
  main {
    flex-direction: row;
  }
  #threed-area {
    border-right: 4px solid var(--panel);
    border-bottom: none;
    height: auto;
  }
  #canvas-area {
    height: auto;
  }
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  /* iOS/iPadOS: 100vh can include browser UI and cause clipping; prefer dynamic viewport units */
  min-height: 100vh;
  height: 100dvh;
  font-family: "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ヘッダー */
header {
  /* Add breathing room (desktop): avoid touching window edge and panels below */
  padding: calc(10px + env(safe-area-inset-top, 0px)) 20px 8px;
  height: auto;
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  flex-wrap: wrap;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  z-index: 100;
}

/* ロゴデザイン */
.brand {
  font-size: 24px;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand span.en {
  color: var(--primary);
}
.brand span.jp {
  font-size: 16px;
  font-weight: normal;
  opacity: 0.8;
  font-style: normal;
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.brand { flex: 0 0 auto; }

/* Header layout: primary + quick + drawer */
#primary-controls { flex: 1 1 520px; justify-content: flex-end; }
#quick-controls { flex: 1 1 100%; justify-content: flex-end; }

.movable-controls-slot {
  width: 100%;
}

/* Default: keep header layout unchanged (wrapper should not affect flex layout) */
#quick-controls .movable-controls {
  display: contents;
}

/* When moved into the drawer, show as a proper group */
#top-control-group .movable-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

#top-control-group .movable-controls .control-sep {
  display: none;
}

.control-sep {
  width: 1px;
  height: 20px;
  background: #555;
  margin: 0 4px;
  display: inline-block;
}

/* Drawer panel (desktop: inline under header; mobile: bottom sheet) */
#top-control-group.controls-drawer {
  display: none;
  width: 100%;
  flex: 1 1 100%;
  padding: 10px 12px;
  margin-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(45, 45, 45, 0.98);
  border-radius: 10px;
}
body.top-controls-open #top-control-group.controls-drawer {
  display: flex;
}

#top-controls-backdrop {
  display: none;
}
body.top-controls-open #top-controls-backdrop {
  display: block;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 90;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Eraser button: show a clear circular "range" icon */
#eraser-btn {
  position: relative;
  width: 42px;
  min-width: 42px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#eraser-btn::before {
  content: "";
  width: var(--eraser-icon-size, 18px);
  height: var(--eraser-icon-size, 18px);
  border-radius: 9999px;
  border: 2px solid rgba(255,255,255,0.85);
  background: rgba(255,255,255,0.08);
  box-sizing: border-box;
}
#eraser-btn.active::before {
  border-color: rgba(0,188,212,1);
  background: rgba(0,188,212,0.18);
  box-shadow: 0 0 0 4px rgba(0,188,212,0.12);
}

/* Eraser cursor on canvas */
#brush-cursor {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cursor-size, 18px);
  height: var(--cursor-size, 18px);
  transform: translate(-50%, -50%);
  border-radius: 9999px;
  border: 2px solid rgba(0,0,0,0.55);
  background: rgba(255,255,255,0.28);
  box-sizing: border-box;
  pointer-events: none;
  display: none;
}
#canvas-area.eraser-active {
  cursor: none;
}
#canvas-area.eraser-active #brush-cursor {
  display: block;
}

/* Layers panel (Photoshop-like minimal) */
#layers-panel {
  position: absolute;
  right: 10px;
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  width: 220px;
  max-width: calc(100% - 20px); /* prevent clipping when the sketch panel is narrow */
  box-sizing: border-box;
  /* iOS/iPadOS: vh can be larger than the *visible* viewport (browser UI), causing clipping */
  max-height: 55vh;
  max-height: 55dvh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 10px;
  background: rgba(30, 30, 30, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
  color: #eee;
  pointer-events: auto;
  z-index: 10;
}
.layers-header-actions {
  display: inline-flex;
  gap: 6px;
}
.layers-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.layers-title {
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.4px;
  opacity: 0.9;
}
#layers-panel button {
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
}
.layers-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
  padding-right: 4px;
}
.layer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
  user-select: none;
}
.layer-row.active {
  border-color: rgba(0, 188, 212, 0.8);
  box-shadow: 0 0 0 3px rgba(0, 188, 212, 0.12);
}
.layer-vis {
  width: 26px;
  min-width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 14px;
}
.layer-name {
  flex: 1;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.layers-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.layers-footer > button {
  /* Make icon buttons fit in a single row within 220px panel (content ~200px) */
  width: 24px;
  min-width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 0;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
}
.layers-opacity {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
}
#layer-opacity {
  width: 120px;
  flex: 1;
}

#layer-blend {
  flex: 1;
  min-width: 0;
}

/* Show/hide toggle for layers window */
#layers-fab {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 9999px;
  background: rgba(30, 30, 30, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #eee;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}
#layers-fab .layers-fab-icon {
  font-size: 14px;
}
#layers-fab .layers-fab-text {
  font-size: 12px;
}
#canvas-area.layers-hidden #layers-panel {
  display: none;
}
#canvas-area.layers-hidden #layers-fab {
  display: inline-flex;
}

@media (max-width: 768px) {
  #layers-panel {
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    width: min(260px, calc(100% - 16px));
    max-height: 45vh;
  }

  /* Prevent label wrap that breaks the layout on narrow screens */
  #layers-panel .layers-opacity {
    flex-wrap: nowrap;
  }
  #layers-panel .layers-opacity .control-label {
    width: 56px;
    min-width: 56px;
    margin-right: 0;
    white-space: nowrap;
    font-size: 11px;
    opacity: 0.85;
  }
  #layers-panel #layer-opacity {
    flex: 1 1 auto;
    min-width: 0;
  }
  #layers-panel #layer-opacity-display {
    min-width: 44px;
    text-align: right;
    font-size: 11px;
    opacity: 0.85;
  }
  #layers-panel #layer-blend {
    flex: 1 1 auto;
    min-width: 0;
  }

  /* Slightly larger tap targets */
  #layers-panel .layers-footer > button {
    width: 26px;
    min-width: 26px;
    height: 26px;
    min-height: 26px;
  }
}
.mobile-toggle {
  display: inline-flex;
  padding: 6px 10px;
  background: #333;
  border: 1px solid #555;
  border-radius: 4px;
  color: #eee;
  font-weight: bold;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

/* Primary / Accent / Neutral */
button#start-btn {
  background: var(--primary);
  color: #fff;
  min-width: 80px;
}
.btn-accent {
  background: var(--accent);
  color: #000;
  box-shadow: 0 0 8px rgba(0, 188, 212, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-sizing: border-box;
}

/* Toggle buttons: show a checkmark when active for consistency */
.toggle-btn {
  position: relative;
  padding-left: 22px;
}
.toggle-btn::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 50%;
  width: 8px;
  height: 8px;
  transform: translateY(-50%);
  border-radius: 9999px;
  border: 2px solid rgba(255,255,255,0.55);
  box-sizing: border-box;
}
.toggle-btn.active::before {
  content: "✓";
  width: auto;
  height: auto;
  border: none;
  color: #000;
  font-weight: 900;
}

/* Mobile-only: VRM interaction toggle (standard mode helper) */
#vrm-interact-toggle {
  display: none;
}
@media (pointer: coarse) {
  #vrm-interact-toggle {
    display: inline-flex;
  }
}

/* Long label resilience */
#quick-controls button,
#top-control-group button,
#top-control-group select {
  max-width: min(220px, 100%);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Pen panel (mobile collapsible) */
.pen-panel-toggle {
  display: none;
  background: #3a3a3a;
  border: 1px solid rgba(255,255,255,0.18);
}
body.pen-panel-open #pen-panel {
  display: flex;
}
.pen-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* ボタン類 */
button,
label.file-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  background: #444;
  color: #eee;
  font-size: 13px;
  transition: all 0.2s;
  min-height: 34px;
}
button:hover,
label.file-btn:hover {
  background: #666;
  transform: translateY(-1px);
}
button:active {
  transform: translateY(1px);
}
button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

button.active {
  background: var(--accent);
  color: #000;
  box-shadow: 0 0 8px rgba(0, 188, 212, 0.4);
}
select {
  padding: 6px 10px;
  border-radius: 4px;
  border: 1px solid #555;
  background: #333;
  color: #eee;
  font-weight: bold;
  font-size: 13px;
  cursor: pointer;
  appearance: none;
}
select:focus {
  outline: 2px solid var(--accent);
}
.control-label {
  font-size: 12px;
  opacity: 0.8;
  margin-right: 4px;
}

/* Character dropdown (next to VRM load) */
.character-picker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.character-picker .control-label {
  margin-right: 0;
  white-space: nowrap;
}

/* Make character dropdown stand out (primary entry point) */
#character-picker {
  position: relative;
  padding: 4px 6px;
  border-radius: 8px;
  background: rgba(0, 188, 212, 0.10);
  border: 1px solid rgba(0, 188, 212, 0.35);
}
#character-picker .control-label {
  opacity: 0.95;
  font-weight: 800;
}
#character-select {
  padding: 8px 34px 8px 12px; /* room for the ▼ */
  border-radius: 8px;
  border: 2px solid rgba(0, 188, 212, 0.75);
  background: #101416;
  color: #eaffff;
  font-weight: 900;
  font-size: 14px;
  min-width: 140px;
  box-shadow: 0 0 10px rgba(0, 188, 212, 0.25);
}
#character-select:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 188, 212, 0.35), 0 0 12px rgba(0, 188, 212, 0.35);
}
#character-picker::after {
  content: "▼";
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: rgba(234, 255, 255, 0.85);
  font-size: 11px;
}
input[type="color"] {
  width: 36px;
  height: 30px;
  padding: 2px;
  border: 1px solid #555;
  border-radius: 4px;
  background: #333;
  cursor: pointer;
}
input[type="range"] {
  width: 80px;
  accent-color: var(--accent);
}
.pen-width-display {
  min-width: 34px;
  text-align: right;
  font-size: 12px;
  opacity: 0.8;
}

input[type="file"] {
  display: none;
}
label.file-btn {
  background: var(--primary);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 5px;
  box-sizing: border-box; /* keep total height consistent with buttons */
}

/* Improve contrast for tutorial/manual */
#tutorial-btn,
#manual-btn {
  background: #4a4a4a;
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
}

/* Make sync/mode readable and consistent (accent-outline) */
#sync-btn,
#broadcast-btn,
#mode-toggle {
  background: rgba(0, 188, 212, 0.14);
  border: 1px solid rgba(0, 188, 212, 0.65);
  color: #eaffff;
}
#sync-btn.active,
#broadcast-btn.active {
  background: var(--accent);
  color: #000;
}

/* Mobile: fixed rows and bottom sheet */
@media (max-width: 768px) {
  button,
  label.file-btn,
  select {
    min-height: 44px;
  }
  button,
  label.file-btn {
    padding: 10px 14px;
  }
  #primary-controls { width: 100%; justify-content: flex-start; }
  #quick-controls {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap; /* allow pen panel to go to the next row */
    gap: 6px;
  }
  /* Hide separators in the compact action row */
  #quick-controls .control-sep { display: none; }

  /* Compact action buttons (undo/redo/clear/pen) as icon-sized */
  #undo-btn,
  #redo-btn,
  #clear-btn,
  #pen-panel-toggle {
    width: 44px;
    min-width: 44px;
    padding: 0;
    font-size: 18px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Keep the eraser icon button aligned with others */
  #eraser-btn {
    width: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .mobile-toggle { display: inline-flex; margin-left: auto; }

  /* Pen controls collapse by default on mobile */
  #pen-panel {
    display: none;
    width: 100%;
    flex: 0 0 100%;
    order: 999; /* always on the next row */
    padding-top: 8px;
    /* Designer-friendly layout: 2 columns x 2 rows (wraps to 1 col on very narrow widths) */
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 10px;
    align-items: stretch;
  }
  body.pen-panel-open #pen-panel {
    display: grid;
  }
  #pen-panel .pen-field {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 8px 10px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-sizing: border-box;
  }
  #pen-panel .pen-field .control-label {
    margin: 0;
    font-size: 11px;
    opacity: 0.85;
    white-space: nowrap;
  }
  #pen-panel .pen-field input[type="color"] {
    width: 34px;
    height: 34px;
    padding: 2px;
    border-radius: 8px;
  }
  #pen-panel .pen-field input[type="range"] {
    flex: 1 1 auto;
    min-width: 0; /* allow shrinking inside grid cell */
    width: auto;
  }
  #pen-panel .pen-field .pen-width-display {
    min-width: 44px;
    text-align: right;
    font-size: 11px;
    opacity: 0.85;
  }
  #pen-panel .pen-style select {
    flex: 1 1 auto;
    min-width: 0;
  }
  #pen-panel .pen-style .control-label {
    font-size: 14px;
    opacity: 0.7;
  }

  @media (max-width: 360px) {
    #pen-panel {
      grid-template-columns: 1fr;
    }
  }
  .pen-panel-toggle { display: inline-flex; }

  /* Bottom sheet drawer */
  #top-control-group.controls-drawer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    border-radius: 16px 16px 0 0;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    max-height: 70vh;
    overflow: auto;
    z-index: 100;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.45);
  }
}

.timer-display {
  font-family: "Courier New", monospace;
  font-size: 28px;
  font-weight: bold;
  color: var(--accent);
  min-width: 80px;
  text-align: center;
  background: #000;
  padding: 2px 8px;
  border-radius: 4px;
  margin: 0 10px;
}
.timer-display.is-infinite {
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 1px;
}

/* メインエリア */
main {
  display: flex;
  flex: 1;
  overflow: hidden;
  /* Flexbox: allow main to shrink so the header doesn't get squeezed/clipped on iOS */
  min-height: 0;
}

/* Desktop/tablet: keep a small gap so panels don't visually collide with header */
@media (min-width: 769px) {
  main {
    padding-top: 10px;
    box-sizing: border-box;
  }
}

/* App modes */
body.mode-standard main {
  position: relative;
  background: #ffffff; /* paper */
}
body.mode-standard #threed-area,
body.mode-standard #canvas-area {
  position: absolute;
  inset: 0;
  flex: none;
  height: auto;
  width: auto;
}
body.mode-standard #threed-area {
  background: transparent;
  border-right: none;
}
body.mode-standard #threed-area::before {
  display: none; /* hide grid pattern in tracing mode */
}
body.mode-standard #guide-overlay {
  opacity: 0.25;
}
body.mode-standard #canvas-area {
  background: transparent;
  cursor: crosshair;
}
body.mode-standard #splitter {
  display: none;
}

body.mode-advanced main {
  flex-direction: row;
}
@media (orientation: portrait) {
  body.mode-advanced main {
    flex-direction: column;
  }
}

.vrm-underlay-controls {
  display: none;
  align-items: center;
  gap: 6px;
}
body.mode-standard .vrm-underlay-controls {
  display: inline-flex;
}

/* Splitter (resizable boundary between 3D and sketch) */
#splitter {
  flex: 0 0 10px;
  position: relative;
  background: rgba(0, 0, 0, 0.15);
  cursor: col-resize;
  touch-action: none;
  user-select: none;
}
#splitter::before {
  content: "";
  position: absolute;
  top: 10%;
  bottom: 10%;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.18);
  border-radius: 9999px;
}
#splitter:hover::before {
  background: rgba(0, 188, 212, 0.6);
}
#splitter:focus {
  outline: 2px solid rgba(0, 188, 212, 0.8);
  outline-offset: -2px;
}

/* 左側：3D表示エリア */
#threed-area {
  flex: 1;
  background: #1a1a1a;
  position: relative;
  overflow: hidden;
  border-right: 4px solid var(--panel);
  /* Allow flex items to shrink even if their children have large intrinsic sizes */
  min-width: 0;
  min-height: 0;
}
/* グリッドのような背景パターン */
#threed-area::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: linear-gradient(#333 1px, transparent 1px),
    linear-gradient(90deg, #333 1px, transparent 1px);
  background-size: 50px 50px;
  opacity: 0.3;
  pointer-events: none;
}
/* ボタンで消せるUIグリッド */
#threed-area.hide-panel-grid::before {
  display: none;
}
/* 顔位置合わせ用の縦横ガイド */
#guide-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  background-image: linear-gradient(
      to right,
      transparent 49.6%,
      rgba(255, 255, 255, 0.35) 50%,
      transparent 50.4%
    ),
    linear-gradient(
      to bottom,
      transparent 49.6%,
      rgba(255, 255, 255, 0.35) 50%,
      transparent 50.4%
    );
  opacity: 0.45;
}

#loading-msg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.7);
  padding: 20px;
  border-radius: 8px;
}
#loading-msg h2 {
  margin: 0 0 10px 0;
  color: var(--primary);
}
#loading-msg p {
  margin: 0;
  font-size: 14px;
  color: #ccc;
}

/* 右側：描画エリア */
#canvas-area {
  flex: 1;
  background: #fff;
  position: relative;
  cursor: crosshair;
  touch-action: none;
  /* Allow flex items to shrink even if the canvas intrinsic size is larger */
  min-width: 0;
  min-height: 0;
}
canvas#drawing-board {
  display: block;
  /* Prevent intrinsic canvas size from forcing layout width during splitter drag */
  width: 100%;
  height: 100%;
}

/* --- Responsive (タブレット: PCと同じ左右分割を維持しつつメニュー開閉) --- */
@media (max-width: 1366px) and (min-width: 769px) {
  header {
    flex-wrap: wrap;
    gap: 6px;
    height: auto;
    padding: 10px;
  }
  .controls {
    flex-wrap: wrap;
    row-gap: 4px;
    gap: 6px;
  }
  button,
  label.file-btn {
    padding: 5px 10px;
    min-height: 30px;
    font-size: 12px;
  }
  select {
    padding: 5px 8px;
    font-size: 12px;
  }
  .pen-controls {
    gap: 4px;
  }
  .pen-width-display {
    font-size: 11px;
  }
  .timer-display {
    margin: 0 6px;
  }
  /* keep side-by-side layout, but allow toggle */
  #top-control-group {
    display: none;
    flex-wrap: wrap;
    width: 100%;
  }
  body.top-controls-open #top-control-group {
    display: flex;
  }
  #top-controls-toggle {
    display: flex;
  }
  main {
    flex-direction: row;
  }
  #threed-area {
    border-right: 4px solid var(--panel);
    border-bottom: none;
    height: auto;
  }
  #canvas-area {
    height: auto;
  }
}

/* --- Responsive (iPhoneなどモバイル向け) --- */
@media (max-width: 768px) {
  header {
    flex-wrap: wrap;
    gap: 6px;
    height: auto;
    padding: 10px;
  }
  .controls {
    flex-wrap: wrap;
    row-gap: 4px;
    gap: 6px;
  }
  button,
  label.file-btn {
    padding: 5px 10px;
    min-height: 30px;
    font-size: 12px;
  }
  select {
    padding: 5px 8px;
    font-size: 12px;
  }
  .pen-controls {
    gap: 4px;
  }
  .pen-width-display {
    font-size: 11px;
  }
  .timer-display {
    margin: 0 6px;
  }
  body.mode-advanced main {
    flex-direction: column;
  }
  #splitter {
    flex: 0 0 10px;
    cursor: row-resize;
  }
  #splitter::before {
    top: 50%;
    bottom: auto;
    left: 10%;
    right: 10%;
    width: auto;
    height: 2px;
    transform: translateY(-50%);
  }
  .controls {
    width: 100%;
  }
  body.mode-advanced #threed-area {
    flex: none;
    height: 40vh;
    border-right: none;
    border-bottom: 4px solid var(--panel);
  }
  body.mode-advanced #canvas-area {
    flex: none;
    height: 60vh;
  }

  /* If VRM panel is hidden, let canvas fill the remaining space (avoid black gap) */
  body.mode-advanced.vrm-hidden #threed-area {
    display: none !important;
    height: 0 !important;
    border-bottom: none !important;
  }
  body.mode-advanced.vrm-hidden #splitter {
    display: none !important;
  }
  body.mode-advanced.vrm-hidden #canvas-area {
    flex: 1 1 auto !important;
    height: auto !important;
    min-height: 0;
  }
  canvas#drawing-board {
    width: 100%;
    height: 100%;
  }
  #guide-overlay {
    pointer-events: none;
  }
  #top-control-group {
    display: none;
    width: 100%;
    flex-wrap: wrap;
  }
  body.top-controls-open #top-control-group {
    display: flex;
  }
  #top-controls-toggle {
    display: flex;
  }
}

/* --- Tutorial Highlight (SweetAlert2 + focus target) --- */
.tutorial-target {
  position: relative;
  z-index: 3000; /* above SweetAlert2 backdrop */
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  box-shadow: 0 0 0 8px rgba(0, 188, 212, 0.28);
  border-radius: 10px;
  animation: tutorialPulse 1.4s ease-in-out infinite;
}

/* SweetAlert2 (Tutorial only): keep the popup clickable while letting users interact with the app behind it */
.swal2-container.kaoren-tour-container {
  pointer-events: none;
  z-index: 4000;
}
.swal2-container.kaoren-tour-container .swal2-popup,
.swal2-container.kaoren-tour-container .swal2-actions,
.swal2-container.kaoren-tour-container .swal2-confirm,
.swal2-container.kaoren-tour-container .swal2-cancel,
.swal2-container.kaoren-tour-container .swal2-deny,
.swal2-container.kaoren-tour-container .swal2-close {
  pointer-events: auto;
}
@keyframes tutorialPulse {
  0% {
    box-shadow: 0 0 0 8px rgba(0, 188, 212, 0.22);
  }
  50% {
    box-shadow: 0 0 0 14px rgba(0, 188, 212, 0.34);
  }
  100% {
    box-shadow: 0 0 0 8px rgba(0, 188, 212, 0.22);
  }
}
.tutorial-action {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0, 188, 212, 0.1);
  border: 1px solid rgba(0, 188, 212, 0.35);
  font-weight: 700;
}

/* Sync modal (SweetAlert2) layout */
.swal2-popup .sync-form {
  text-align: left;
  font-size: 13px;
  line-height: 1.6;
}
.swal2-popup .sync-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px;
  align-items: center;
  margin: 10px 0;
}
.swal2-popup .sync-row label {
  opacity: 0.85;
}
.swal2-popup .sync-form .swal2-input,
.swal2-popup .sync-form .swal2-select {
  width: 100%;
  max-width: none;
  margin: 0;
}
.swal2-popup .sync-note {
  opacity: 0.75;
  font-size: 12px;
  margin-top: 8px;
}
@media (max-width: 420px) {
  .swal2-popup .sync-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

