:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --line: #e6edf5;
  --ink: #1a2332;
  --muted: #6b7c90;
  --accent: #5b9dff;
  --accent-soft: #e8f1ff;
  --accent-deep: #3b82f6;
  --key: #ffffff;
  --key-special: #dce5f0;
  --panel: #eef3f9;
  --ug: "alkatip tor", "alkatip basma tom", "alkatip basma", "Noto Naskh Arabic", "Microsoft Uighur", serif;
  --ui: "Outfit", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ug);
}
body[data-lang="zh"],
body[data-lang="en"] {
  font-family: var(--ui);
}

.stage {
  width: min(560px, calc(100% - 24px));
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 20px 0 16px;
  gap: 12px;
  animation: rise 0.45s ease both;
}

.editor {
  width: 100%;
  border: 1.5px solid #cfe0ff;
  border-radius: 16px;
  padding: 14px 16px;
  font-size: 17px;
  line-height: 1.7;
  resize: vertical;
  min-height: 120px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
  font-family: inherit;
  box-shadow: 0 10px 28px rgba(91, 157, 255, 0.08);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}
.editor:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(91, 157, 255, 0.15);
}
.editor::placeholder { color: #9aabbd; }

.ime {
  background: var(--panel);
  border-radius: 18px;
  overflow: hidden;
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: 0 16px 40px rgba(26, 35, 50, 0.08);
  animation: slide-up 0.45s 0.05s ease both;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 8px 4px;
  background: #e4ebf4;
}
.tool, .lang {
  border: 0;
  background: transparent;
  min-width: 36px;
  height: 34px;
  border-radius: 10px;
  font-size: 15px;
  color: #45566a;
  cursor: pointer;
  font-family: inherit;
}
.lang.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 10px rgba(91, 157, 255, 0.35);
}
.brand-chip {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
  font-family: var(--ui);
  color: var(--accent-deep);
  background: #fff;
  border: 1px solid #c9d7e8;
  margin-inline: 4px;
}
.spacer { flex: 1; }

.candidates {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  min-height: 40px;
  overflow-x: auto;
  background: #f7fafc;
  scrollbar-width: none;
}
.candidates::-webkit-scrollbar { display: none; }
.cand {
  flex: 0 0 auto;
  padding: 5px 12px;
  border: 0;
  border-radius: 10px;
  font-size: 15px;
  cursor: pointer;
  color: var(--ink);
  white-space: nowrap;
  background: transparent;
  font-family: inherit;
}
.cand:first-child {
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 700;
}
.cand[dir="rtl"] { font-family: var(--ug); }

.composing {
  padding: 2px 14px 6px;
  font-size: 13px;
  color: var(--accent-deep);
  font-weight: 600;
  font-family: var(--ui);
}

.keys {
  padding: 4px 4px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.row {
  display: flex;
  gap: 4px;
  padding: 0 4px;
}
.row.inset { padding-inline: 18px; }
.key {
  flex: 1;
  min-height: 46px;
  border: 0;
  border-radius: 10px;
  background: var(--key);
  color: var(--ink);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 0 #b7c4d4;
  position: relative;
  touch-action: manipulation;
  font-family: inherit;
  transition: transform 0.08s ease, background 0.08s ease;
}
.key:active { transform: scale(0.97); background: #eef3f8; }
.key.special { background: var(--key-special); font-size: 14px; font-family: var(--ui); }
.key.enter {
  background: var(--accent);
  color: #fff;
  flex: 1.4;
  box-shadow: 0 4px 12px rgba(91, 157, 255, 0.35);
}
.key .sub {
  position: absolute;
  top: 3px;
  inset-inline-start: 5px;
  font-size: 9px;
  color: #90a4ae;
  font-weight: 500;
  font-family: var(--ui);
}
.key.space { flex: 3.6; font-size: 12px; color: var(--muted); }

.foot {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #8a9bb0;
  font-family: var(--ui);
  padding: 0 2px;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes slide-up {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 420px) {
  .key { min-height: 42px; font-size: 16px; }
}
