:root {
  --background: #111315;
  --surface: #2b2e32;
  --command: #393e44;
  --x-button: #2d4257;
  --primary: #a8c7fa;
  --on-primary: #06116f;
  --text: #f1f3f4;
  --muted: #a9adb2;
  --history-card: #1e2124;
  --radius: 28px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--background);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 0;
  font-family: inherit;
  cursor: pointer;
  user-select: none;
}

button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary), white 15%);
  outline-offset: 3px;
}

.app-shell {
  width: min(100vw, 520px);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--background);
  overflow: hidden;
}

.screen {
  display: none;
  min-height: 100dvh;
  padding: 24px 16px calc(24px + var(--safe-bottom));
}

.screen-active {
  display: flex;
  flex-direction: column;
}

.top-bar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.top-bar h1 {
  flex: 1;
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.link-button,
.icon-button {
  color: var(--primary);
  background: transparent;
  border-radius: 16px;
}

.link-button {
  min-width: 88px;
  height: 40px;
  padding: 0 10px;
  font-size: 14px;
}

.icon-button {
  width: 44px;
  height: 44px;
  color: var(--text);
  font-size: 40px;
  line-height: 1;
}

.display-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: stretch;
  padding: 8px 8px 28px;
  text-align: right;
}

.entry-count {
  color: var(--muted);
  font-size: 14px;
  min-height: 22px;
}

.expression-scroll {
  width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}

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

.expression {
  min-width: max-content;
  padding: 4px 4px 4px 4px;
  color: var(--muted);
  font-size: 30px;
  line-height: 1.2;
  white-space: nowrap;
}

.total {
  color: var(--text);
  font-size: clamp(68px, 22vw, 112px);
  line-height: 1;
  font-weight: 500;
  letter-spacing: -0.05em;
}

.x-count {
  margin-top: 10px;
  color: var(--primary);
  font-size: 22px;
  font-weight: 600;
}

.keypad {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 42dvh;
}

.key-row {
  flex: 1;
  display: flex;
  min-height: 72px;
}

.score-key,
.command-key {
  flex: 1;
  margin: 6px;
  min-width: 0;
  border-radius: var(--radius);
  font-size: 26px;
  color: var(--text);
  background: var(--surface);
  display: grid;
  place-items: center;
  transition: transform 80ms ease, filter 120ms ease;
}

.score-key:active,
.command-key:active,
.link-button:active,
.icon-button:active {
  transform: scale(0.98);
  filter: brightness(1.12);
}

.x-key {
  background: var(--x-button);
}

.command-key {
  background: var(--command);
}

.primary-key {
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 700;
}

.history-bar h1 {
  text-align: left;
  font-size: 22px;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 24px;
}

.history-empty {
  height: 150px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 17px;
  text-align: center;
}

.history-card {
  margin: 8px 0;
  padding: 20px 16px;
  background: var(--history-card);
  border-radius: 20px;
}

.history-date {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.history-expression {
  color: var(--text);
  font-size: 18px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.history-summary {
  margin-top: 12px;
  display: flex;
  align-items: baseline;
  gap: 16px;
}

.history-x {
  flex: 1;
  color: var(--primary);
  font-size: 16px;
  font-weight: 600;
}

.history-total {
  color: var(--text);
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
}

@media (min-width: 521px) {
  body {
    background:
      radial-gradient(circle at top, rgba(168, 199, 250, 0.08), transparent 30rem),
      var(--background);
  }

  .app-shell {
    min-height: min(900px, 100dvh);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.04);
  }
}
