:root {
  --bg: #f7f5f3;
  --bg-elevated: #fffdfa;
  --ink: #1c1917;
  --muted: #57534e;
  --faint: #a8a29e;
  --border: #e7e5e4;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: rgba(79, 70, 229, 0.12);
  --danger: #b91c1c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.04), 0 10px 28px rgba(28, 25, 23, 0.06);
  /* Amdo Classic as the primary Tibetan font */
  --font: "AmdoClassic", "Noto Sans Tibetan", "Microsoft Himalaya", "Tibetan Machine Uni", "DM Sans", system-ui, sans-serif;
  --font-tibt: "AmdoClassic", "Noto Sans Tibetan", "Microsoft Himalaya", "Tibetan Machine Uni", serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  background-image: radial-gradient(ellipse 120% 80% at 50% -20%, rgba(79, 70, 229, 0.06), transparent);
  /* Tibetan text needs more line height for stacked characters */
  line-height: 1.9;
  font-size: 1.05rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 252, 250, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar__inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.topbar__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar__mark {
  font-family: var(--font-tibt);
  font-size: 1.45rem;
  line-height: 1;
  color: var(--accent);
  opacity: 0.9;
}

.lang-switch {
  display: flex;
  padding: 3px;
  background: var(--border);
  border-radius: 999px;
  gap: 2px;
}

.lang-switch button {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.lang-switch button:hover {
  color: var(--ink);
}

.lang-switch button[aria-pressed="true"] {
  background: var(--bg-elevated);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* Main */
.main {
  flex: 1;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

.hero {
  text-align: center;
  margin-bottom: 2rem;
}

.hero__title {
  font-size: clamp(1.6rem, 4.5vw, 2rem);
  font-weight: 700;
  line-height: 1.5;
  margin: 0 0 1rem;
  color: var(--ink);
  font-family: var(--font-tibt);
}

.hero__lead {
  margin: 0 auto;
  max-width: 42rem;
  font-size: 1.05rem;
  color: var(--muted);
  line-height: 1.9;
  font-family: var(--font-tibt);
}

.hero__note {
  margin: 1rem auto 0;
  max-width: 38rem;
  font-size: 0.875rem;
  color: var(--faint);
  line-height: 1.8;
  font-family: var(--font-tibt);
}

/* Panel */
.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.25rem 1.5rem;
}

.panel__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  justify-content: center;
  gap: 0.75rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-tibt);
  font-size: 1rem;
  font-weight: 600;
  border-radius: 10px;
  padding: 0.7rem 1.25rem;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.5;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
}

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

.btn__icon {
  flex-shrink: 0;
  opacity: 0.92;
}

.btn--primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

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

.btn--ghost {
  background: var(--bg-elevated);
  color: var(--accent);
  border-color: var(--border);
}

.btn--ghost:hover:not([aria-disabled="true"]) {
  background: var(--accent-soft);
  border-color: rgba(67, 56, 202, 0.25);
}

.btn--ghost[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.file-load {
  position: relative;
  overflow: hidden;
}

.file-load input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.panel__meta {
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
  margin: 1rem 0 0;
  min-height: 1.5em;
  font-family: var(--font-tibt);
  line-height: 1.7;
}

.panel__error {
  color: var(--danger);
  font-size: 0.95rem;
  margin: 0.5rem 0 0;
  text-align: center;
  min-height: 0;
  font-family: var(--font-tibt);
  line-height: 1.7;
}

.panel__error:empty {
  display: none;
}

/* Output */
.output {
  margin-top: 1rem;
  padding: 1.25rem 1.5rem;
  min-height: 160px;
  max-height: min(56vh, 480px);
  overflow: auto;
  border-radius: 10px;
  background: #fafaf9;
  border: 1px solid var(--border);
  font-family: var(--font-tibt);
  font-size: 1.35rem;
  /* Tibetan text needs generous line height for vertical stacks */
  line-height: 2.1;
  white-space: pre-wrap;
  word-break: break-word;
}

.empty-hint {
  color: var(--faint);
  font-family: var(--font-tibt);
  font-size: 1rem;
  font-style: normal;
  line-height: 1.8;
}

/* Footer */
.footer {
  margin-top: auto;
  padding: 1.5rem 1.25rem 2rem;
  text-align: center;
}

.footer__text {
  margin: 0;
  font-size: 0.85rem;
  color: var(--faint);
  line-height: 1.7;
  max-width: 34rem;
  margin-left: auto;
  margin-right: auto;
  font-family: var(--font-tibt);
}

.footer a {
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

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

@media (max-width: 520px) {
  .panel__actions {
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }
}
