/* ==========================================================================
   스마트 만능 계산기 - 스타일시트 (style.css)
   모던 다크/라이트 테마, 세련된 반응형 레이아웃, 모바일 터치 최적화
   ========================================================================== */

/* 1. 디자인 시스템 & CSS 변수 */
:root {
  /* 다크 테마 기본값 (세련된 딥 네이비 & 선명한 숫자 가독성) */
  --bg-color: #0b0f19;
  --card-bg: rgba(19, 27, 46, 0.98);
  --header-bg: rgba(11, 15, 25, 0.85);
  --border-color: rgba(255, 255, 255, 0.12);
  
  --text-main: #ffffff;
  --text-muted: #cbd5e1;
  --text-subtle: #94a3b8;
  
  /* 키패드 숫자 버튼 색상 (숫자가 또렷하고 선명하게 보이도록 최적화) */
  --btn-num-bg: #2b3954;
  --btn-num-hover: #3c4f74;
  --btn-num-active: #1e283d;
  --btn-num-text: #ffffff;
  
  --btn-func-bg: #374663;
  --btn-func-hover: #485b80;
  --btn-func-active: #263249;
  --btn-func-text: #ffffff;
  
  --btn-op-bg: #f59e0b;
  --btn-op-hover: #d97706;
  --btn-op-active: #b45309;
  --btn-op-text: #ffffff;
  
  --btn-eq-bg: #10b981;
  --btn-eq-hover: #059669;
  --btn-eq-active: #047857;
  --btn-eq-text: #ffffff;
  
  /* 하이라이트 & 카드 색상 */
  --primary-accent: #38bdf8;
  --accent-color: #f43f5e;
  --input-bg: #162035;
  --input-border: #2c3b59;
  --result-card-bg: #162035;
  --shadow-color: rgba(0, 0, 0, 0.55);
  
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;
  
  --font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, 'Helvetica Neue', 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', sans-serif;
}

/* 라이트 테마 */
body.light-theme {
  --bg-color: #f1f5f9;
  --card-bg: rgba(255, 255, 255, 0.96);
  --header-bg: rgba(241, 245, 249, 0.85);
  --border-color: rgba(0, 0, 0, 0.08);
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  
  --btn-num-bg: #f8fafc;
  --btn-num-hover: #e2e8f0;
  --btn-num-active: #cbd5e1;
  --btn-num-text: #1e293b;
  
  --btn-func-bg: #e2e8f0;
  --btn-func-hover: #cbd5e1;
  --btn-func-active: #94a3b8;
  --btn-func-text: #0f172a;
  
  --btn-op-bg: #f59e0b;
  --btn-op-hover: #d97706;
  --btn-op-active: #b45309;
  --btn-op-text: #ffffff;
  
  --btn-eq-bg: #10b981;
  --btn-eq-hover: #059669;
  --btn-eq-active: #047857;
  --btn-eq-text: #ffffff;
  
  --primary-accent: #0284c7;
  --accent-color: #e11d48;
  --input-bg: #f8fafc;
  --input-border: #cbd5e1;
  --result-card-bg: #f8fafc;
  --shadow-color: rgba(0, 0, 0, 0.1);
}

/* 2. 전역 리셋 & 레이아웃 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  overflow-x: hidden;
  transition: background-color 0.25s ease, color 0.25s ease;
  user-select: none;
}

/* 3. 앱 컨테이너 */
.app-container {
  width: 100%;
  max-width: 380px;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* 4. 상단 헤더 */
.app-header {
  margin-bottom: 10px;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 6px 10px;
}

.logo-title {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.logo-icon {
  font-size: 1.25rem;
}

.header-controls {
  display: flex;
  gap: 6px;
}

.icon-btn {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 6px var(--shadow-color);
  transition: all 0.2s ease;
}

.icon-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
}

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

.theme-icon {
  font-size: 1rem;
}

/* 모드 탭 네비게이션 */
.mode-nav {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  background: var(--card-bg);
  padding: 5px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: 0 4px 12px var(--shadow-color);
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 7px 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: var(--primary-accent);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(56, 189, 248, 0.4);
}

.tab-btn:hover:not(.active) {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

/* 5. 메인 카드 */
.calculator-card {
  background: var(--card-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: 0 12px 30px var(--shadow-color);
  backdrop-filter: blur(16px);
  overflow: hidden;
  position: relative;
  min-height: 460px;
}

.mode-section {
  display: none;
  padding: 16px;
}

.mode-section.active {
  display: block;
  animation: fadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* 6. 디스플레이 화면 (음영 없이 깔끔하고 선명한 숫자 화면) */
.display-container {
  background: #111a2e;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 14px;
  text-align: right;
  cursor: pointer;
  position: relative;
  min-height: 94px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  transition: all 0.2s ease;
}

.display-container:hover {
  border-color: var(--primary-accent);
  background: #141f36;
}

.expression-line {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  min-height: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.result-wrapper {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none; /* Firefox */
}

.result-wrapper::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.result-line {
  font-size: 2.35rem;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.01em;
  line-height: 1.15;
  white-space: nowrap;
  text-shadow: none;
  transition: font-size 0.15s ease;
}

.copy-badge {
  position: absolute;
  top: 6px;
  left: 10px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-subtle);
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 7px;
  border-radius: var(--radius-full);
  opacity: 0.9;
  pointer-events: none;
}

/* 7. 일반 계산기 키패드 */
.keypad-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 9px;
}

.btn {
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: 12px;
  font-family: inherit;
  font-size: 1.32rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.08s ease, filter 0.15s ease, background-color 0.15s ease;
  touch-action: manipulation;
}

.btn:active,
.btn.is-pressed {
  transform: scale(0.92);
  filter: brightness(0.85);
}

/* 숫자 버튼 스타일 (선명하고 깨끗한 플랫 버튼) */
.btn-num {
  background-color: #243048;
  color: #ffffff;
}
.btn-num:hover {
  background-color: #31405e;
}

.btn-func {
  background-color: #3b4866;
  color: #ffffff;
  font-size: 1.15rem;
}
.btn-func:hover {
  background-color: #4a5b80;
}

/* 1행 기능키: 30% 투명한 파스텔 바탕색 + 동색상 선명한 테두리 */
/* 1) AC (초기화): 30% 투명 파스텔 로즈 핑크 + 로즈 테두리 */
#key-clear {
  background-color: rgba(244, 163, 163, 0.70);
  border: 1.5px solid #f87171;
  color: #0f172a;
  font-weight: 700;
}
#key-clear:hover {
  background-color: rgba(244, 163, 163, 0.88);
  border-color: #ef4444;
  color: #0f172a;
}

/* 2) % (퍼센트): 30% 투명 파스텔 라벤더 + 라벤더 테두리 */
#key-percent {
  background-color: rgba(216, 180, 254, 0.70);
  border: 1.5px solid #c084fc;
  color: #0f172a;
  font-weight: 700;
}
#key-percent:hover {
  background-color: rgba(216, 180, 254, 0.88);
  border-color: #a855f7;
  color: #0f172a;
}

/* 3) ⌫ (삭제): 30% 투명 파스텔 스카이블루 + 스카이 테두리 */
#key-delete {
  background-color: rgba(147, 197, 253, 0.70);
  border: 1.5px solid #60a5fa;
  color: #0f172a;
  font-weight: 700;
}
#key-delete:hover {
  background-color: rgba(147, 197, 253, 0.88);
  border-color: #3b82f6;
  color: #0f172a;
}

/* 라이트 테마일 때 개별 기능키 파스텔 색상 */
body.light-theme #key-clear {
  background-color: rgba(254, 205, 211, 0.75);
  border: 1.5px solid #f43f5e;
  color: #0f172a;
}
body.light-theme #key-clear:hover {
  background-color: #fecdd3;
}

body.light-theme #key-percent {
  background-color: rgba(237, 233, 254, 0.75);
  border: 1.5px solid #8b5cf6;
  color: #0f172a;
}
body.light-theme #key-percent:hover {
  background-color: #ede9fe;
}

body.light-theme #key-delete {
  background-color: rgba(224, 242, 254, 0.75);
  border: 1.5px solid #0ea5e9;
  color: #0f172a;
}
body.light-theme #key-delete:hover {
  background-color: #e0f2fe;
}

.btn-operator {
  background-color: var(--btn-op-bg);
  color: var(--btn-op-text);
  font-size: 1.4rem;
}
.btn-operator:hover {
  background-color: var(--btn-op-hover);
}

.btn-operator.is-active-op {
  box-shadow: 0 0 0 2px #ffffff, 0 0 10px var(--btn-op-bg);
}

.btn-equals {
  background-color: var(--btn-eq-bg);
  color: var(--btn-eq-text);
  font-size: 1.4rem;
}
.btn-equals:hover {
  background-color: var(--btn-eq-hover);
}

/* 8. 부가 계산기 툴 공통 스타일 */
.tool-content {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 4px;
}

.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

.btn-text-reset {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn-text-reset:hover {
  background: rgba(244, 63, 94, 0.1);
  color: var(--accent-color);
  border-color: var(--accent-color);
  transform: scale(1.03);
}

.btn-text-reset:active {
  transform: scale(0.96);
}

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

.input-group label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
}

.tool-input {
  width: 100%;
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--text-main);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.tool-input:focus {
  border-color: var(--primary-accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.tool-input.text-right {
  text-align: right;
}

.input-with-unit {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-unit .unit {
  position: absolute;
  right: 16px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  pointer-events: none;
}

.input-with-unit .tool-input {
  padding-right: 40px;
}

.input-row {
  display: flex;
  gap: 12px;
}

.flex-1 { flex: 1; }
.flex-2 { flex: 2; }

.select-box {
  cursor: pointer;
}

.quick-chips {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.chip-btn {
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip-btn:hover {
  background: var(--primary-accent);
  color: #ffffff;
  border-color: var(--primary-accent);
}

.btn-action {
  width: 100%;
  background: var(--primary-accent);
  border: none;
  color: #ffffff;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(56, 189, 248, 0.4);
  transition: all 0.2s ease;
}

.btn-action:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.btn-action:active {
  transform: scale(0.98);
}

/* 결과 카드 */
.result-card {
  background: var(--result-card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px;
  margin-top: 4px;
  animation: fadeIn 0.25s ease;
}

.result-highlight {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--border-color);
  margin-bottom: 12px;
}

.result-highlight .highlight-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
}

.result-highlight .highlight-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--primary-accent);
}

.result-highlight.primary .highlight-value {
  color: var(--btn-eq-bg);
}

.result-grid-info {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.info-item.full-width {
  grid-column: span 2;
  padding-top: 6px;
  border-top: 1px solid var(--border-color);
}

.item-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-subtle);
}

.item-value {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
}

.text-accent {
  color: var(--accent-color) !important;
}

/* 날짜 서브 탭 */
.sub-tab-nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: rgba(0, 0, 0, 0.1);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.sub-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 0;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sub-tab-btn.active {
  background: var(--input-bg);
  color: var(--text-main);
  box-shadow: 0 2px 4px var(--shadow-color);
}

.sub-tool-box {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.sub-tool-box.active {
  display: flex;
}

/* 9. 계산 기록 슬라이드 패널 */
.history-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 320px;
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  border-left: 1px solid var(--border-color);
  box-shadow: -8px 0 24px var(--shadow-color);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
}

.history-panel.open {
  transform: translateX(0);
}

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

.history-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  color: var(--text-main);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  text-align: right;
  cursor: pointer;
  transition: all 0.15s ease;
}

.history-item:hover {
  border-color: var(--primary-accent);
  background: rgba(56, 189, 248, 0.08);
}

.history-exp {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.history-res {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.empty-history {
  text-align: center;
  color: var(--text-subtle);
  font-size: 0.9rem;
  margin-top: 40px;
}

.history-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border-color);
}

.btn-clear-history {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-clear-history:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
  background: rgba(244, 63, 94, 0.05);
}

/* 오버레이 */
.backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  border-radius: var(--radius-lg);
}

.backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* 10. 토스트 알림 */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(15, 23, 42, 0.92);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 1000;
}

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

/* 11. 반응형 미디어 쿼리 */
@media (max-width: 480px) {
  body {
    padding: 8px;
    align-items: flex-start;
  }
  .app-container {
    max-width: 100%;
  }
  .calculator-card {
    border-radius: var(--radius-md);
    min-height: auto;
  }
  .mode-section {
    padding: 16px;
  }
  .result-line {
    font-size: 2.25rem;
  }
  .btn {
    font-size: 1.35rem;
    border-radius: var(--radius-sm);
  }
}
