:root {
  color-scheme: dark;
  --bg: #120c18;
  --surface: #1c1526;
  --display: #16101f;
  --btn: #2a2138;
  --btn-op: #322844;
  --btn-active: #43355a;
  --accent: #8b5cf6;
  --accent-deep: #7c3aed;
  --text: #f3eefe;
  --muted: #a394b8;
  --line: #3b2f4f;
  --ad: #23182f;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0
    env(safe-area-inset-left);
}

.install-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  background: #241833;
  border-bottom: 1px solid var(--line);
}

.install-bar[hidden] {
  display: none;
}

.install-bar p {
  margin: 0;
  flex: 1;
  font-size: 13px;
}

.install-bar button {
  border: 0;
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  color: var(--text);
  background: var(--accent-deep);
}

.install-bar .ghost {
  background: transparent;
  color: var(--muted);
}

.ad-slot {
  flex: 0 0 auto;
  padding: 8px 10px 0;
}

.ad-slot[hidden] {
  display: none;
}

.ad-card {
  background: var(--ad);
  border: 1px solid #5b21b6;
  border-radius: 10px;
  padding: 8px 10px 9px;
}

.ad-kicker {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 2px;
}

.ad-title {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
}

.ad-body {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.ad-links {
  margin-top: 6px;
  font-size: 12px;
}

.ad-link {
  color: #ddd6fe;
}

.ad-sep {
  color: var(--muted);
}

#display {
  flex: 1 1 auto;
  min-height: 140px;
  margin: 8px 10px;
  padding: 12px;
  resize: none;
  border: 0;
  border-radius: 12px;
  background: var(--display);
  color: var(--text);
  caret-color: #c4b5fd;
  font-family: "Roboto Mono", "Noto Sans Mono", ui-monospace, monospace;
  font-size: 18px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-all;
  overflow-y: auto;
  user-select: text;
  -webkit-user-select: text;
}

#display:focus {
  outline: 1px solid #6d28d980;
}

.pad {
  display: flex;
  flex: 0 0 auto;
  height: min(54dvh, 430px);
  gap: 6px;
  padding: 0 8px calc(8px + env(safe-area-inset-bottom));
}

.pad-main {
  flex: 1;
  display: grid;
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: 6px;
  min-width: 0;
}

.pad-ops {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 18.5%;
  min-width: 56px;
}

.row-4,
.row-3 {
  display: grid;
  gap: 6px;
  min-height: 0;
}

.row-4 {
  grid-template-columns: repeat(4, 1fr);
}

.row-3 {
  grid-row: span 4;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(4, minmax(0, 1fr));
}

.pad button {
  appearance: none;
  border: 0;
  border-radius: 12px;
  background: var(--btn);
  color: var(--text);
  font: inherit;
  font-size: 22px;
  min-width: 0;
  width: 100%;
  height: 100%;
  padding: 0;
}

.pad-ops button {
  flex: 1;
  background: var(--btn-op);
  font-size: 24px;
}

.pad button:active {
  background: var(--btn-active);
}

.pad .key-ac {
  background: var(--accent-deep);
  font-weight: 700;
}

.pad .key-ac:active {
  background: var(--accent);
}

.pad .key-subbed {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  line-height: 1;
}

.pad .key-main {
  font-size: 20px;
}

.pad .key-sub {
  font-size: 10px;
  color: var(--muted);
}

.pad .key-ans,
.pad .key-bs {
  font-size: 18px;
}
