@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Oswald:wght@400;600&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --body-bg:      #2a2a2a;
  --calc-body:    #c8c0b0;
  --calc-shadow:  #5a5040;
  --calc-accent:  #4a3f2f;
  --key-digit:    #161616;
  --key-op:       #1b65b9;
  --key-service:  #8f1b1b;
  --key-equals:   #1b65b9;
  --key-func:     #1b65b9;
  --key-text:     #d4d4d4;
  --key-light:    #f0ece0;
  --display-bg:   #0d1a0d;
  --display-glow: #22cc44;
  --display-dim:  #0a4010;
  --brand-red:    #c0392b;
  --history-bg:   #1e1e1e;
  --history-text: #d0d0c0;
  --history-line: #3a3a3a;
}

body {
  background: var(--body-bg);
  background-image:
    radial-gradient(ellipse at 30% 20%, #3a3020 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, #1a2030 0%, transparent 60%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Oswald', sans-serif;
  padding: 20px;
}

.page-wrapper {
  display: flex;
  align-items: flex-start;
  gap: 28px;
}

.calculator-wrap {
  filter: drop-shadow(0 20px 40px rgba(0,0,0,0.7));
}

.calc-body {
  width: 280px;
  background: var(--calc-body);
  border-radius: 14px 14px 10px 10px;
  padding: 20px 18px 18px;
  border: 2px solid #a09080;
  box-shadow:
    inset 0 2px 4px rgba(255,255,255,0.5),
    inset 0 -3px 8px rgba(0,0,0,0.25),
    0 2px 0 var(--calc-shadow);
  position: relative;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(0,0,0,0.08) 1px, transparent 0);
  background-size: 4px 4px;
}

.brand-plate {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  margin-top: 8px;
  margin-bottom: 0;
  padding: 0 4px;
}

.brand-name {
  font-family: 'Oswald', sans-serif;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--calc-accent);
  text-transform: uppercase;
  opacity: 0.75;
}

.display-housing {
  background: #1a1a14;
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 18px;
  box-shadow:
    inset 0 4px 12px rgba(0,0,0,0.8),
    inset 0 1px 3px rgba(0,0,0,0.6),
    0 1px 0 rgba(255,255,255,0.15);
  border: 1px solid #0a0a08;
}

.display-inner {
  background: var(--display-bg);
  border-radius: 3px;
  height: 52px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  position: relative;
  overflow: hidden;
}

.seven-seg-display {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  position: relative;
  z-index: 1;
}

.sign-indicator {
  position: relative;
  width: 10px;
  height: 26px;
  margin-right: 1.5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  flex-shrink: 0;
}

.sign-bar {
  width: 8px;
  height: 2px;
  border-radius: 1px;
  margin-bottom: 9px;
}

.sign-bar.on {
  background: var(--display-glow);
  box-shadow: 0 0 2px var(--display-glow), 0 0 5px rgba(34,204,68,0.7);
}

.sign-bar.off {
  background: var(--display-dim);
}

.seg-digit {
  position: relative;
  width: 16px;
  height: 26px;
  margin: 0 1.5px;
  display: flex;
  align-items: flex-end;
  flex-shrink: 0;
}

.seg-digit-svg {
  width: 12px;
  height: 20px;
  overflow: visible;
  flex-shrink: 0;
}

.seg-on {
  fill: var(--display-glow);
  filter: drop-shadow(0 0 2px var(--display-glow)) drop-shadow(0 0 5px rgba(34,204,68,0.7));
}

.seg-off {
  fill: var(--display-dim);
}

.seg-dot-on, .seg-dot-off {
  display: inline-block;
  width: 2.6px;
  height: 2.6px;
  border-radius: 50%;
  margin: 0 1.5px 1.5px 1px;
  flex-shrink: 0;
}

.seg-dot-on {
  background: var(--display-glow);
  box-shadow: 0 0 2px var(--display-glow), 0 0 4px rgba(34,204,68,0.7);
}

.seg-dot-off {
  background: var(--display-dim);
}

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.key-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.key {
  height: 46px;
  border-radius: 5px;
  border: none;
  cursor: pointer;
  font-family: 'Oswald', sans-serif;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
  position: relative;
  transition: transform 0.07s, box-shadow 0.07s, filter 0.07s;
  outline: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.key::after {
  content: '';
  position: absolute;
  bottom: -3px;
  left: 2px;
  right: 2px;
  height: 3px;
  border-radius: 0 0 5px 5px;
  opacity: 0.6;
  transition: height 0.07s, bottom 0.07s;
}

.key:active,
.key.pressed {
  transform: translateY(2px);
  box-shadow: none !important;
}

.key:active::after,
.key.pressed::after {
  height: 1px;
  bottom: -1px;
}

.key-digit {
  background: var(--key-digit);
  color: var(--key-text);
  box-shadow:
    0 3px 0 #a09080,
    0 4px 6px rgba(0,0,0,0.3),
    inset 0 1px 0 rgba(255,255,255,0.08);
}
.key-digit::after { background: #a09080; }
.key-digit:hover { filter: brightness(1.05); }

.key-op {
  background: var(--key-op);
  color: #f0e8d8;
  font-size: 18px;
  box-shadow:
    0 3px 0 #4a3a20,
    0 4px 6px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.25);
}
.key-op::after { background: #4a3a20; }
.key-op:hover { filter: brightness(1.12); }

.key-service {
  background: var(--key-service);
  color: #e8d0c0;
  font-size: 14px;
  box-shadow:
    0 3px 0 #3a1a0a,
    0 4px 6px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.15);
}
.key-service::after { background: #3a1a0a; }
.key-service:hover { filter: brightness(1.15); }

.key-func {
  background: var(--key-func);
  color: #d8e8c8;
  font-size: 15px;
  box-shadow:
    0 3px 0 #2a3a1a,
    0 4px 6px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.2);
}
.key-func::after { background: #2a3a1a; }
.key-func:hover { filter: brightness(1.12); }

.key-equals {
  background: var(--key-equals);
  color: #ffe0d8;
  font-size: 20px;
  box-shadow:
    0 3px 0 #5a0808,
    0 4px 6px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.2);
}
.key-equals::after { background: #5a0808; }
.key-equals:hover { filter: brightness(1.15); }

.bottom-strip {
  height: 5px;
  background: #a09080;
  border-radius: 0 0 6px 6px;
  margin-top: 12px;
}

.history-panel {
  width: 220px;
  background: var(--history-bg);
  border-radius: 10px;
  border: 1px solid #2e2e2e;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #161616;
  border-bottom: 1px solid var(--history-line);
  font-family: 'Oswald', sans-serif;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #888;
}

.history-clear-btn {
  background: none;
  border: none;
  color: #555;
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 3px;
  transition: color 0.2s, background 0.2s;
  line-height: 1;
}
.history-clear-btn:hover {
  color: #ff6644;
  background: rgba(255,100,68,0.12);
}

.history-list {
  list-style: none;
  padding: 8px 0;
  max-height: 400px;
  overflow-y: auto;
}

.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-track { background: var(--history-bg); }
.history-list::-webkit-scrollbar-thumb { background: #3a3a3a; border-radius: 2px; }

.history-empty {
  padding: 14px 16px;
  font-family: 'Oswald', sans-serif;
  font-size: 12px;
  color: #444;
  text-align: center;
  font-style: italic;
  letter-spacing: 0.5px;
}

.history-item {
  padding: 8px 14px;
  border-bottom: 1px solid var(--history-line);
  animation: fadeIn 0.2s ease;
}

.history-item:last-child { border-bottom: none; }

.history-expr {
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  color: #666;
  margin-bottom: 2px;
  letter-spacing: 0.5px;
}

.history-result {
  font-family: 'Share Tech Mono', monospace;
  font-size: 15px;
  color: var(--display-glow);
  text-shadow: 0 0 6px rgba(34,204,68,0.4);
  letter-spacing: 1px;
}

.history-result.error {
  color: #ff6644;
  font-size: 11px;
  letter-spacing: 0.3px;
  font-family: 'Oswald', sans-serif;
  white-space: normal;
  line-height: 1.4;
  text-shadow: none;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (max-width: 560px) {
  .page-wrapper { flex-direction: column; align-items: center; }
  .history-panel { width: 280px; }
}