:root {
  color-scheme: light;
  --bg: #ede0c4;
  --panel: #f8f1df;
  --panel-border: #d5c3a0;
  --accent: #b3261e;
  --accent-text: #fbf3e6;
  --text: #1c1710;
  --text-dim: #6f6247;
  --mongolian-font: 'Noto Sans Mongolian', 'Mongolian Baiti', 'MongolianWhite', 'Menksoft Qagan', sans-serif;
  --old-uyghur-font: 'Noto Serif Old Uyghur', serif;
}

@font-face {
  font-family: 'Noto Serif Old Uyghur';
  src: url('fonts/NotoSerifOldUyghur-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Noto Sans Mongolian';
  src: url('fonts/NotoSansMongolian-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overscroll-behavior: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
  flex-wrap: wrap;
  row-gap: 0.5rem;
}

.app__header h1 {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 1.25rem;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  flex-shrink: 0;
}

.header__controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

.mode-switch {
  position: relative;
  display: flex;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 2px;
  height: 2rem;
}

.mode-switch__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(50% - 2px);
  height: calc(100% - 4px);
  background: var(--accent);
  border-radius: 999px;
  transition: transform 0.2s ease;
}

.mode-switch.is-cyrillic .mode-switch__thumb,
.mode-switch.is-olduyghur .mode-switch__thumb {
  transform: translateX(100%);
}

.mode-switch__option {
  position: relative;
  z-index: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  width: 3rem;
  border-radius: 999px;
  transition: color 0.2s ease;
}

.mode-switch__option.is-active {
  color: var(--accent-text);
}

.app__main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 0.75rem;
  overflow: hidden;
  min-height: 0;
}

.panel--input {
  flex: 1 1 40%;
}

.panel--preview {
  flex: 1 1 60%;
}

.panel__label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.85rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
}

.panel__actions {
  display: flex;
  gap: 0.5rem;
}

.text-btn {
  background: none;
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
  font-size: 0.72rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  text-transform: none;
  letter-spacing: normal;
}

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

.input-area {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--mongolian-font);
  font-size: 1.4rem;
  line-height: 1.6;
  padding: 0.85rem;
  resize: none;
  outline: none;
  min-height: 0;
}

.input-area::placeholder {
  color: var(--text-dim);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 0.95rem;
}

.preview-scroll {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  display: flex;
  align-items: stretch;
  min-height: 0;
  position: relative;
  scroll-snap-type: x proximity;
  scroll-behavior: smooth;
}

.preview-track {
  position: relative;
  display: flex;
  align-items: stretch;
  --page-w: 100%;
  background-image:
    repeating-linear-gradient(
      to right,
      transparent 0,
      transparent calc(var(--page-w) - 1px),
      var(--panel-border) calc(var(--page-w) - 1px),
      var(--panel-border) var(--page-w)
    ),
    repeating-linear-gradient(
      to right,
      rgba(0, 0, 0, 0.035) 0,
      rgba(0, 0, 0, 0.035) var(--page-w),
      transparent var(--page-w),
      transparent calc(var(--page-w) * 2)
    );
}

.page-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  scroll-snap-align: start;
}

.preview-text {
  writing-mode: vertical-lr;
  text-orientation: mixed;
  font-family: var(--mongolian-font);
  font-size: 2rem;
  line-height: 1.5;
  padding: 1rem;
  white-space: pre-wrap;
  color: var(--text);
  box-shadow: inset 0 0 0 1px transparent;
}

.preview-text.is-old-uyghur {
  font-family: var(--old-uyghur-font);
}

.preview-text:empty {
  display: none;
}

.page-dots {
  display: flex;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.4rem 0;
  flex-shrink: 0;
}

.page-dots:empty {
  display: none;
}

.page-dots__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--panel-border);
  transition: background 0.2s ease;
}

.page-dots__dot.is-active {
  background: var(--accent);
}

.preview-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1.5rem;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.preview-warning {
  display: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.95rem;
}

.app__footer {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem calc(0.6rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--panel-border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.size-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.size-control input[type="range"] {
  width: 100px;
  accent-color: var(--accent);
}

.hint {
  font-size: 0.72rem;
  color: var(--text-dim);
  flex: 1 1 auto;
  min-width: 200px;
}

.credit-badge {
  position: fixed;
  right: calc(0.6rem + env(safe-area-inset-right));
  bottom: calc(0.6rem + env(safe-area-inset-bottom));
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.6rem 0.3rem 0.3rem;
  background: rgba(248, 241, 223, 0.9);
  backdrop-filter: blur(6px);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  text-decoration: none;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

.credit-badge:hover {
  border-color: var(--accent);
}

.credit-badge:hover .credit-badge__text {
  color: var(--accent);
}

.credit-badge__mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.credit-badge__text {
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
  transition: color 0.2s ease;
}

@media (max-width: 420px) {
  .credit-badge__text {
    display: none;
  }
  .credit-badge {
    padding: 0.3rem;
  }
}

/* Landscape / wider screens: side-by-side panels */
@media (min-width: 640px), (orientation: landscape) {
  .app__main {
    flex-direction: row;
  }
  .panel--input {
    flex: 1 1 40%;
  }
  .panel--preview {
    flex: 1 1 60%;
  }
}

@media (max-width: 420px) {
  .preview-text {
    font-size: 1.6rem;
  }
  .input-area {
    font-size: 1.2rem;
  }
  .mode-switch__option {
    width: 2.4rem;
  }
}

@media (max-width: 340px) {
  .app__header h1 {
    font-size: 1.1rem;
  }
  .header__controls {
    gap: 0.4rem;
  }
}
