:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #8a9099;
  --accent: #2f6bff;
  --line: #e4e7ec;
  --key: #ffffff;
  --func: #d9dce2;
  --kb-h: 268px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
}

button,
textarea {
  font-family: inherit;
}

button {
  cursor: pointer;
}

.app {
  height: 100vh;
  height: 100dvh;
  max-width: 620px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--kb-h) + 8px);
  transition: padding-bottom 0.2s ease;
}

body.kb-hidden .app {
  padding-bottom: 12px;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  flex: 0 0 auto;
}

.brand-text {
  min-width: 0;
}

.title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.25;
}

.badge {
  font-size: 10px;
  font-weight: 500;
  color: var(--accent);
  background: #e8efff;
  border-radius: 6px;
  padding: 2px 6px;
}

.subtitle {
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font-size: 16px;
}

.editor-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  padding: 6px 12px 10px;
}

.editor-card {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 6px 24px rgba(17, 24, 39, 0.06);
  overflow: hidden;
}

.editor-tools {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.tool-btn {
  border: 0;
  background: #eef1f6;
  color: #3c4043;
  font-size: 13px;
  padding: 7px 13px;
  border-radius: 8px;
}

.tool-btn:active {
  background: #e1e5ed;
}

.count {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
}

#editor {
  flex: 1 1 auto;
  width: 100%;
  min-height: 80px;
  border: 0;
  outline: 0;
  resize: none;
  padding: 14px;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  line-height: 1.65;
}

#editor::placeholder {
  color: #a6abb3;
}

.editor-hint {
  flex: 0 0 auto;
  padding: 8px 14px 12px;
  font-size: 11px;
  color: var(--muted);
}

.apk-link {
  flex: 0 0 auto;
  margin: 0 14px 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #eef3ff;
  color: #2f6bff;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}

.apk-link:active {
  background: #dfe8ff;
}

.keyboard {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: #e9ebef;
  box-shadow: 0 -8px 24px rgba(17, 24, 39, 0.1);
  transition: transform 0.2s ease;
}

body.kb-hidden .keyboard {
  transform: translateY(calc(100% + 24px));
}

.cand-bar {
  height: 44px;
  display: flex;
  align-items: center;
  padding-left: 6px;
  background: #f7f8fa;
  border-bottom: 1px solid var(--line);
}

.cand-scroll {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.cand-scroll::-webkit-scrollbar {
  display: none;
}

.cand-idle {
  flex: 0 0 auto;
  padding: 0 6px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.cand-idle.active {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
}

.cand-list {
  display: flex;
  align-items: stretch;
  height: 100%;
}

.cand-item {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 17px;
  min-width: 42px;
  height: 100%;
  padding: 0 10px;
  border-radius: 8px;
}

.cand-item:active {
  background: #e7ebf3;
}

.bar-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  border-radius: 6px;
}

.bar-btn:active {
  background: #e5e8ee;
}

.pages {
  position: relative;
  height: 224px;
}

.page {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: 3px 4px 4px;
}

.page.active {
  display: flex;
}

.krow {
  flex: 1 1 0;
  display: flex;
  gap: 5px;
  padding: 2px 0;
  min-height: 0;
}

.krow.nav {
  flex: 0 0 44px;
  padding-top: 6px;
}

.key {
  flex: 1 1 1;
  min-width: 0;
  border: 0;
  border-radius: 8px;
  background: var(--key);
  color: var(--text);
  font-size: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 0 rgba(17, 24, 39, 0.12);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.key.func {
  background: var(--func);
  font-size: 15px;
}

.key.space {
  font-size: 12px;
  color: var(--muted);
}

.key.active {
  background: #dce6ff;
  color: var(--accent);
}

.key:active {
  filter: brightness(0.94);
  transform: translateY(1px);
}

.spacer {
  flex: 0.5 0 0;
}

.emoji-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 2px;
}

.emoji-key {
  height: 38px;
  border: 0;
  background: transparent;
  font-size: 22px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.emoji-key:active {
  background: rgba(17, 24, 39, 0.08);
}

.clip-head {
  flex: 0 0 32px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 8px;
}

.clip-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clip-action {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
}

.clip-action:active {
  background: #e8efff;
}

.clip-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 7px;
}

.clip-empty {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 0 20px;
}

.clip-item {
  display: flex;
  align-items: stretch;
  gap: 4px;
  margin: 3px 0;
}

.clip-text {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  text-align: left;
  padding: 10px 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clip-text:active {
  background: #e9edf5;
}

.clip-del {
  flex: 0 0 36px;
  border: 0;
  border-radius: 10px;
  background: #f0f2f6;
  color: var(--muted);
  font-size: 16px;
}

.clip-del:active {
  background: #e1e5ed;
}

.show-kb {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 21;
  display: none;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  font-size: 14px;
  padding: 10px 20px;
  box-shadow: 0 8px 24px rgba(47, 107, 255, 0.35);
}

body.kb-hidden .show-kb {
  display: block;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--kb-h) + 16px);
  transform: translate(-50%, 8px);
  z-index: 40;
  max-width: 78vw;
  background: rgba(28, 28, 30, 0.92);
  color: #ffffff;
  font-size: 13px;
  line-height: 1.4;
  padding: 9px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

body.kb-hidden .toast {
  bottom: 72px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: flex-end;
  justify-content: center;
  background: rgba(17, 24, 39, 0.35);
}

.modal.open {
  display: flex;
}

.sheet {
  width: 100%;
  max-width: 620px;
  max-height: 82vh;
  overflow-y: auto;
  background: #ffffff;
  border-radius: 20px 20px 0 0;
  padding: 22px 22px calc(22px + env(safe-area-inset-bottom, 0px));
}

.sheet h3 {
  margin: 0 0 12px;
  font-size: 18px;
}

.sheet ul {
  margin: 0;
  padding-left: 18px;
  color: #3c4043;
  font-size: 14px;
  line-height: 1.8;
}

.sheet .primary {
  width: 100%;
  height: 46px;
  margin-top: 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #ffffff;
  font-size: 15px;
}

@media (max-height: 700px) {
  .pages {
    height: 198px;
  }

  .key {
    font-size: 17px;
  }

  .key.func {
    font-size: 14px;
  }
}

@media (max-width: 350px) {
  .key {
    font-size: 16px;
  }

  .krow {
    gap: 4px;
  }
}

@media (min-width: 480px) {
  .emoji-grid {
    grid-template-columns: repeat(10, 1fr);
  }
}
