* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #121212;
  color: #f0ece4;
  font-family: system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

#sidebar {
  width: 340px;
  min-width: 340px;
  height: 100vh;
  overflow-y: auto;
  padding: 28px 22px 36px;
  background: linear-gradient(180deg, #1d1d1d 0%, #181818 100%);
  border-right: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  flex-direction: column;
  gap: 22px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

.sidebar-header {
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.sidebar-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.sidebar-subtitle {
  margin: 6px 0 0;
  font-size: 12px;
  opacity: 0.5;
}

.canvas-mode-section {
  margin-bottom: 0;
  border-top: none;
  padding-top: 0;
}

.canvas-mode-hint {
  margin-top: 12px;
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.mode-btn {
  padding: 11px 12px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: rgba(240, 236, 228, 0.72);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.mode-btn:hover {
  color: #f0ece4;
  background: rgba(255, 255, 255, 0.06);
}

.mode-btn.is-active {
  background: rgba(232, 220, 200, 0.16);
  border-color: rgba(232, 220, 200, 0.28);
  color: #f8f2e8;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset;
}

.hint.is-hidden {
  display: none;
}

#canvas-text-input {
  position: absolute;
  left: 0;
  top: 0;
  display: none;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: transparent;
  caret-color: #e8dcc8;
  outline: none;
  font-family: 'Source Serif 4', 'Noto Sans SC', serif;
  line-height: 1;
  min-width: 24px;
  z-index: 2;
}

#recording-indicator {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(12, 11, 10, 0.82);
  border: 1px solid rgba(196, 58, 48, 0.45);
  color: #ffd8d4;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  pointer-events: none;
  user-select: none;
}

#recording-indicator.is-hidden {
  display: none;
}

.recording-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c43a30;
  box-shadow: 0 0 8px rgba(196, 58, 48, 0.75);
}

.control-section {
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.control-section h2 {
  margin: 0 0 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.55;
}

.control-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  margin-bottom: 10px;
}

.control-row:last-child {
  margin-bottom: 0;
}

.control-row > label {
  font-size: 13px;
  font-weight: 500;
  opacity: 0.92;
  margin-bottom: 8px;
}

.control-input {
  display: flex;
  align-items: stretch;
  width: 100%;
}

.thick-slider {
  position: relative;
  width: 100%;
  height: 40px;
}

.thick-slider__face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.055);
  pointer-events: none;
  overflow: hidden;
}

.thick-slider:hover .thick-slider__face,
.thick-slider:focus-within .thick-slider__face {
  background: rgba(255, 255, 255, 0.07);
}

.thick-slider__fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  min-width: 0;
  background: rgba(255, 255, 255, 0.11);
  border-radius: 20px;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}

.thick-slider__fill.is-empty {
  opacity: 0;
}

.thick-slider__label {
  position: relative;
  z-index: 0;
  font-size: 12px;
  font-weight: 500;
  color: rgba(240, 236, 228, 0.52);
  white-space: nowrap;
}

.thick-slider__value {
  position: relative;
  z-index: 2;
  min-width: 36px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: rgba(255, 255, 255, 0.92);
}

.thick-slider__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: ew-resize;
  -webkit-appearance: none;
  appearance: none;
}

.thick-slider__input:focus {
  outline: none;
}

.thick-slider:focus-within .thick-slider__face {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.control-value {
  min-width: 44px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  opacity: 0.82;
}

#color-mode {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: #f0ece4;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

#color-mode:hover {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
}

#color-mode:focus {
  outline: none;
  border-color: rgba(232, 220, 200, 0.35);
}

.color-label.is-hidden {
  display: none;
}

input[type='color'] {
  width: 48px;
  height: 36px;
  padding: 2px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

input[type='color']:hover {
  border-color: rgba(255, 255, 255, 0.22);
  transform: translateY(-1px);
}

.export-section {
  margin-top: auto;
}

.export-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  color: #f0ece4;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.22);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-record.is-recording {
  background: rgba(196, 58, 48, 0.22);
  border-color: rgba(196, 58, 48, 0.55);
  color: #ffd8d4;
}

.btn-primary {
  background: rgba(232, 220, 200, 0.14);
  border-color: rgba(232, 220, 200, 0.35);
}

.btn-primary:hover {
  background: rgba(232, 220, 200, 0.22);
  border-color: rgba(232, 220, 200, 0.5);
}

.btn-compact {
  width: auto;
  flex: 1;
  padding: 8px 10px;
  font-size: 12px;
}

.bg-image-controls {
  flex-wrap: wrap;
}

.bg-image-label {
  margin: 0;
  font-size: 11px;
  line-height: 1.4;
  opacity: 0.45;
}

.export-hint {
  margin-top: 10px;
}

#archive-panel {
  width: 280px;
  min-width: 280px;
  height: 100vh;
  overflow-y: auto;
  padding: 28px 16px 36px;
  background: linear-gradient(180deg, #1d1d1d 0%, #181818 100%);
  border-left: 1px solid rgba(255, 255, 255, 0.07);
  color: #f0ece4;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

.archive-header {
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.archive-header h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.65);
}

.archive-subtitle {
  margin: 6px 0 0;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.45);
}

.archive-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.archive-empty {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.45);
}

.archive-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  color: #f0ece4;
  font: inherit;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.archive-item:hover {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.05);
  transform: translateY(-1px);
}

.archive-item.is-active {
  border-color: rgba(232, 220, 200, 0.45);
  background: rgba(232, 220, 200, 0.08);
}

.archive-thumb {
  width: 100%;
  aspect-ratio: 210 / 297;
  object-fit: cover;
  border-radius: 6px;
  background: #0c0b0a;
  display: block;
}

.archive-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.archive-name {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.92);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.archive-date {
  margin: 0;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.48);
}

.archive-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: rgba(12, 11, 10, 0.78);
  color: #f0ece4;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.archive-item:hover .archive-delete,
.archive-delete:focus-visible {
  opacity: 1;
}

.archive-delete:hover {
  background: rgba(196, 58, 48, 0.35);
  border-color: rgba(196, 58, 48, 0.5);
}

.hint {
  margin: 0;
  font-size: 11px;
  line-height: 1.55;
  opacity: 0.48;
}

.control-section.is-hidden {
  display: none;
}

.selection-label {
  margin: 0 0 12px;
  font-size: 13px;
  opacity: 0.85;
  word-break: break-word;
}

#canvas-panel {
  flex: 1;
  min-width: 0;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.05), transparent 55%),
    #111111;
}

.canvas-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 100%;
}

.canvas-tip {
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.4;
  letter-spacing: 0.01em;
  color: rgba(240, 236, 228, 0.72);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

#a4-frame {
  position: relative;
  box-shadow:
    0 28px 72px rgba(0, 0, 0, 0.48),
    0 0 0 1px rgba(255, 255, 255, 0.08);
  background: #0c0b0a;
  border-radius: 2px;
}

#a4-frame canvas {
  display: block;
  cursor: text;
  border-radius: 2px;
}

@media (max-width: 900px) {
  #app {
    flex-direction: column;
  }

  #sidebar {
    width: 100%;
    min-width: 0;
    height: auto;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  #canvas-panel {
    height: 45vh;
    padding: 20px;
  }

  .canvas-tip {
    font-size: 11px;
    padding: 7px 12px;
    text-align: center;
  }

  #archive-panel {
    width: 100%;
    min-width: 0;
    height: auto;
    max-height: 28vh;
    border-left: none;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }

  .archive-list {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .archive-item {
    min-width: 140px;
    flex: 0 0 140px;
  }
}
