html { color-scheme: only light !important; }
html[data-theme="dark"] { color-scheme: only dark !important; }

:root {
  --page-bg: #fff;
  --page-text: #111;
  --placeholder: #9fa0a5;
  --panel: #d1d3d8;
  --key: #f9f9fa;
  --key-text: #050505;
  --fn-key: #adb3bd;
  --send: #0a84ff;
  --send-text: #fff;
  --key-pressed: #c7c9ce;
  --fn-pressed: #9299a4;
  --send-pressed: #0070df;
  --edge: rgba(0,0,0,.18);
  --alt-bg: #f7f7f8;
  --alt-text: #080808;
  --toggle-bg: rgba(245,245,248,.9);
  --toggle-fg: #222;
  --move: rgba(30,31,35,.55);
  --emoji-ui: #73757c;
  font-family: "SF Pro Text", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

html[data-theme="dark"] {
  --page-bg: #111217;
  --page-text: #f4f4f5;
  --placeholder: #777b83;
  --panel: #1c1f24;
  --key: #6b6d72;
  --key-text: #fff;
  --fn-key: #45484e;
  --key-pressed: #85878c;
  --fn-pressed: #60636a;
  --send-pressed: #2d96ff;
  --edge: rgba(255,255,255,.07);
  --alt-bg: #f2f2f3;
  --alt-text: #050505;
  --toggle-bg: rgba(45,47,53,.92);
  --toggle-fg: #fff;
  --move: rgba(255,255,255,.52);
  --emoji-ui: #a1a3a8;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; forced-color-adjust: none; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: var(--page-bg) !important; }
body { touch-action: manipulation; font-family: inherit; }
html.first-visit-intro-pending, html.first-visit-intro-pending body { background: #000 !important; }
html[data-theme="light"] body,
html[data-theme="light"] .keyboard-shell,
html[data-theme="light"] .simple-keyboard,
html[data-theme="light"] .emoji-panel,
html[data-theme="light"] .editor { color-scheme: only light !important; }
html[data-theme="dark"] body,
html[data-theme="dark"] .keyboard-shell,
html[data-theme="dark"] .simple-keyboard,
html[data-theme="dark"] .emoji-panel,
html[data-theme="dark"] .editor { color-scheme: only dark !important; }

.editor {
  position: fixed; inset: 0; resize: none; border: 0; outline: 0; background: var(--page-bg) !important; color: var(--page-text) !important;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 24px max(24px, env(safe-area-inset-left));
  font: 400 22px/1.42 "SF Pro Text", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  caret-color: #0a84ff;
}
.editor::placeholder { color: var(--placeholder) !important; }

.theme-toggle {
  position: fixed; z-index: 40; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); width: 42px;
  height: 42px; border: 0; border-radius: 999px; background: var(--toggle-bg) !important; color: var(--toggle-fg) !important;
  box-shadow: inset 0 0 0 1px var(--edge); display: grid; place-items: center; backdrop-filter: blur(18px); cursor: pointer;
}
.theme-toggle svg { width: 20px; height: 20px; fill: currentColor; }

.keyboard-shell {
  --keyboard-center: 50%;
  position: fixed; z-index: 20; left: var(--keyboard-center); top: 0; bottom: 0; width: clamp(300px, 30vw, 520px); height: 100svh; transform: translateX(-50%);
  background: var(--panel) !important; padding: max(7px, env(safe-area-inset-top)) 5px max(8px, env(safe-area-inset-bottom)); border-radius: 12px 12px 0 0;
  box-shadow: 0 -1px 0 rgba(255,255,255,.35) inset; touch-action: none; overflow: hidden; display: flex; flex-direction: column;
}
.keyboard-pane { width: 100%; flex: 1 1 auto; min-height: 0; display: flex; }
.emoji-panel { width: 100%; flex: 1 1 auto; min-height: 0; overflow: hidden; display: flex; flex-direction: column; padding: 4px 3px 0; color: var(--emoji-ui) !important; }

.simple-keyboard.hg-theme-default {
  background: transparent !important; padding: 0 !important; border-radius: 0 !important; font-family: inherit; user-select: none; touch-action: none;
  flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column;
}
.simple-keyboard .hg-rows { display: flex; flex: 1 1 auto; min-height: 0; flex-direction: column; gap: clamp(9px, 1.25svh, 16px); }
.simple-keyboard .hg-row { display: flex; flex: 1 1 0; min-height: 0; gap: 6px; margin: 0 !important; }
.simple-keyboard .hg-row:nth-child(2) { padding-inline: 5.5%; }
.simple-keyboard .hg-row:nth-child(3) { padding-inline: 0; }
.simple-keyboard .hg-row:nth-child(4) { gap: 7px; }

.simple-keyboard .hg-button {
  position: relative; height: 100%; min-height: 0; min-width: 0; padding: 0; border: 0 !important; border-radius: 8px !important; background: var(--key) !important;
  color: var(--key-text) !important; box-shadow: inset 0 1px 0 rgba(255,255,255,.6), inset 0 -1px 0 rgba(0,0,0,.06), inset 0 0 0 .65px var(--edge), 0 1.5px 1px rgba(0,0,0,.18) !important;
  font: 400 clamp(25px, 3.5svh, 38px)/1 "SF Pro Text", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif !important;
  overflow: hidden; transition: transform 45ms ease-out, background-color 45ms ease-out, box-shadow 45ms ease-out; -webkit-font-smoothing: antialiased; text-rendering: geometricPrecision;
}
.simple-keyboard .hg-button > span { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
.simple-keyboard .hg-button.hg-functionBtn { background: var(--fn-key) !important; font-size: clamp(15px, 2.1svh, 22px) !important; font-weight: 500 !important; }
.simple-keyboard .hg-button.key-send { background: var(--send) !important; color: var(--send-text) !important; }
.simple-keyboard .hg-button.is-pressed { transform: translateY(2px) scale(.97); background: var(--key-pressed) !important; box-shadow: inset 0 0 0 .65px var(--edge) !important; }
.simple-keyboard .hg-button.hg-functionBtn.is-pressed { background: var(--fn-pressed) !important; }
.simple-keyboard .hg-button.key-send.is-pressed { background: var(--send-pressed) !important; }

.simple-keyboard .hg-button-shift, .simple-keyboard .hg-button-bksp, .simple-keyboard .hg-button-emoji,
.simple-keyboard .hg-button-numbers, .simple-keyboard .hg-button-letters, .simple-keyboard .hg-button-symbols,
.simple-keyboard .hg-button-space, .simple-keyboard .hg-button-send, .simple-keyboard .hg-button-period { flex-shrink: 0 !important; }
.simple-keyboard .hg-button-shift, .simple-keyboard .hg-button-bksp { flex: 0 0 13.5% !important; max-width: 13.5% !important; }
.simple-keyboard .hg-button-numbers, .simple-keyboard .hg-button-letters, .simple-keyboard .hg-button-symbols { flex: 0 0 18% !important; max-width: 18% !important; }
.simple-keyboard .hg-button-emoji, .simple-keyboard .hg-button-period { flex: 0 0 8.8% !important; max-width: 8.8% !important; }
.simple-keyboard .hg-button-space { flex: 1 1 auto !important; min-width: 0 !important; font-size: clamp(14px, 2svh, 20px) !important; }
.simple-keyboard .hg-button-send { flex: 0 0 20% !important; max-width: 20% !important; font-size: clamp(15px, 2.1svh, 22px) !important; }

.icon { width: clamp(27px, 3.6svh, 38px); height: clamp(27px, 3.6svh, 38px); stroke: currentColor; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.icon-fill { fill: currentColor; stroke: none; }

.alternates {
  position: fixed; z-index: 100; display: flex; gap: 1px; padding: 5px; border-radius: 12px; background: var(--alt-bg) !important; color: var(--alt-text) !important;
  box-shadow: inset 0 0 0 .7px rgba(0,0,0,.15), 0 3px 12px rgba(0,0,0,.27); pointer-events: none;
}
.alternate-key { min-width: 44px; height: 56px; padding-inline: 7px; border-radius: 8px; display: grid; place-items: center; font: 400 27px/1 "SF Pro Text", "SF Pro Display", -apple-system, BlinkMacSystemFont, sans-serif; color: var(--alt-text) !important; }
.alternate-key.is-selected { background: #8e8e93 !important; color: #fff !important; }

.emoji-toolbar { flex: 0 0 38px; display: grid; grid-template-columns: 38px 1fr 38px; align-items: center; gap: 4px; padding: 0 1px 4px; }
.emoji-header { text-align: center; font: 700 12px/1 "SF Pro Text", -apple-system, BlinkMacSystemFont, sans-serif; letter-spacing: .025em; color: var(--emoji-ui) !important; }
.emoji-back { width: 36px; height: 34px; padding: 0; border: 0; border-radius: 9px; background: transparent !important; color: var(--emoji-ui) !important; display: grid; place-items: center; }
.emoji-back:active { background: rgba(127,127,127,.16) !important; }
.emoji-back svg { width: 27px; height: 21px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.emoji-scroll-cue { text-align: center; font-size: 16px; color: var(--emoji-ui) !important; opacity: .8; }
.emoji-scroller { flex: 1 1 auto; min-height: 0; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; touch-action: pan-x; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.emoji-scroller::-webkit-scrollbar { display: none; }
.emoji-grid {
  height: 100%; min-width: 100%; width: max-content; display: grid; grid-auto-flow: column; grid-template-rows: repeat(12, minmax(0, 1fr));
  grid-auto-columns: 48px; gap: 3px 4px; padding: 2px 2px 5px; align-items: center;
}
.emoji-cell { border: 0; border-radius: 8px; background: transparent !important; font-size: clamp(28px, 3.25svh, 39px); line-height: 1; padding: 0; min-width: 0; min-height: 0; display: grid; place-items: center; cursor: pointer; }
.emoji-cell.is-pressed { background: rgba(127,127,127,.18) !important; transform: scale(.9); }

.move-bar { flex: 0 0 22px; height: 22px; margin-top: 7px; display: grid; place-items: center; cursor: ew-resize; touch-action: none; outline: none; }
.move-bar-grip { display: block; width: 54px; height: 5px; border-radius: 999px; background: var(--move) !important; transition: width 80ms ease, opacity 80ms ease, background-color .35s ease, box-shadow .35s ease; }
.move-bar.is-dragging .move-bar-grip { width: 72px; opacity: .9; }
.move-bar.is-tutorial .move-bar-grip { width: 76px; background: #fff !important; box-shadow: 0 0 0 5px rgba(255,255,255,.12), 0 0 26px rgba(255,255,255,.7); animation: moveTutorialPulse 1.35s ease-in-out infinite; }

.first-visit-intro { position: fixed; z-index: 5000; inset: 0; display: none; align-items: center; justify-content: center; padding: 28px; background: #000; color: #fff; backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); transition: background-color 2s ease, backdrop-filter 2s ease, -webkit-backdrop-filter 2s ease; }
html.first-visit-intro-pending .first-visit-intro { display: flex; }
.first-visit-intro-text { width: min(760px, 88vw); text-align: center; opacity: 0; font: 500 clamp(24px, 5vw, 52px)/1.18 "SF Pro Display", "SF Pro Text", -apple-system, BlinkMacSystemFont, sans-serif; letter-spacing: -.025em; transition: opacity 2s ease; }
.first-visit-intro.is-text-visible .first-visit-intro-text { opacity: 1; }
.first-visit-intro.is-revealing { background: rgba(0,0,0,0); backdrop-filter: blur(0); -webkit-backdrop-filter: blur(0); }

.move-tutorial { --hole-left: 0px; --hole-top: 0px; --hole-width: 0px; --hole-height: 0px; --label-left: 50vw; --label-top: 50vh; position: fixed; z-index: 3400; inset: 0; pointer-events: none; }
.move-tutorial-shade { position: fixed; z-index: 3400; background: rgba(0,0,0,.62); opacity: 0; backdrop-filter: blur(0); -webkit-backdrop-filter: blur(0); transition: opacity .7s ease, backdrop-filter .7s ease, -webkit-backdrop-filter .7s ease; }
.move-tutorial-top { top: 0; left: 0; right: 0; height: var(--hole-top); }
.move-tutorial-bottom { top: calc(var(--hole-top) + var(--hole-height)); left: 0; right: 0; bottom: 0; }
.move-tutorial-left { top: var(--hole-top); left: 0; width: var(--hole-left); height: var(--hole-height); }
.move-tutorial-right { top: var(--hole-top); left: calc(var(--hole-left) + var(--hole-width)); right: 0; height: var(--hole-height); }
.move-tutorial-label { position: fixed; z-index: 3410; left: var(--label-left); top: var(--label-top); transform: translate(-50%, calc(-100% - 12px)) scale(.96); opacity: 0; padding: 9px 13px; border-radius: 999px; background: rgba(0,0,0,.76); color: #fff; box-shadow: 0 6px 24px rgba(0,0,0,.28); font: 700 14px/1 "SF Pro Text", -apple-system, BlinkMacSystemFont, sans-serif; white-space: nowrap; transition: opacity .55s ease .12s, transform .55s cubic-bezier(.2,.8,.2,1) .12s; }
.move-tutorial-label::after { content: ''; position: absolute; left: 50%; top: 100%; transform: translateX(-50%); border: 7px solid transparent; border-top-color: rgba(0,0,0,.76); }
.move-tutorial.is-visible .move-tutorial-shade { opacity: 1; backdrop-filter: blur(9px); -webkit-backdrop-filter: blur(9px); }
.move-tutorial.is-visible .move-tutorial-label { opacity: 1; transform: translate(-50%, calc(-100% - 12px)) scale(1); }
.move-tutorial.is-leaving .move-tutorial-shade { opacity: 0; backdrop-filter: blur(0); -webkit-backdrop-filter: blur(0); transition-duration: .65s; }
.move-tutorial.is-leaving .move-tutorial-label { opacity: 0; transform: translate(-50%, calc(-100% - 4px)) scale(.96); transition-delay: 0s; transition-duration: .4s; }
@keyframes moveTutorialPulse { 0%,100% { transform: scaleX(1); opacity: .9; } 50% { transform: scaleX(1.12); opacity: 1; } }

[hidden] { display: none !important; }

@media (max-width: 720px) {
  .editor { padding-bottom: 24px; font-size: 20px; }
  .keyboard-shell { width: clamp(220px, 56vw, 320px); }
  .simple-keyboard .hg-rows { gap: clamp(7px, 1.05svh, 11px); }
  .simple-keyboard .hg-row { gap: 4px; }
  .simple-keyboard .hg-row:nth-child(4) { gap: 5px; }
  .simple-keyboard .hg-button { height: 100%; min-height: 0; border-radius: 7px !important; font-size: clamp(21px, 3.1svh, 32px) !important; }
  .simple-keyboard .hg-button.hg-functionBtn { font-size: clamp(12px, 1.8svh, 17px) !important; }
  .simple-keyboard .hg-button-space, .simple-keyboard .hg-button-send { font-size: clamp(12px, 1.8svh, 17px) !important; }
  .simple-keyboard .hg-button-emoji, .simple-keyboard .hg-button-period { flex-basis: 8.8% !important; max-width: 8.8% !important; }
  .icon { width: clamp(23px, 3.2svh, 32px); height: clamp(23px, 3.2svh, 32px); }
  .alternate-key { min-width: 38px; height: 50px; font-size: 23px; }
  .emoji-grid { grid-template-rows: repeat(12, minmax(0, 1fr)); grid-auto-columns: 44px; gap: 2px 3px; }
  .first-visit-intro-text { width: min(520px, 86vw); font-size: clamp(23px, 7vw, 38px); }
  .move-tutorial-label { font-size: 13px; padding: 8px 12px; }
}

@media (max-height: 720px) {
  .emoji-grid { grid-template-rows: repeat(8, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) { .simple-keyboard .hg-button, .move-bar-grip { transition: none; } }
