:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #131a22;
  --panel-2: #1b2530;
  --text: #eef3f8;
  --text-dim: #8ea0b3;
  --accent: #ff9f0a;
  --accent-text: #1a1200;
  --op: #2a3542;
  --danger: #ff453a;
  --ok: #30d158;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom) 12px;
  gap: 10px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 0;
}

.header h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  padding: 6px 10px;
  border-radius: 10px;
}

.icon-btn:active { background: var(--panel-2); }

.display-area {
  background: var(--panel);
  border-radius: 18px;
  padding: 16px 18px;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
}

.recognized-text {
  font-size: 13px;
  color: var(--text-dim);
  min-height: 16px;
  word-break: break-word;
}

.expression {
  font-size: 20px;
  color: var(--text-dim);
  min-height: 24px;
  word-break: break-all;
  text-align: right;
}

.result {
  font-size: 44px;
  font-weight: 300;
  text-align: right;
  word-break: break-all;
  line-height: 1.1;
}

.result.error {
  color: var(--danger);
  font-size: 28px;
}

.dictation-area {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dictation-input {
  width: 100%;
  font-size: 17px;
  padding: 14px 14px;
  border-radius: 14px;
  border: 1px solid #2a3542;
  background: var(--panel-2);
  color: var(--text);
}

.dictation-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.hint {
  font-size: 12px;
  color: var(--text-dim);
  padding: 0 4px;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  flex: 1;
  align-content: center;
}

.key {
  border: none;
  border-radius: 16px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 22px;
  padding: 0;
  aspect-ratio: 1.3 / 1;
  min-height: 52px;
}

.key:active { filter: brightness(1.3); }

.key-op {
  background: var(--op);
  color: var(--accent);
}

.key-del {
  background: var(--op);
  color: var(--danger);
}

.key-wide {
  grid-column: span 4;
  aspect-ratio: auto;
  min-height: 48px;
  font-size: 16px;
}

.key-eq {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.history-area {
  max-height: 22vh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 14px;
  padding: 8px 14px;
}

.history-title {
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 0;
  position: sticky;
  top: 0;
  background: var(--panel);
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  padding: 6px 0;
  border-bottom: 1px solid #1e2a35;
}

.history-expr {
  color: var(--text-dim);
  word-break: break-all;
}

.history-result {
  color: var(--text);
  white-space: nowrap;
}
