.calculator-app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  width: 100%;
}

.calc-wrapper {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  justify-content: center;
}

/* Calculator Main Shell */
.calculator-main {
  flex: 1;
  max-width: 720px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.5), 0 0 25px rgba(99, 102, 241, 0.08);
  position: relative;
  overflow: hidden;
}

/* Topbar */
.calc-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.brand-tag {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--secondary-accent);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.angle-mode-toggle {
  display: inline-flex;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 2px;
}

.mode-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: var(--transition-fast);
}

.mode-btn.active {
  background: var(--primary-accent);
  color: #ffffff;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.icon-toggle-btn {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: var(--transition-fast);
}

.icon-toggle-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--primary-accent);
}

/* Display Panel */
.display-panel {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  text-align: right;
  margin-bottom: 1.5rem;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
  position: relative;
  overflow: hidden;
}

.expression-line {
  min-height: 1.6rem;
  font-size: 1.05rem;
  color: var(--text-secondary);
  font-family: 'Inter', monospace;
  overflow-x: auto;
  white-space: nowrap;
  letter-spacing: 0.03em;
  padding-bottom: 0.3rem;
  scroll-behavior: smooth;
}

.expression-line::-webkit-scrollbar {
  height: 3px;
}
.expression-line::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

.preview-line {
  font-size: 0.95rem;
  color: var(--secondary-accent);
  min-height: 1.3rem;
  font-family: 'Inter', monospace;
  opacity: 0.9;
  letter-spacing: 0.02em;
}

.result-line {
  font-size: 2.3rem;
  font-weight: 700;
  color: var(--text-primary);
  font-family: 'Inter', monospace;
  overflow-x: auto;
  white-space: nowrap;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.result-line.error {
  color: #f87171;
  font-size: 1.6rem;
}

/* Keypad Grid */
.keypad-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.6rem;
}

.btn {
  font-family: 'Inter', 'Pretendard', sans-serif;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 0.85rem 0.2rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  cursor: pointer;
  user-select: none;
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.btn:active {
  transform: scale(0.95);
}

/* Button Variants */
.btn-num {
  background: rgba(30, 41, 59, 0.9);
  color: var(--text-primary);
  font-size: 1.2rem;
  font-weight: 600;
}
.btn-num:hover {
  background: rgba(51, 65, 85, 0.9);
  border-color: rgba(148, 163, 184, 0.4);
}

.btn-op {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.35);
  color: #A5B4FC;
  font-size: 1.3rem;
}
.btn-op:hover {
  background: rgba(99, 102, 241, 0.3);
  color: #FFFFFF;
}

.btn-func {
  background: rgba(15, 23, 42, 0.65);
  color: #CBD5E1;
  font-size: 0.95rem;
}
.btn-func:hover {
  background: rgba(51, 65, 85, 0.7);
  color: #FFFFFF;
}

.mode-indicator {
  font-weight: 800;
  color: var(--secondary-accent);
  pointer-events: none;
  font-size: 0.82rem;
  border-color: rgba(6, 182, 212, 0.3);
}

.btn-secondary {
  background: rgba(15, 23, 42, 0.8);
  color: var(--text-secondary);
}
.btn-secondary:hover {
  color: var(--text-primary);
  background: rgba(51, 65, 85, 0.8);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.35);
  color: #F87171;
}
.btn-danger:hover {
  background: rgba(239, 68, 68, 0.3);
  color: #FFFFFF;
}

.btn-primary {
  background: var(--primary-accent);
  color: #FFFFFF;
  border-color: var(--primary-accent);
  font-size: 1.35rem;
  box-shadow: 0 4px 14px var(--accent-glow);
}
.btn-primary:hover {
  background: var(--primary-hover);
}

/* Grid layout overrides */
.zero-btn {
  grid-column: span 1;
}

.equals-btn {
  grid-column: span 2;
}

/* History Panel */
.history-panel {
  width: 360px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.4rem;
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  max-height: 600px;
}

.history-panel.collapsed {
  display: none;
}

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

.history-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.history-title h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.history-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-text-sm {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  transition: var(--transition-fast);
}
.btn-text-sm:hover {
  color: #F87171;
  background: rgba(239, 68, 68, 0.1);
}

.history-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}
.history-close-btn:hover {
  color: var(--text-primary);
}

.history-tip {
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 0.8rem;
  padding: 0.5rem 0.75rem;
  background: rgba(15, 23, 42, 0.4);
  border-radius: var(--radius-sm);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding-right: 0.3rem;
}

.history-list::-webkit-scrollbar {
  width: 4px;
}
.history-list::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

.history-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
  padding: 3rem 1rem;
}

.history-item {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  position: relative;
  transition: var(--transition-fast);
}

.history-item:hover {
  border-color: var(--primary-accent);
  background: rgba(15, 23, 42, 0.95);
}

.history-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.history-item-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0 0.2rem;
}
.history-item-delete:hover {
  color: #F87171;
}

.history-item-expr {
  font-size: 0.88rem;
  color: var(--text-secondary);
  cursor: pointer;
  word-break: break-all;
  font-family: 'Inter', monospace;
  transition: color var(--transition-fast);
}
.history-item-expr:hover {
  color: var(--secondary-accent);
  text-decoration: underline;
}

.history-item-res {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
  text-align: right;
  font-family: 'Inter', monospace;
  transition: color var(--transition-fast);
}
.history-item-res:hover {
  color: var(--primary-accent);
}

/* Responsive Rules */
@media (max-width: 960px) {
  .calc-wrapper {
    flex-direction: column;
    align-items: center;
  }
  .calculator-main {
    width: 100%;
    max-width: 650px;
  }
  .history-panel {
    width: 100%;
    max-width: 650px;
    max-height: 380px;
  }
}

@media (max-width: 640px) {
  .calculator-app {
    padding: 0.8rem 0.6rem 2.5rem;
  }

  .calculator-main {
    padding: 0.85rem 0.75rem;
    border-radius: var(--radius-md);
  }

  .calc-topbar {
    margin-bottom: 0.75rem;
  }

  .brand-tag {
    font-size: 0.75rem;
  }

  .display-panel {
    padding: 0.9rem 1rem;
    min-height: 110px;
    margin-bottom: 1rem;
    border-radius: var(--radius-sm);
  }

  .expression-line {
    font-size: 0.95rem;
    min-height: 1.4rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  .preview-line {
    font-size: 0.85rem;
    min-height: 1.15rem;
  }

  .result-line {
    font-size: 1.85rem;
    line-height: 1.25;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    scrollbar-width: thin;
  }

  .result-line::-webkit-scrollbar {
    height: 3px;
  }
  .result-line::-webkit-scrollbar-thumb {
    background: var(--border-color);
  }

  /* 7열을 모바일 폭에서도 가로 스크롤/핏 가능하도록 세밀한 비율과 패딩 설정 */
  .keypad-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.3rem;
  }

  .btn {
    font-size: 0.82rem;
    min-height: 44px;
    padding: 0.55rem 0.05rem;
    border-radius: 6px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .btn-num {
    font-size: 1.05rem;
    font-weight: 700;
  }

  .btn-op {
    font-size: 1.15rem;
  }

  .btn-func {
    font-size: 0.72rem;
    letter-spacing: -0.02em;
  }

  .btn-primary {
    font-size: 1.2rem;
  }

  .mode-indicator {
    font-size: 0.7rem;
  }

  .equals-btn {
    grid-column: span 2;
  }

  /* 모바일 히스토리 패널 */
  .history-panel {
    max-height: 320px;
    padding: 1rem;
  }
}

/* 초소형 모바일 화면 (360px 이하) */
@media (max-width: 375px) {
  .keypad-grid {
    gap: 0.22rem;
  }

  .btn {
    font-size: 0.74rem;
    min-height: 42px;
    padding: 0.5rem 0;
  }

  .btn-num {
    font-size: 0.98rem;
  }

  .btn-func {
    font-size: 0.68rem;
  }

  .result-line {
    font-size: 1.6rem;
  }
}

