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

html, body {
  height: 100%;
  background: var(--tg-theme-bg-color, #ffffff);
  color: var(--tg-theme-text-color, #000000);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Telegram theme fallbacks */
:root {
  --tg-theme-bg-color: #ffffff;
  --tg-theme-text-color: #000000;
  --tg-theme-hint-color: #999999;
  --tg-theme-link-color: #2481cc;
  --tg-theme-button-color: #2481cc;
  --tg-theme-button-text-color: #ffffff;
  --tg-theme-secondary-bg-color: #f0f0f0;
}

/* ==================== SCREENS ==================== */

.screen {
  display: none;
  height: 100vh;
  height: 100dvh;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

/* ==================== EDITOR SCREEN ==================== */

#screen-editor {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#screen-editor .container {
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
  min-height: 100%;
}

#screen-editor h2 {
  font-size: 18px;
  font-weight: 600;
}

/* Cover preview — square, Instagram format */
.cover-preview {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 10px;
}

/* Textarea — Telegram-like input */
textarea {
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: 12px;
  background: var(--tg-theme-secondary-bg-color, #f0f0f0);
  font-size: 16px;
  resize: none;
  min-height: 120px;
  max-height: 200px;
  font-family: inherit;
  color: var(--tg-theme-text-color, #000);
  line-height: 1.4;
}

textarea:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--tg-theme-button-color, #2481cc);
}

/* ==================== BUTTONS ==================== */

.btn {
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  width: 100%;
  text-align: center;
}

.btn:active {
  opacity: 0.7;
}

.btn-primary {
  background: var(--tg-theme-button-color, #2481cc);
  color: var(--tg-theme-button-text-color, #ffffff);
}

.btn-secondary {
  background: var(--tg-theme-secondary-bg-color, #f0f0f0);
  color: var(--tg-theme-text-color, #000);
}

/* ==================== PREVIEW SCREEN ==================== */

#screen-preview {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
}

#screen-preview .container {
  display: flex;
  flex-direction: column;
  padding-bottom: 16px;
}

#screen-preview h2 {
  font-size: 17px;
  font-weight: 600;
  padding: 12px 16px 4px;
}

/* Slide counter */
.carousel-nav {
  text-align: center;
  padding: 4px 16px 8px;
}

.slide-counter {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #999);
  font-weight: 500;
}

/* ==================== CAROUSEL ==================== */

.slides-grid {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  gap: 10px;
  padding: 0 16px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.slides-grid::-webkit-scrollbar {
  display: none;
}

/* Slide card — compact with padding, rounded */
.slide-card {
  flex: 0 0 calc(100vw - 48px);
  aspect-ratio: 1 / 1;
  scroll-snap-align: center;
  overflow: hidden;
  position: relative;
  border-radius: 12px;
  margin: 0;
  padding: 0;
}

/* Cover card — photo + editable title */
.cover-card {
  background: #000;
  position: relative;
}

.cover-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cover-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 0 8%;
}

.cover-title {
  color: #fff;
  font-size: 6.5vw;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  outline: none;
  cursor: text;
  width: 100%;
}

.cover-title:empty::before {
  content: 'Заголовок обложки';
  opacity: 0.5;
}

.cover-title:focus {
  background: rgba(255,255,255,0.15);
  border-radius: 6px;
  outline: 2px solid #fff;
  outline-offset: 4px;
}

/* HTML Slides — full bleed square */
.html-slide {
  width: 100%;
  height: 100%;
  position: relative;
  background: #f6eceb;
}

.html-slide .slide-bg {
  position: absolute;
  inset: 0;
  background-image: url('/webapp/static/bg_slides.png');
  background-size: cover;
  background-position: center;
}

.html-slide .slide-content {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0 6%;
  z-index: 2;
}

/* Hook — between top and center */
.html-slide .slide-hook {
  margin-top: 20%;
  font-size: 5.5vw;
  font-weight: bold;
  text-align: center;
  padding: 0 2%;
  color: #000;
  line-height: 1.25;
  outline: none;
  word-wrap: break-word;
  overflow-wrap: break-word;
  z-index: 3;
  cursor: text;
}

/* Body — bottom */
.html-slide .slide-body {
  margin-top: auto;
  margin-bottom: 10%;
  font-size: 3.8vw;
  text-align: center;
  padding: 0 3%;
  color: #000;
  line-height: 1.45;
  outline: none;
  word-wrap: break-word;
  overflow-wrap: break-word;
  z-index: 3;
  cursor: text;
}

/* Editable focus */
.html-slide .slide-hook:focus,
.html-slide .slide-body:focus {
  background: rgba(0,0,0,0.05);
  border-radius: 6px;
  outline: 2px solid var(--tg-theme-button-color, #2481cc);
  outline-offset: 2px;
}

.html-slide .slide-hook:empty::before {
  content: 'Заголовок';
  opacity: 0.3;
}

.html-slide .slide-body:empty::before {
  content: 'Описание';
  opacity: 0.3;
}

/* ==================== BOTTOM PANEL (caption + buttons) ==================== */

.bottom-panel {
  display: flex;
  flex-direction: column;
  padding: 8px 0 0;
}

/* Caption block — Telegram message bubble style */
.caption-block {
  margin: 8px 16px;
  padding: 10px 14px;
  background: var(--tg-theme-secondary-bg-color, #f0f0f0);
  border-radius: 12px 12px 12px 4px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--tg-theme-text-color, #000);
  max-height: 140px;
  overflow-y: auto;
  flex-shrink: 0;
  cursor: text;
  outline: none;
}

.caption-block:focus {
  box-shadow: 0 0 0 2px var(--tg-theme-button-color, #2481cc);
}

/* Enhance button — compact */
.btn-enhance {
  margin: 0 16px 8px;
  flex-shrink: 0;
  padding: 8px 14px;
  font-size: 13px;
  width: auto;
}

/* Action buttons row */
.actions {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  flex-shrink: 0;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.actions .btn {
  flex: 1;
}

/* ==================== LOADER ==================== */

.loader {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  gap: 14px;
}

.loader p {
  color: #fff;
  font-size: 15px;
  font-weight: 500;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==================== COVER TOOLS ==================== */

.cover-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px;
  align-items: center;
}

.cover-tools-row {
  display: flex;
  gap: 6px;
  align-items: center;
  width: 100%;
}

.cover-tools-label {
  font-size: 11px;
  color: var(--tg-theme-hint-color, #999);
  font-weight: 500;
  min-width: 48px;
}

.tools-section-label {
  width: 100%;
  font-size: 12px;
  font-weight: 600;
  color: var(--tg-theme-hint-color, #999);
  padding: 4px 0 0;
  border-top: 1px solid var(--tg-theme-secondary-bg-color, #eee);
  margin-top: 2px;
}

/* Font buttons */
.font-btn {
  padding: 6px 12px;
  border: 1.5px solid var(--tg-theme-hint-color, #ccc);
  border-radius: 8px;
  background: transparent;
  color: var(--tg-theme-text-color, #000);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.font-btn.active {
  border-color: var(--tg-theme-button-color, #2481cc);
  background: var(--tg-theme-button-color, #2481cc);
  color: var(--tg-theme-button-text-color, #fff);
}

.font-btn[data-font="serif"] {
  font-family: Georgia, 'Times New Roman', serif;
}

.font-btn[data-font="condensed"] {
  font-family: 'Arial Narrow', sans-serif;
  letter-spacing: -0.02em;
}

/* Color dots */
.color-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1);
}

.color-btn.active {
  border-color: var(--tg-theme-button-color, #2481cc);
  transform: scale(1.15);
}

/* Numeric size input — Word/Excel style */
.size-input {
  width: 56px;
  padding: 4px 6px;
  border: 1.5px solid var(--tg-theme-hint-color, #ccc);
  border-radius: 6px;
  background: var(--tg-theme-secondary-bg-color, #f0f0f0);
  color: var(--tg-theme-text-color, #000);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  -moz-appearance: textfield;
}

.size-input::-webkit-inner-spin-button,
.size-input::-webkit-outer-spin-button {
  opacity: 1;
  height: 24px;
}

.size-input:focus {
  outline: none;
  border-color: var(--tg-theme-button-color, #2481cc);
}

/* Position slider — same as size slider */
.position-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--tg-theme-hint-color, #ccc);
  outline: none;
}

.position-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--tg-theme-button-color, #2481cc);
  cursor: pointer;
}

.hidden {
  display: none !important;
}
