:root {
  color-scheme: light;
  --bg: #f6f7f2;
  --panel: #ffffff;
  --ink: #202830;
  --muted: #66727e;
  --line: #d7dbd2;
  --accent: #126e82;
  --accent-strong: #0f5d6f;
  --accent-soft: #e2f2f4;
  --danger-soft: #f7e8e5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", sans-serif;
}

button {
  font: inherit;
}

textarea {
  font: inherit;
}

.app {
  width: min(1120px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
}

.toolbar {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 8px;
}

.brand {
  margin-right: auto;
  padding: 0 8px;
  font-weight: 750;
  color: #25313a;
}

.mode-toggle {
  display: grid;
  grid-template-columns: repeat(2, 38px);
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f5f7f4;
}

.mode-button,
.icon-button,
.text-button,
.key-button {
  border: 1px solid transparent;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}

.mode-button {
  height: 32px;
  font-weight: 760;
}

.mode-button.is-active {
  background: var(--accent);
  color: #fff;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-color: var(--line);
  font-size: 18px;
}

.icon-button.small {
  width: 34px;
  height: 30px;
  font-size: 16px;
}

.icon-button.is-active,
.icon-button[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: #9ec6ce;
}

.text-button {
  height: 38px;
  padding: 0 13px;
  border-color: var(--line);
  font-weight: 650;
}

.text-button:hover,
.icon-button:hover,
.key-button:hover {
  border-color: #aac2c7;
  background: #f6fbfc;
}

.status {
  min-width: 74px;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.editor-wrap {
  position: relative;
  min-height: 0;
}

.editor {
  position: relative;
  width: 100%;
  min-height: calc(100vh - 98px);
  height: calc(100vh - 98px);
  display: block;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 22px;
  font-size: 22px;
  line-height: 1.65;
  outline: none;
  resize: none;
  caret-color: var(--accent-strong);
  white-space: pre-wrap;
  word-break: break-word;
}

.editor::placeholder {
  color: var(--muted);
  opacity: 1;
}

.editor:focus {
  border-color: #8fb8bf;
  box-shadow: 0 0 0 3px rgba(18, 110, 130, .12);
}

.keyboard-popover {
  position: absolute;
  top: 14px;
  right: 14px;
  width: min(760px, calc(100% - 28px));
  min-width: min(420px, calc(100% - 28px));
  min-height: 260px;
  border: 1px solid #9bbbc1;
  border-radius: 8px;
  background: #fbfefd;
  box-shadow: 0 18px 42px rgba(23, 43, 51, .18);
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.keyboard-head {
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  color: #43515a;
  font-size: 13px;
  font-weight: 700;
  cursor: move;
  touch-action: none;
  user-select: none;
}

.keyboard-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.keyboard-actions .icon-button {
  cursor: pointer;
}

.keyboard-popover.is-dragging {
  cursor: move;
  box-shadow: 0 24px 52px rgba(23, 43, 51, .22);
}

.keyboard-popover.is-resizing {
  box-shadow: 0 24px 52px rgba(23, 43, 51, .22);
}

.resize-handle {
  position: absolute;
  display: block;
  z-index: 2;
  touch-action: none;
}

.resize-handle.right {
  top: 12px;
  right: -5px;
  width: 10px;
  height: calc(100% - 24px);
  cursor: ew-resize;
}

.resize-handle.bottom {
  left: 12px;
  bottom: -5px;
  width: calc(100% - 24px);
  height: 10px;
  cursor: ns-resize;
}

.resize-handle.corner {
  right: -5px;
  bottom: -5px;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
}

.resize-handle.corner::after {
  content: "";
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 8px;
  height: 8px;
  border-right: 2px solid #8aaeb5;
  border-bottom: 2px solid #8aaeb5;
}

.keyboard-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.key-row {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  gap: 6px;
}

.key-button,
.key-spacer {
  flex: var(--key-units, 42) 1 0;
}

.key-button {
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0 6px;
  border-color: #c7d2d4;
  display: grid;
  place-items: center;
  background: #fff;
}

.key-button.text {
  background: #fbfbf7;
}

.key-button.action,
.key-spacer {
  background: #eef4f5;
}

.key-spacer {
  height: 100%;
  border-radius: 6px;
}

.key-button.backspace {
  --key-units: 58;
}

.key-button.lang {
  --key-units: 58;
}

.key-button.shift {
  --key-units: 68;
}

.key-button.clear,
.key-button.enter {
  --key-units: 84;
}

.key-button.space {
  --key-units: 310;
}

.key-spacer.tab {
  --key-units: 42;
}

.key-main {
  line-height: 1;
  font-size: 17px;
  font-weight: 760;
}

.key-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
}

@media (max-width: 720px) {
  .app {
    width: 100%;
    padding: 0;
    gap: 0;
  }

  .toolbar,
  .editor {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .brand {
    display: none;
  }

  .status {
    display: none;
  }

  .editor {
    min-height: calc(100vh - 54px);
    height: calc(100vh - 54px);
    padding: 16px;
    font-size: 20px;
  }

  .keyboard-popover {
    position: fixed;
    left: 8px;
    right: 8px;
    top: auto;
    bottom: 8px;
    width: auto;
  }

  .resize-handle.right,
  .resize-handle.bottom {
    display: none;
  }

  .resize-handle.corner {
    right: 2px;
    bottom: 2px;
  }

  .keyboard-grid,
  .key-row {
    gap: 3px;
  }

  .key-button {
    height: 100%;
    min-width: 0;
    padding: 0 3px;
  }

  .key-spacer {
    display: none;
  }

  .key-button.backspace,
  .key-button.lang,
  .key-button.shift,
  .key-button.clear,
  .key-button.enter {
    --key-units: 58;
  }

  .key-button.space {
    --key-units: 180;
  }

  .key-sub {
    display: none;
  }
}
