:root {
  color-scheme: light dark;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

.calc {
  width: 100%;
  height: 100%;
  background: #1f2937;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.calc-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #e5e7eb;
  font-size: 0.9rem;
}

.back-link {
  color: #a5b4fc;
  text-decoration: none;
  font-weight: 600;
}

.back-link:hover {
  text-decoration: underline;
}

.mode-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  user-select: none;
}

.display {
  flex: 0 0 auto;
  width: 100%;
  border: none;
  border-radius: 0.75rem;
  padding: 1rem;
  font-size: clamp(1.75rem, 6vw, 2.5rem);
  text-align: right;
  background: #111827;
  color: #f9fafb;
  outline: none;
}

.display.error {
  color: #f87171;
}

.preview {
  flex: 0 0 auto;
  min-height: 1.2rem;
  padding: 0 0.25rem;
  text-align: right;
  font-size: 1rem;
  color: #9ca3af;
}

.pad {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.row {
  flex: 1 1 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.sci-row {
  display: none;
}

.calc.scientific .sci-row {
  display: grid;
}

button {
  border: none;
  border-radius: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1rem, 3.5vw, 1.3rem);
  background: #374151;
  color: #f9fafb;
  cursor: pointer;
  transition: background 0.15s ease;
}

button:hover {
  background: #4b5563;
}

button:active {
  background: #6366f1;
}

button.op {
  background: #4338ca;
}

button.op:hover {
  background: #4f46e5;
}

button.equals {
  background: #6366f1;
  grid-column: span 2;
}

button.equals:hover {
  background: #818cf8;
}

#angle-mode {
  background: #4338ca;
}
