/* ========================================
   OHAV Creator - Style
   Theme: Dark & Aesthetic (#202023 / #f7f9fb)
   ======================================== */

:root {
  --bg-primary: #202023;
  --bg-secondary: #2a2a2e;
  --bg-tertiary: #35353a;
  --text-primary: #f7f9fb;
  --text-secondary: #a8aab0;
  --text-muted: #6b6d73;
  --accent: #8a7bce;
  --accent-hover: #a596e0;
  --border: #3e3e44;
  --border-light: #4a4a52;
  --danger: #c45c5c;
  --success: #5cba7d;
  --font-display: 'Cormorant Garamond', serif;
  --font-body: 'Noto Sans JP', sans-serif;
  --radius: 6px;
  --radius-lg: 10px;
  --transition: 0.2s ease;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-weight: 300;
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* ========== Header ========== */

.app-header {
  text-align: center;
  padding: 24px 20px 14px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.app-logo {
  height: 55px;
  width: auto;
  display: block;
  margin: 0;
}

.header-hashtag {
  position: absolute;
  right: 120px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.6rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.app-title {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 1.8rem;
  letter-spacing: 0.15em;
  color: var(--text-primary);
}

.app-subtitle {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 0.8rem;
  letter-spacing: 0.3em;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ========== Main Layout ========== */

.app-main {
  display: flex;
  gap: 0;
  height: calc(100vh - 90px);
}

/* ========== Canvas Section ========== */

.canvas-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.canvas-section::after {
  content: '';
  position: absolute;
  bottom: 10px;
  right: 30px;
  width: 240px;
  height: 240px;
  background: url('./ViNETlogo_white.png') no-repeat center / contain;
  opacity: 0.5;
  pointer-events: none;
  z-index: -1;
}

.canvas-toolbar {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: none;
}

.view-zoom-control {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: rgba(32, 32, 35, 0.85);
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.zoom-buttons {
  display: flex;
  align-items: center;
  gap: 4px;
}

.zoom-slider {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border-light);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--text-primary);
  cursor: pointer;
  transition: background var(--transition);
}

.zoom-slider::-webkit-slider-thumb:hover {
  background: var(--accent-hover);
}

.zoom-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--text-primary);
  cursor: pointer;
}

.zoom-slider::-moz-range-track {
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
}

.zoom-btn {
  width: 24px;
  height: 24px;
  border: 1px solid var(--border-light);
  border-radius: 3px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  line-height: 1;
}

.zoom-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.zoom-reset {
  font-size: 0.75rem;
  margin-left: 2px;
}

.zoom-value {
  font-size: 0.6rem;
  color: var(--text-muted);
  min-width: 32px;
  text-align: center;
}

.export-btn-float {
  width: auto;
  padding: 10px 24px;
  font-size: 0.9rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.canvas-wrapper {
  position: relative;
  background: #18181b;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: visible;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  background-image:
    linear-gradient(45deg, #2a2a2e 25%, transparent 25%),
    linear-gradient(-45deg, #2a2a2e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2a2e 75%),
    linear-gradient(-45deg, transparent 75%, #2a2a2e 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

#preview-canvas {
  display: block;
}

.interaction-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: default;
}

.canvas-notice {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
  letter-spacing: 0.02em;
}

/* ========== Control Panel ========== */

.control-panel {
  width: 320px;
  min-width: 320px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ========== Section Card (折りたたみ) ========== */

.section-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.section-card.warning {
  border-color: var(--danger);
}

.section-card.warning .section-header {
  background: rgba(196, 92, 92, 0.15);
}

.section-warning-text {
  font-family: var(--font-body);
  font-size: 0.6rem;
  color: var(--danger);
  font-weight: 400;
  margin-left: 6px;
}

.section-card.caution {
  border-color: #c9a825;
}

.section-card.caution .section-header {
  background: rgba(201, 168, 37, 0.15);
}

.section-caution-text {
  font-family: var(--font-body);
  font-size: 0.6rem;
  color: #c9a825;
  font-weight: 400;
  margin-left: 6px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.15);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}

.section-header:hover {
  background: rgba(0, 0, 0, 0.25);
}

.section-header.header-dragover {
  background: rgba(138, 123, 206, 0.2);
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}

.section-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: var(--text-primary);
}

.section-title-jp {
  font-family: var(--font-body);
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  margin-left: 4px;
}

.section-chevron {
  font-size: 0.6rem;
  color: var(--text-muted);
  transition: transform var(--transition);
}

/* ========== Section Footer & Clear Button ========== */

.section-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 4px;
}

.section-clear-text-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.65rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: all var(--transition);
}

.section-clear-text-btn:hover {
  color: var(--danger);
  background: rgba(196, 92, 92, 0.08);
}

/* ========== Wipe Section ========== */

.wipe-section {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.wipe-section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  cursor: pointer;
  user-select: none;
}

.wipe-section-header .wipe-add-btn {
  margin-left: auto;
}

.wipe-help-btn {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--border-light);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.wipe-help-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.wipe-chevron {
  transition: transform var(--transition);
}

.wipe-section.collapsed .wipe-chevron {
  transform: rotate(-90deg);
}

.wipe-section.collapsed .wipe-list {
  display: none;
}

.wipe-section.caution .wipe-section-header {
  background: rgba(201, 168, 37, 0.12);
  border-radius: var(--radius);
}

.wipe-section.caution .wipe-section-title {
  color: #c9a825;
}

.wipe-section-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.wipe-add-btn {
  background: none;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.65rem;
  padding: 3px 8px;
  cursor: pointer;
  transition: all var(--transition);
}

.wipe-add-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.wipe-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.wipe-list:empty {
  display: none;
}

/* ========== Wipe Item ========== */

.wipe-item {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color var(--transition);
}

.wipe-item.selected {
  border-color: var(--accent);
  background: rgba(138, 123, 206, 0.06);
}

.wipe-item.caution {
  border-color: #c9a825;
  background: rgba(201, 168, 37, 0.06);
}

.wipe-item.caution.selected {
  border-color: var(--accent);
  background: rgba(138, 123, 206, 0.06);
}

.wipe-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.wipe-item-title {
  font-size: 0.7rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.wipe-item-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.wipe-item-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.wipe-item-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  min-width: 50px;
  flex-shrink: 0;
}

.wipe-item-file {
  font-size: 0.6rem;
  color: var(--text-secondary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ========== Wipe Previews ========== */

.wipe-item-previews {
  display: flex;
  gap: 6px;
}

.wipe-preview-slot {
  flex: 1;
  height: 48px;
  border-radius: 4px;
  border: 1px solid var(--border);
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
}

.wipe-preview-slot img {
  height: 100%;
  width: auto;
  object-fit: contain;
}

.wipe-preview-slot.empty {
  border-style: dashed;
  border-color: var(--border-light);
}

.wipe-preview-label {
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 0.5rem;
  color: var(--text-muted);
  pointer-events: none;
}

.wipe-chara-remove-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--border-light);
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 0.6rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all var(--transition);
  z-index: 2;
}

.wipe-chara-remove-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(196, 92, 92, 0.15);
}

.wipe-drop-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 8px;
  border: 1px dashed var(--border-light);
  border-radius: 3px;
  cursor: pointer;
  transition: all var(--transition);
  min-height: 28px;
  font-size: 0.6rem;
  color: var(--text-muted);
}

.wipe-drop-area:hover {
  border-color: var(--accent);
  color: var(--accent-hover);
}

.wipe-drop-area.dragover {
  border-color: var(--accent);
  background: rgba(138, 123, 206, 0.1);
}

.section-card.collapsed .section-chevron {
  transform: rotate(-90deg);
}

.section-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.2s ease;
  max-height: 5000px;
  overflow: visible;
}

.section-card.collapsed .section-body {
  max-height: 0;
  padding: 0 10px;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}

/* ========== Mini Preview (collapsed) ========== */

.mini-preview {
  display: none;
  align-items: center;
  gap: 3px;
  margin-left: auto;
  margin-right: 8px;
  overflow: hidden;
  max-width: 160px;
}

.section-card.collapsed .mini-preview {
  display: flex;
}

.mini-preview-item {
  height: 24px;
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid var(--border);
  position: relative;
}

.mini-preview-item img {
  height: 100%;
  width: auto;
  object-fit: contain;
}

.mini-preview-item.hidden-layer {
  opacity: 0.3;
}

.mini-preview-item.hidden-layer::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 3px,
    rgba(0,0,0,0.4) 3px,
    rgba(0,0,0,0.4) 4px
  );
}

/* ========== Layer List ========== */

.layer-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.layer-list:empty {
  display: none;
}

/* ========== Layer Item ========== */

.layer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all var(--transition);
  cursor: pointer;
  user-select: none;
}

.layer-item:hover {
  border-color: var(--border-light);
}

.layer-item.selected {
  border-color: var(--accent);
  background: rgba(138, 123, 206, 0.08);
}

.layer-item.dragging {
  opacity: 0.5;
  border-color: var(--accent);
}

.layer-item.drag-over {
  border-top: 2px solid var(--accent);
}

.layer-item-grip {
  color: var(--text-muted);
  font-size: 0.7rem;
  cursor: grab;
  padding: 0 2px;
  line-height: 1;
}

.layer-item-thumb {
  width: 32px;
  height: 32px;
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--bg-primary);
}

.layer-item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.layer-item-name {
  flex: 1;
  font-size: 0.7rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer-item-actions {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

/* ========== Layer Item Buttons ========== */

.layer-btn {
  width: 22px;
  height: 22px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  line-height: 1;
}

.layer-btn:hover {
  border-color: var(--border-light);
  color: var(--text-secondary);
  background: var(--bg-tertiary);
}

.layer-btn.active {
  color: var(--accent);
}

.layer-btn.btn-lock.active {
  color: var(--accent);
}

.layer-btn.btn-flip {
  border: 1px solid var(--border-light);
}

.layer-btn.btn-flip.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(138, 123, 206, 0.1);
}

.layer-btn.btn-remove {
  width: 26px;
  height: 26px;
  font-size: 1rem;
}

.layer-btn.btn-remove:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(196, 92, 92, 0.1);
}

.layer-btn.btn-up,
.layer-btn.btn-down {
  font-size: 0.6rem;
}

/* ========== Layer Updown Wrapper ========== */

.layer-updown {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.layer-updown .layer-btn {
  width: 20px;
  height: 14px;
  font-size: 0.5rem;
}

/* ========== Layer Checkbox (表示切替) ========== */

.layer-checkbox {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
  flex-shrink: 0;
}

/* ========== Template UI ========== */

.preset-load-btn {
  width: 100%;
  padding: 10px;
  background: transparent;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: 0.03em;
}

.preset-load-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(138, 123, 206, 0.05);
}

.preset-modal-options {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
  display: flex;
  justify-content: flex-end;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 10px;
}

.preset-grid:empty::after {
  content: 'テンプレートなし';
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding: 8px;
  grid-column: 1 / -1;
}

.preset-thumb {
  width: 100%;
  border-radius: 4px;
  border: 2px solid var(--border);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.preset-thumb img {
  width: 100%;
  height: auto;
  display: block;
}

.preset-thumb:hover {
  border-color: var(--accent-hover);
  transform: scale(1.05);
}

.preset-empty {
  aspect-ratio: 1;
  border-style: dashed;
  border-color: var(--border-light);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
}

.preset-empty:hover {
  border-color: var(--accent);
  background: rgba(138, 123, 206, 0.05);
}

.preset-empty-icon {
  font-size: 1.8rem;
  color: var(--text-muted);
  line-height: 1;
}

.preset-empty:hover .preset-empty-icon {
  color: var(--accent);
}

.preset-category-label {
  grid-column: 1 / -1;
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 400;
  padding: 8px 0 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}

.preset-thumb-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  color: var(--text-primary);
  font-size: 0.6rem;
  padding: 2px 3px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preset-wipe-badge {
  position: absolute;
  top: 3px;
  left: 3px;
  background: var(--accent);
  color: #fff;
  font-size: 0.55rem;
  padding: 2px 5px;
  border-radius: 3px;
  line-height: 1.4;
  pointer-events: none;
}

.preset-new-badge {
  display: inline-block;
  background: #e6c42e;
  color: #fff;
  font-size: 0.55rem;
  font-weight: 500;
  padding: 2px 5px;
  border-radius: 3px;
  line-height: 1.4;
  margin-right: 6px;
  vertical-align: middle;
  animation: newBlink 1.5s ease-in-out infinite;
}

@keyframes newBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ========== Drop Area ========== */

.layer-drop-area {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border: 1px dashed var(--border-light);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  min-height: 72px;
}

.layer-drop-area:hover {
  border-color: var(--accent);
  background: rgba(138, 123, 206, 0.05);
}

.layer-drop-area.dragover {
  border-color: var(--accent);
  background: rgba(138, 123, 206, 0.12);
  box-shadow: inset 0 0 8px rgba(138, 123, 206, 0.1);
}

.drop-area-text {
  font-size: 0.7rem;
  color: var(--text-muted);
  pointer-events: none;
}

/* ========== Chara Slot ========== */

.chara-slot {
  min-height: 0;
}

.chara-slot:empty {
  display: none;
}

.slot-placeholder {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  padding: 8px;
}

.slot-placeholder:empty,
.slot-placeholder[hidden] {
  display: none;
}

/* ========== Output Block ========== */

.output-block {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.output-block-top {
  margin-top: 0;
}



.export-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.export-btn::after {
  content: attr(data-hover);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-hover);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 400;
  letter-spacing: 0.05em;
  opacity: 0;
  transition: opacity var(--transition);
}

.export-btn:hover::after {
  opacity: 1;
}

.export-btn:hover {
  background: var(--accent-hover);
  box-shadow: 0 2px 12px rgba(138, 123, 206, 0.3);
}

.export-btn:active {
  transform: scale(0.98);
}

.control-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  min-width: 32px;
}

.select-input {
  flex: 1;
  padding: 6px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-family: var(--font-body);
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition);
}

.select-input:hover,
.select-input:focus {
  border-color: var(--accent);
}

/* ========== Export Modal ========== */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modalFadeIn 0.2s ease;
}

.modal-overlay[hidden] {
  display: none;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 720px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.6);
}

.modal-content-sm {
  max-width: 480px;
}

.modal-content-lg {
  max-width: 60vw;
}

.help-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

.help-text p {
  margin-bottom: 10px;
}

.help-text ul, .help-text ol {
  padding-left: 20px;
  margin-bottom: 10px;
}

.help-text li {
  margin-bottom: 4px;
}

.help-text strong {
  color: var(--text-primary);
}

.help-text a {
  color: var(--accent-hover);
  text-decoration: none;
  transition: color var(--transition);
}

.help-text a:visited {
  color: var(--accent-hover);
}

.help-text a:hover {
  text-decoration: underline;
}

.howto-terms-link {
  color: var(--accent-hover);
  text-decoration: none;
  font-size: 0.8rem;
  transition: color var(--transition);
}

.howto-terms-link:visited {
  color: var(--accent-hover);
}

.howto-terms-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.help-gif {
  margin-top: 12px;
  text-align: center;
}

.help-gif img,
.help-gif video {
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* ========== Howto Layout ========== */

.howto-layout {
  flex-direction: row !important;
  gap: 20px;
}

.howto-text {
  flex: 1;
}

.howto-video {
  flex-shrink: 0;
  width: 280px;
  display: flex;
  align-items: center;
}

.howto-video video {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

@media (max-width: 768px) {
  .howto-layout {
    flex-direction: column !important;
  }

  .howto-video {
    width: 100%;
  }

  .modal-content-lg {
    max-width: 80vw;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.2rem;
  letter-spacing: 0.1em;
  color: var(--text-primary);
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 1.4rem;
  cursor: pointer;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.modal-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.modal-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111114;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 200px;
}

.modal-preview img {
  max-width: 100%;
  max-height: 50vh;
  border-radius: 4px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

/* ========== Modal Adjust Row ========== */

.modal-adjust-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-adjust-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.btn-reset {
  width: auto;
  height: auto;
  padding: 4px 12px;
  font-size: 0.7rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-reset:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-reset:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#modal-canvas {
  max-width: 100%;
  max-height: 50vh;
  cursor: default;
}

#modal-canvas[hidden] {
  display: none !important;
}

#modal-canvas:not([hidden]) {
  display: block;
}

.modal-preview img.hidden-for-canvas {
  display: none;
}

.modal-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-control-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-download-btn {
  flex: 1;
}

.ios-save-notice {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: center;
  padding: 8px 0;
}

/* ========== Scrollbar ========== */

.control-panel::-webkit-scrollbar {
  width: 6px;
}

.control-panel::-webkit-scrollbar-track {
  background: transparent;
}

.control-panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.control-panel::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* ========== Header Help Button ========== */

.header-help-btn {
  position: absolute;
  right: 60px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.7rem;
  padding: 4px 10px;
  cursor: pointer;
  transition: all var(--transition);
}

.header-help-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ========== Footer ========== */

.app-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 8px;
  margin-top: auto;
  border-top: 1px solid var(--border);
}

.footer-link {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition);
}

.footer-link:hover {
  color: var(--accent);
}

.footer-copy {
  font-size: 0.6rem;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

/* ========== Hamburger Button ========== */

.hamburger-btn {
  display: none;
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px;
  transition: all var(--transition);
  z-index: 1001;
}

.hamburger-btn:hover {
  border-color: var(--accent);
}

.hamburger-line {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--text-primary);
  border-radius: 1px;
  transition: all 0.3s ease;
}

.hamburger-btn.active .hamburger-line:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.hamburger-btn.active .hamburger-line:nth-child(2) {
  opacity: 0;
}

.hamburger-btn.active .hamburger-line:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

/* ========== Panel Overlay (mobile) ========== */

.panel-overlay {
  display: none;
}

/* ========== Responsive ========== */

@media (max-width: 768px) {
  .app-header {
    padding: 6px 16px 5px;
  }

  .header-hashtag {
    display: none;
  }

  .app-logo {
    height: 30px;
    margin: 0 auto;
  }

  .canvas-section::after {
    bottom: 4px;
    right: 50%;
    transform: translateX(50%);
    width: 120px;
    height: 120px;
  }

  .view-zoom-control {
    position: absolute;
  }

  .canvas-wrapper {
    max-width: 96vw;
  }

  .app-title {
    font-size: 1.4rem;
  }

  .app-subtitle {
    font-size: 0.7rem;
  }

  .hamburger-btn {
    display: flex;
  }

  .app-main {
    height: calc(100vh - 70px);
  }

  .canvas-section {
    padding: 12px;
  }

  .canvas-toolbar {
    display: block;
  }

  .output-block-top {
    display: none;
  }

  .control-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 300px;
    height: 100vh;
    height: -webkit-fill-available;
    z-index: 1000;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    padding: 70px 12px 12px;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.5);
    overflow: scroll;
    -webkit-overflow-scrolling: touch;
    display: block;
  }

  .control-panel.open {
    transform: translateX(0);
  }

  .panel-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }

  .panel-overlay.active {
    display: block;
  }
}

@media (max-width: 480px) {
  .control-panel {
    width: 100%;
  }
}
