* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  background-color: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100%;
  transition: background-color 0.3s, color 0.3s;
}

.app-container {
  display: grid;
  grid-template-columns: 1fr 400px;
  height: 100vh;
  height: 100dvh;
  width: 100%;
}

.sidebar-toggle { display: none; }

@media (max-width: 1180px) {
  .app-container {
    grid-template-columns: 1fr;
    height: auto;
    width: 100%;
    max-width: 100%;
  }
  .sidebar {
    height: auto;
    border-left: none;
    border-top: 1px solid var(--border);
    width: 100%;
    box-sizing: border-box;
  }
  .preview-header { padding: 40px 30px 16px; }
  .site-nav { gap: 16px; font-size: 8px; letter-spacing: 0.15em; }
  .preview-content { padding: 64px 40px 100px; }

  .sidebar-toggle {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 20;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 44px;
    padding: 10px 15px;
    border: 1px solid var(--fg);
    border-radius: 99px;
    background: var(--fg);
    color: var(--bg);
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    font: 700 12px var(--font-body);
    cursor: pointer;
  }
  .sidebar-toggle-icon { font-size: 18px; line-height: 12px; }
  .sidebar-collapsed .sidebar { display: none; }
  .sidebar-collapsed .preview-area { min-height: 100vh; min-height: 100dvh; }
  .sidebar-collapsed .preview-content { min-height: calc(100vh - 120px); min-height: calc(100dvh - 120px); }
}

@media (max-width: 768px) {
  .preview-area { padding: 0; min-height: 100vh; min-height: 100dvh; }
  .preview-header { padding: 24px 20px; }
  .preview-content {
    padding: 48px 10px 60px;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 120px);
    min-height: calc(100dvh - 120px);
  }
  .art-wrapper { margin: 20px auto !important; max-width: 100%; }
}

/* Snapshot Mode Overrides */
body.snapshot-active {
  overflow: hidden;
  background-color: white !important;
}

body.snapshot-active .sidebar,
body.snapshot-active .preview-header,
body.snapshot-active .vision-toggle {
  display: none !important;
}

body.snapshot-active .sidebar-toggle { display: none !important; }

body.snapshot-active .app-container {
  grid-template-columns: 1fr;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
}

body.snapshot-active .preview-area {
  height: 100vh;
  height: 100dvh;
  background: white !important;
  cursor: pointer;
}

body.snapshot-active .preview-content {
  padding: 0;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
}

body.snapshot-active .snapshot-hint {
  display: block;
}

/* Preview Area */
.preview-area {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
  overflow-y: auto;
  min-height: 500px;
  -webkit-overflow-scrolling: touch;
  transition: background-color 0.3s;
}

.preview-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 60px 100px;
  min-height: min-content;
  position: relative;
}

.preview-header {
  position: relative;
  top: 0;
  left: 0;
  width: 100%;
  padding: 32px 40px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 20px;
  z-index: 10;
  transition: background-color 0.3s;
  background: var(--bg);
}

.site-logo {
  height: 50px;
  width: auto;
  transition: filter 0.3s;
}

[data-theme='dark'] .site-logo {
  filter: invert(1) brightness(1.5);
}

.art-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: auto;
  flex-shrink: 0;
}

[data-theme='dark'] .art-wrapper {
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

.preview-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 400px;
  background: var(--bg);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
}

.reset-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--muted);
  transition: all 0.2s;
  text-transform: uppercase;
  width: 100%;
}
.reset-btn:hover { border-color: var(--accent); color: var(--accent); }
.reset-btn.active { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.reset-primary {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
  box-shadow: 0 4px 12px rgba(180, 75, 62, 0.22);
}
.reset-primary:hover { border-color: var(--danger-hover); background: var(--danger-hover); color: #fff; }
.reset-primary:focus-visible { outline: 3px solid rgba(180, 75, 62, 0.28); outline-offset: 2px; }

.section-title {
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.format-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.format-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.2s;
  color: var(--muted);
}
.format-card:hover:not(:disabled) {
  border-color: var(--accent);
}
.format-card.active {
  border-color: var(--fg);
  background: var(--fg);
  color: var(--bg);
  box-shadow: 0 4px 12px rgba(0,0,0,0.14);
  transform: scale(0.98);
}
.format-card:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.format-icon-box {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.format-icon {
  border: 1.5px solid currentColor;
  border-radius: 2px;
  position: relative;
}
.format-icon.standard { width: 18px; height: 24px; }
.format-icon.panoramic { width: 28px; height: 12px; }
.format-icon.square { width: 20px; height: 20px; }

.format-card span {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.format-card:focus-visible,
.tab-btn:focus-visible,
.orient-btn:focus-visible,
.reset-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.select-group label {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--muted);
  margin-bottom: 4px;
  display: block;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(4, 64px);
  gap: 8px;
}

.swatch { width: 64px; height: 64px; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; position: relative; transition: transform 0.2s; background-size: cover; }
.swatch:hover { transform: scale(1.1); z-index: 10; }
.swatch.active::after { content: ''; position: absolute; inset: -4px; border: 2px solid var(--accent); border-radius: 10px; }

.orientation-toggle { display: flex; gap: 8px; }
.orient-btn { flex: 1; padding: 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 13px; font-weight: 600; color: var(--fg); transition: all 0.2s; }
.orient-btn.active { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.orient-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Vision Toggle */
.vision-toggle {
  position: relative;
  display: flex;
  background: var(--bg);
  padding: 2px;
  border-radius: 99px;
  border: 1px solid var(--border);
  width: 140px;
  height: 36px;
}
.vision-btn {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px;
  border-radius: 99px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  transition: color 0.3s;
}
.vision-btn.active { color: var(--fg); }
.vision-slider {
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(50% - 2px);
  height: calc(100% - 4px);
  background: var(--surface);
  border-radius: 99px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transition: transform 0.3s cubic-bezier(0.23, 1, 0.32, 1);
}
[data-theme='dark'] .vision-slider { transform: translateX(100%); }

/* Snapshot Hint */
.snapshot-hint {
  display: none;
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  color: white;
  padding: 10px 20px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  z-index: 10001;
  pointer-events: none;
  white-space: nowrap;
}

body.snapshot-active .snapshot-hint {
  display: block;
}

.custom-size-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}
.custom-size-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.custom-size-field label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.custom-size-field input {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--fg);
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
}
.custom-size-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
}
.custom-size-field input::placeholder {
  color: var(--muted);
  font-family: var(--font-body);
}

.print-hint-overlay {
  position: fixed; inset: 0; z-index: 99999;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-body);
}
.print-hint-card {
  background: #fff; color: #222;
  border-radius: 16px; padding: 36px 40px;
  width: 380px; max-width: 90vw;
  text-align: center;
}
.print-hint-card h3 { margin: 0 0 8px; font-size: 20px; font-weight: 700; }
.print-hint-card p { margin: 0 0 20px; font-size: 14px; color: #666; line-height: 1.6; }
.print-hint-card kbd {
  display: inline-block;
  padding: 4px 10px; border-radius: 6px;
  background: #f0f0f0; border: 1px solid #ddd;
  font-family: var(--font-mono); font-size: 13px;
  font-weight: 600; color: #333;
}
.print-hint-card .ok-btn {
  padding: 10px 32px; border-radius: 99px;
  border: none; background: #111; color: #fff;
  font-weight: 700; font-size: 14px; cursor: pointer;
}

.print-screen-row { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }

.detection-badge { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; background: var(--fg); color: var(--bg); border-radius: 99px; font-size: 11px; font-weight: 700; margin-bottom: 12px; }

@media (max-width: 768px) {
  .print-screen-btn { display: none; }
}

@media (max-width: 1180px) {
  .preview-content { padding: 48px 60px 100px; }
}

/* Narrow-screen safeguard: keep the optional settings collapse control from covering sidebar inputs. */
@media (max-width: 360px) {
  .sidebar-toggle {
    position: static;
    display: flex;
    width: fit-content;
    margin: 12px auto 0;
    padding: 9px 12px;
    min-height: 40px;
    font-size: 11px;
  }
  .preview-content { padding-bottom: 20px; }
}
