/* ============================================================
   Tibetan HWR — Design System
   Light theme · single-viewport · no external dependencies
   ============================================================ */

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

:root {
  --bg:          hsl(160, 22%, 96%);
  --surface:     hsl(160, 30%, 99%);
  --surface-2:   hsl(160, 18%, 93%);
  --border:      hsl(160, 20%, 87%);
  --border-2:    hsl(160, 18%, 74%);

  --primary:     hsl(160, 56%, 36%);
  --primary-dim: hsl(160, 56%, 26%);
  --primary-bg:  hsla(160, 56%, 36%, .08);
  --accent:      hsl(152, 60%, 50%);

  --text:        hsl(160, 22%, 12%);
  --text-dim:    hsl(160, 14%, 38%);
  --text-muted:  hsl(160, 10%, 60%);

  --radius:      10px;
  --radius-sm:   7px;
  --radius-lg:   14px;

  --shadow-sm: 0 1px 4px rgba(30, 100, 75, .08);
  --shadow:    0 4px 16px rgba(30, 100, 75, .10);
  --shadow-lg: 0 8px 32px rgba(30, 100, 75, .13);

  --t: 180ms ease;
}

/* ── Viewport lock ────────────────────────────────────────── */
html, body {
  height: 100dvh;
  overflow: hidden;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

h1, h2, h3 { line-height: 1.3; font-weight: 600; }
p { color: var(--text-dim); }

/* ── Header ───────────────────────────────────────────────── */
.header {
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.logo { display: flex; align-items: center; gap: .65rem; }

.logo-tibetan {
  font-size: 1.8rem;
  line-height: 1;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo h1 { font-size: .95rem; color: var(--text); }
.logo p  { font-size: .68rem; color: var(--text-muted); }

.mode-tabs {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 3px;
  gap: 2px;
}

.tab {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .32rem .95rem;
  border-radius: 50px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--t);
  white-space: nowrap;
}
.tab:hover { color: var(--text); background: var(--border); }
.tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px hsla(160, 56%, 36%, .3);
}
.tab-icon { font-size: .9rem; font-family: 'Noto Serif Tibetan', serif; }

/* ── Main ─────────────────────────────────────────────────── */
.main {
  flex: 1;
  min-height: 0;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: .85rem 1.25rem;
  overflow: hidden;
}

.card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  height: 100%;
}

/* ── Right column ─────────────────────────────────────────── */
.right-col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 0;
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: .7rem;
}

.card-title {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
}
.card-title svg { color: var(--primary); flex-shrink: 0; }

/* ── Left: input card ─────────────────────────────────────── */
.input-card {
  min-height: 0;
  overflow: hidden;
}

.canvas-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1.5px solid var(--border);
  background: #fff;
  box-shadow: inset 0 1px 4px rgba(30, 100, 75, .06);
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.canvas-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  color: var(--text-muted);
  pointer-events: none;
  transition: opacity var(--t);
}
.canvas-hint.hidden { opacity: 0; }

.canvas-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  flex-shrink: 0;
}

.pen-group {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .78rem;
  color: var(--text-dim);
}
.pen-group input[type="range"] {
  width: 80px;
  accent-color: var(--primary);
}

.btn-group { display: flex; gap: .4rem; }

/* ── Right top: action card ───────────────────────────────── */
.action-card { flex-shrink: 0; }

.action-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .6rem;
}

.btn-action {
  justify-content: center;
  padding: .65rem .5rem;
  font-size: .875rem;
  border-radius: var(--radius);
}

.action-hint {
  font-size: .72rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: -.1rem;
}

/* ── Right bottom: result card ────────────────────────────── */
.result-card {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .4rem .8rem;
  border-radius: var(--radius-sm);
  border: none;
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--t);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 10px hsla(160, 56%, 36%, .28);
}
.btn-primary:hover  { background: var(--primary-dim); transform: translateY(-1px); }
.btn-primary:active { transform: none; }

.btn-ghost {
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-2); background: var(--border); }

#uploadArea.drag-over {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-bg);
}

/* ── Result states ────────────────────────────────────────── */
.result-idle,
.result-loading,
.result-error {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .8rem;
  text-align: center;
  padding: 1rem;
}

.idle-char {
  font-size: 4rem;
  line-height: 1.4;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  opacity: .2;
  font-family: 'Noto Serif Tibetan', serif;
}

.result-error svg { color: var(--accent); opacity: .7; }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Result content ───────────────────────────────────────── */
.result-content {
  display: flex;
  flex-direction: column;
  gap: .9rem;
}

.result-hero {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  padding: .9rem 1.1rem;
  background: var(--primary-bg);
  border-radius: var(--radius);
  border: 1px solid hsla(160, 56%, 36%, .18);
  overflow: visible;
}

.result-char {
  font-size: 3.8rem;
  line-height: 1;
  font-family: 'Noto Serif Tibetan', serif;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  min-width: 64px;
  text-align: center;
  overflow: visible;
  padding-bottom: 0.35em;
}

.result-meta { display: flex; flex-direction: column; gap: .3rem; }

.result-label {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}

.result-mode {
  font-size: .72rem;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: .1rem .5rem;
  width: fit-content;
}

.confidence-bar-wrap { display: flex; flex-direction: column; gap: .4rem; }
.confidence-label {
  display: flex;
  justify-content: space-between;
  font-size: .78rem;
  color: var(--text-dim);
}
.confidence-track {
  height: 7px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.confidence-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 99px;
  transition: width .6s cubic-bezier(.4,0,.2,1);
  width: 0%;
}

.top5-title {
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: .45rem;
}

.top5-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.top5-item {
  display: grid;
  grid-template-columns: 1.3rem 2.1rem 1fr 2.8rem;
  align-items: center;
  gap: .5rem;
  padding: .35rem .55rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: var(--t);
}
.top5-item:first-child {
  border-color: hsla(160, 56%, 36%, .35);
  background: var(--primary-bg);
}

.top5-rank { font-size: .68rem; color: var(--text-muted); text-align: center; }
.top5-char {
  font-size: 1.2rem;
  line-height: 1.5;
  font-family: 'Noto Serif Tibetan', serif;
  text-align: center;
  color: var(--text);
  overflow: visible;
}
.top5-bar-track {
  height: 5px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.top5-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 99px;
  transition: width .5s ease;
}
.top5-pct { font-size: .68rem; color: var(--text-dim); text-align: right; }

/* ── Scrollbar (light) ────────────────────────────────────── */
.result-card::-webkit-scrollbar { width: 5px; }
.result-card::-webkit-scrollbar-track { background: transparent; }
.result-card::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: 99px;
}

/* ── Utility ──────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 760px) {
  html, body { height: auto; overflow: auto; }
  .main { overflow: visible; padding: .75rem; }
  .card-grid { grid-template-columns: 1fr; height: auto; }
  .canvas-wrap { aspect-ratio: 1 / 1; flex: none; }
  .right-col { min-height: unset; }
  .result-card { min-height: 300px; }
}
