@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Lexend:wght@400;500;600;700&display=swap');

:root {
  --primary: #6366f1;
  --secondary: #a855f7;
  --accent: #22d3ee;
  --danger: #f43f5e;
  --success: #10b981;
  
  --bg-color: #f8fafc;
  --text-main: #0f172a;
  --text-muted: #64748b;
  
  --calc-bg: rgba(255, 255, 255, 0.7);
  --calc-border: rgba(255, 255, 255, 0.5);
  --display-bg: rgba(241, 245, 249, 0.8);
  
  --btn-bg: #ffffff;
  --btn-text: #334155;
  --btn-op-bg: #eef2ff;
  --btn-op-text: #4f46e5;
  --btn-eq-bg: linear-gradient(135deg, #6366f1, #a855f7);
  --btn-eq-text: #ffffff;
  
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --glass-blur: blur(12px);
}

[data-theme='dark'] {
  --bg-color: #020617;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  --calc-bg: rgba(15, 23, 42, 0.7);
  --calc-border: rgba(30, 41, 59, 0.5);
  --display-bg: rgba(0, 0, 0, 0.3);
  
  --btn-bg: #1e293b;
  --btn-text: #f1f5f9;
  --btn-op-bg: #312e81;
  --btn-op-text: #e0e7ff;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-color);
  background-image: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.1) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(168, 85, 247, 0.1) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(34, 211, 238, 0.1) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Header Styling */
header {
  padding: 1.25rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--calc-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--calc-border);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.site-brand h1 {
  font-family: 'Lexend', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  background: linear-gradient(to right, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}

@media (max-width: 1024px) {
  .brand-descriptor {
    display: none;
  }
}

@media (max-width: 600px) {
  header {
    padding: 1rem;
  }
  .site-brand h1 {
    font-size: 1rem;
  }
}

/* Page Layout */
main {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 3rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 3rem;
}

.calc-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  align-items: start;
}

@media (min-width: 992px) {
  .calc-container {
    grid-template-columns: 1.2fr 0.8fr;
  }
}

/* Calculator Component */
.calculator {
  background: var(--calc-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--calc-border);
  border-radius: 2rem;
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}

.calculator::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(to right, var(--primary), var(--secondary));
}

/* Display Section */
.display-section {
  background: var(--display-bg);
  border-radius: 1.25rem;
  padding: 1.5rem;
  margin-bottom: 2rem;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  position: relative;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--calc-border);
}

.rad-deg-toggle {
  position: absolute;
  top: 1rem;
  left: 1rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--btn-op-bg);
  padding: 0.25rem 0.6rem;
  border-radius: 0.5rem;
  text-transform: uppercase;
}

.history-expr {
  font-size: 1rem;
  color: var(--text-muted);
  text-align: right;
  margin-bottom: 0.5rem;
  min-height: 1.5rem;
  overflow-x: auto;
  white-space: nowrap;
}

.current-input {
  font-family: 'Lexend', sans-serif;
  font-size: 3rem;
  font-weight: 600;
  text-align: right;
  overflow-x: auto;
  white-space: nowrap;
  letter-spacing: -0.02em;
}

/* Grid System */
.grid-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}

.grid-buttons.advanced-visible {
  grid-template-columns: repeat(5, 1fr);
}

/* Button Styling */
button {
  border: none;
  border-radius: 1rem;
  padding: 1.25rem 0.5rem;
  font-family: 'Inter', sans-serif;
  font-size: 1.125rem;
  font-weight: 600;
  background: var(--btn-bg);
  color: var(--btn-text);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  filter: brightness(1.05);
}

button:active {
  transform: translateY(0);
  box-shadow: none;
  filter: brightness(0.95);
}

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

.btn-danger {
  background: rgba(244, 63, 94, 0.1);
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  color: white;
}

.btn-eq {
  background: var(--btn-eq-bg);
  color: var(--btn-eq-text);
  grid-column: span 1;
}

.btn-adv {
  font-size: 0.9rem;
  background: rgba(99, 102, 241, 0.05);
  display: none;
}

.advanced-visible .btn-adv {
  display: flex;
}

/* History Panel */
.history-panel {
  background: var(--calc-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--calc-border);
  border-radius: 2rem;
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  max-height: 600px;
  display: flex;
  flex-direction: column;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--calc-border);
}

.history-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.history-actions button {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  margin-left: 0.5rem;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding-right: 0.5rem;
}

.history-item {
  padding: 1rem;
  border-radius: 1rem;
  margin-bottom: 0.75rem;
  background: var(--display-bg);
  cursor: pointer;
  transition: all 0.2s;
  text-align: right;
}

.history-item:hover {
  transform: translateX(-4px);
  background: var(--btn-op-bg);
}

.history-item-expr {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.history-item-result {
  font-weight: 700;
  color: var(--text-main);
  font-size: 1.1rem;
}

/* Controls */
.controls {
  display: flex;
  gap: 0.75rem;
}

.theme-toggle, .mode-toggle {
  background: var(--btn-bg);
  border: 1px solid var(--calc-border);
  padding: 0.6rem 1.2rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

/* SEO Content & FAQ */
.seo-content {
  background: var(--calc-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--calc-border);
  border-radius: 2rem;
  padding: 3rem;
  box-shadow: var(--shadow-lg);
}

.seo-content h2 {
  font-size: 2rem;
  margin-bottom: 1.5rem;
  background: linear-gradient(to right, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.seo-content p {
  font-size: 1.1rem;
  line-height: 1.8;
  color: var(--text-main);
  opacity: 0.9;
  margin-bottom: 1.5rem;
}

.faq-section {
  margin-top: 3rem;
  display: grid;
  gap: 1.5rem;
}

.faq-section dl {
  display: grid;
  gap: 2rem;
}

.faq-section dt {
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.faq-section dt::before {
  content: 'Q.';
  font-size: 0.8rem;
  background: var(--primary);
  color: white;
  padding: 0.2rem 0.4rem;
  border-radius: 0.3rem;
}

.faq-section dd {
  margin-left: 0;
  line-height: 1.7;
  color: var(--text-muted);
}

/* Footer */
footer {
  margin-top: auto;
  padding: 4rem 2rem;
  text-align: center;
  border-top: 1px solid var(--calc-border);
  background: var(--calc-bg);
}

footer nav {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

footer nav a {
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
  transition: color 0.2s;
}

footer nav a:hover {
  color: var(--primary);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text-main);
  color: var(--bg-color);
  padding: 1rem 2rem;
  border-radius: 1rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  opacity: 0;
  transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 9999;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--calc-border);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
