:root {
    --bg:#27292c;
    --panel:#36373b;
    --screen:#494b52;
    --text:#e5e7eb;
    --accent:#2563eb;
    --op:#3583e9;
    --alt:#e06c00;
    --eq:#21a551;
    --log:#f9a8d4;
}

*{box-sizing:border-box}
html,body{height:100%}
body {
    margin: 0;
    display: grid;
    place-items: center;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.3 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    min-height: 100vh;
    overflow: auto;
}

.calc {
    width: min(92vw, 360px);
    background: var(--panel);
    border-radius: 18px;
    padding: 16px;
    box-shadow: 0 25px 60px rgba(0,0,0,.35);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    transform-origin: center center;
}

.calc:hover {
    transform: scale(1.3);
    box-shadow: 0 35px 80px rgba(0,0,0,.5);
    z-index: 100;
    position: relative;
}

.display-container {
    background: var(--screen);
    border-radius: 6px;
    padding: 12px 16px;
    margin-bottom: 12px;
    min-height: 76px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.equation-display {
    font-size: 14px;
    font-weight: 400;
    color: rgba(229, 231, 235, 0.7);
    text-align: right;
    min-height: 0;
    overflow: hidden;
    white-space: nowrap;
    margin-bottom: 4px;
}

.display {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: .5px;
    text-align: right;
    overflow: hidden;
    white-space: nowrap;
    line-height: 1;
}

.keys {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.key {
    appearance: none;
    border: 0;
    border-radius: 6px;
    padding: 14px 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    background: var(--screen);
    cursor: pointer;
    transition: transform .05s ease, filter .15s ease;
}

.key:active{ transform:translateY(1px) }
.key--op{ background: var(--op) }
.key--eq{ background: var(--eq) }
.key--alt{ background: var(--alt) }
.key--wide{ grid-column: span 2 }
.key--log{ background: var(--log) }

.key:focus-visible{ outline: 2px solid #fff; outline-offset: 2px }

/* ---- History modal ---- */
.history {
    padding: 0;
    border: none;
    background: transparent;
  }
  
  .history::backdrop {
    background: rgba(0,0,0,.45);
  }
  
  .history__sheet {
    width: min(92vw, 380px);
    margin: auto;
    background: var(--panel);
    color: var(--text);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,.4);
    overflow: hidden;
  }
  
  .history__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
  }
  
  .history__header h3 { 
    margin: 0; 
    font-size: 16px; 
  }
  
  .history__actions { 
    display: flex; gap: 8px; margin: 0;
  }
  
  .history__actions button {
    appearance: none;
    border: 0;
    border-radius: 6px;
    padding: 8px 10px;
    font-weight: 700;
    cursor: pointer;
  }
  
  .history__clear { background: #ef4444; color: #fff; }
  .history__close { background: var(--screen); color: var(--text); }
  
  .history__list {
    list-style: none; 
    margin: 0; 
    padding: 6px 6px 8px;
    max-height: 50vh; 
    overflow: auto;
  }
  
  .history__list li {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 10px 10px;
    border-radius: 8px;
    background: rgba(255,255,255,.04);
    margin: 6px;
    cursor: pointer;
    transition: background .15s ease;
  }
  .history__list li:hover { background: rgba(255,255,255,.08); }
  
  .history__expr { opacity: .9; }
  .history__res  { font-weight: 800; }
  
  .history__empty {
    padding: 16px; text-align: center; opacity: .7;
  }
  
  .history__hint { 
    padding: 10px 14px; 
    border-top: 1px solid rgba(255,255,255,.08);
  }