:root {
  --bg: #eef0f2;
  --calc-bg: #d9dde1;
  --calc-border: #b7bcc2;
  --display-bg: #f7f8fa;
  --display-border: #9aa0a7;
  --text-main: #1b1f23;
  --text-muted: #5b6168;
  --btn-num-bg: #ffffff;
  --btn-num-border: #c3c8ce;
  --btn-op-bg: #e4e7ea;
  --btn-op-border: #b7bcc2;
  --btn-mem-bg: #dbe4ec;
  --btn-mem-border: #aebccb;
  --btn-clear-bg: #f3d9d9;
  --btn-clear-border: #d9a3a3;
  --btn-equals-bg: #2f6f4f;
  --btn-equals-border: #245a3f;
  --focus-ring: #1a5fb4;
  --error-color: #a41e22;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  font-family: "Segoe UI", Arial, Helvetica, sans-serif;
  color: var(--text-main);
  display: flex;
  justify-content: center;
  padding: 24px 12px;
}

.app {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.app-title {
  font-size: 1.25rem;
  margin: 0 0 4px 0;
  text-align: center;
}

.app-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0 16px 0;
  text-align: center;
}

.calculator {
  width: 100%;
  background: var(--calc-bg);
  border: 1px solid var(--calc-border);
  border-radius: 8px;
  padding: 14px;
}

.display {
  position: relative;
  background: var(--display-bg);
  border: 1px solid var(--display-border);
  border-radius: 4px;
  padding: 10px 12px;
  margin-bottom: 12px;
  text-align: right;
  overflow: hidden;
}

.memory-indicator {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--focus-ring);
  visibility: hidden;
}

.memory-indicator.active {
  visibility: visible;
}

.expression-line {
  font-size: 0.95rem;
  color: var(--text-muted);
  min-height: 1.2em;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

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

.result-line {
  font-size: 1.7rem;
  font-weight: 600;
  min-height: 1.3em;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.result-line::-webkit-scrollbar {
  display: none;
}

.result-line.error {
  color: var(--error-color);
  font-size: 1.1rem;
  font-weight: 600;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.btn {
  font-size: 1rem;
  font-family: inherit;
  padding: 12px 0;
  border-radius: 4px;
  cursor: pointer;
  background: var(--btn-num-bg);
  border: 1px solid var(--btn-num-border);
  color: var(--text-main);
  transition: background-color 0.1s ease;
}

.btn:hover {
  filter: brightness(0.97);
}

.btn:active {
  filter: brightness(0.92);
}

.btn:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}

.btn-op {
  background: var(--btn-op-bg);
  border-color: var(--btn-op-border);
}

.btn-mem {
  background: var(--btn-mem-bg);
  border-color: var(--btn-mem-border);
  font-size: 0.85rem;
}

.btn-clear {
  background: var(--btn-clear-bg);
  border-color: var(--btn-clear-border);
  font-size: 0.85rem;
}

.btn-equals {
  background: var(--btn-equals-bg);
  border-color: var(--btn-equals-border);
  color: #ffffff;
  font-weight: 700;
}

.transfer-row {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-transfer {
  background: var(--btn-mem-bg);
  border: 1px solid var(--btn-mem-border);
  border-radius: 4px;
  padding: 10px;
  font-size: 0.85rem;
  cursor: pointer;
}

.btn-transfer:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}

.transfer-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--display-bg);
  border: 1px solid var(--display-border);
  border-radius: 4px;
  padding: 6px 8px;
}

.transfer-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.transfer-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 0.95rem;
  text-align: right;
  color: var(--text-main);
}

.transfer-input:focus-visible {
  outline: 2px solid var(--focus-ring);
}

.transfer-note {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.3;
}

.app-footer {
  margin-top: 18px;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
}

@media (max-width: 400px) {
  .btn {
    font-size: 0.9rem;
    padding: 14px 0;
  }
}
