/* เพิ่ม Digital-7 Font */
@font-face {
  font-family: 'Digital-7';
  src: url('./../digital-7.woff') format('woff');
  font-weight: normal;
  font-style: normal;
}

/* ตัวแปรสีสำหรับแต่ละธีม */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-display: #0f3460;
  --text-primary: #e94560;
  --text-secondary: #ffffff;
  --btn-number: #533483;
  --btn-operator: #e94560;
  --btn-equals: #00d9ff;
  --btn-clear: #ff6b6b;
  --btn-backspace: #ff9f43;
  --btn-decimal: #7b68ee;
  --btn-function: #5f27cd;
  --btn-hover: rgba(255, 255, 255, 0.1);
  --shadow: rgba(0, 0, 0, 0.3);
  --history-bg: #0f1419;
  --history-item-bg: #1a1f2e;
  --history-item-hover: #252b3b;
}

/* ธีมสว่าง */
[data-theme="light"] {
  --bg-primary: #f5f5f5;
  --bg-secondary: #ffffff;
  --bg-display: #e3f2fd;
  --text-primary: #1976d2;
  --text-secondary: #424242;
  --btn-number: #90caf9;
  --btn-operator: #ff9800;
  --btn-equals: #4caf50;
  --btn-clear: #f44336;
  --btn-backspace: #ff6f00;
  --btn-decimal: #9c27b0;
  --btn-function: #673ab7;
  --btn-hover: rgba(0, 0, 0, 0.05);
  --shadow: rgba(0, 0, 0, 0.2);
  --history-bg: #fafafa;
  --history-item-bg: #ffffff;
  --history-item-hover: #e3f2fd;
}

/* ธีมนีออน */
[data-theme="neon"] {
  --bg-primary: #000000;
  --bg-secondary: #0a0a0a;
  --bg-display: #1a1a1a;
  --text-primary: #00ff41;
  --text-secondary: #00ff41;
  --btn-number: #1a1a1a;
  --btn-operator: #ff00ff;
  --btn-equals: #00ffff;
  --btn-clear: #ff0000;
  --btn-backspace: #ff8800;
  --btn-decimal: #ffff00;
  --btn-function: #ff00ff;
  --btn-hover: rgba(0, 255, 65, 0.2);
  --shadow: rgba(0, 255, 65, 0.5);
  --history-bg: #000000;
  --history-item-bg: #0a0a0a;
  --history-item-hover: #1a1a1a;
}

/* Reset CSS */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* สไตล์พื้นฐาน */
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

/* Wrapper สำหรับจัด layout */
.calculator-wrapper {
  display: flex;
  gap: 20px;
  max-width: 900px;
  width: 100%;
  align-items: flex-start;
}

/* แผงประวัติการคำนวณ */
.history-panel {
  background: var(--history-bg);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 20px 60px var(--shadow);
  width: 300px;
  max-height: 600px;
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
}

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

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 15px;
  border-bottom: 2px solid var(--text-primary);
}

.history-header h3 {
  color: var(--text-primary);
  font-size: 18px;
  font-weight: bold;
}

.btn-clear-history {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 5px 10px;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.btn-clear-history:hover {
  background: var(--btn-hover);
  transform: scale(1.1);
}

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

.history-list::-webkit-scrollbar {
  width: 8px;
}

.history-list::-webkit-scrollbar-track {
  background: var(--bg-display);
  border-radius: 10px;
}

.history-list::-webkit-scrollbar-thumb {
  background: var(--text-primary);
  border-radius: 10px;
}

.history-empty {
  color: var(--text-secondary);
  opacity: 0.5;
  text-align: center;
  padding: 20px;
  font-size: 14px;
}

.history-item {
  background: var(--history-item-bg);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 2px solid transparent;
}

.history-item:hover {
  background: var(--history-item-hover);
  border-color: var(--text-primary);
  transform: translateX(5px);
}

.history-expression {
  color: var(--text-secondary);
  font-size: 14px;
  opacity: 0.8;
  margin-bottom: 5px;
  font-family: 'Digital-7', 'Courier New', monospace;
}

.history-result {
  color: var(--text-primary);
  font-size: 18px;
  font-weight: bold;
  font-family: 'Digital-7', 'Courier New', monospace;
  letter-spacing: 2px;
}

.history-time {
  color: var(--text-secondary);
  font-size: 11px;
  opacity: 0.5;
  margin-top: 5px;
}

/* คอนเทนเนอร์หลัก */
.calculator-container {
  background: var(--bg-secondary);
  border-radius: 20px;
  padding: 30px;
  box-shadow: 0 20px 60px var(--shadow);
  max-width: 400px;
  width: 100%;
}

/* ส่วนหัว */
.calculator-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.calculator-title {
  color: var(--text-primary);
  font-size: 24px;
  font-weight: bold;
}

.header-buttons {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn-history-toggle {
  background: transparent;
  border: 2px solid var(--text-primary);
  font-size: 20px;
  cursor: pointer;
  padding: 5px 10px;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.btn-history-toggle:hover {
  background: var(--btn-hover);
  transform: scale(1.1);
}

/* ปุ่มเลือกธีม */
.theme-selector {
  display: flex;
  gap: 8px;
}

.theme-button {
  width: 30px;
  height: 30px;
  border: 2px solid var(--text-primary);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.3s ease;
  background: transparent;
}

.theme-button:hover {
  transform: scale(1.1);
}

.theme-button.active {
  box-shadow: 0 0 10px var(--text-primary);
}

.theme-button.dark { 
  background: #1a1a2e; 
}

.theme-button.light { 
  background: #f5f5f5; 
}

.theme-button.neon { 
  background: #000000; 
  border-color: #00ff41; 
}

/* หน้าจอแสดงผล - ใช้ Digital-7 Font */
.calculator-display {
  background: var(--bg-display);
  border-radius: 15px;
  padding: 20px;
  margin-bottom: 20px;
  min-height: 100px;
  text-align: right;
  box-shadow: inset 0 4px 8px var(--shadow);
}

.display-equation {
  color: var(--text-secondary);
  font-size: 20px;
  margin-bottom: 8px;
  min-height: 28px;
  opacity: 0.7;
  font-family: 'Digital-7', 'Courier New', monospace;
  word-wrap: break-word;
  word-break: break-all;
  letter-spacing: 2px;
}

.display-value {
  color: var(--text-secondary);
  font-size: 52px;
  font-weight: normal;
  font-family: 'Digital-7', 'Courier New', monospace;
  min-height: 60px;
  word-wrap: break-word;
  word-break: break-all;
  letter-spacing: 3px;
  text-shadow: 0 0 10px var(--text-secondary);
}

/* กริดปุ่ม */
.calculator-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

/* สไตล์ปุ่มทั่วไป */
.btn {
  padding: 20px;
  font-size: 24px;
  font-weight: bold;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-secondary);
  box-shadow: 0 4px 8px var(--shadow);
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px var(--shadow);
}

.btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px var(--shadow);
}

/* ปุ่มตัวเลข */
.btn-number {
  background: var(--btn-number);
}

/* ปุ่มเครื่องหมาย */
.btn-operator {
  background: var(--btn-operator);
}

/* ปุ่มเท่ากับ */
.btn-equals {
  background: var(--btn-equals);
}

/* ปุ่มล้าง */
.btn-clear {
  background: var(--btn-clear);
}

/* ปุ่ม Backspace */
.btn-backspace {
  background: var(--btn-backspace);
  font-size: 28px;
}

/* ปุ่มทศนิยม */
.btn-decimal {
  background: var(--btn-decimal);
  font-size: 32px;
}

/* ปุ่มฟังก์ชัน (%, +/-) */
.btn-function {
  background: var(--btn-function);
  font-size: 20px;
}

/* ปุ่ม 0 กว้าง 2 ช่อง */
.btn-zero {
  grid-column: span 2;
}

/* Responsive สำหรับมือถือ */
@media (max-width: 768px) {
  .calculator-wrapper {
    flex-direction: column;
    align-items: center;
  }
  
  .history-panel {
    width: 100%;
    max-width: 400px;
    order: 2;
    max-height: 300px;
  }
  
  .calculator-container {
    order: 1;
  }
}

@media (max-width: 480px) {
  .calculator-container {
    padding: 20px;
  }
  
  .display-value {
    font-size: 40px;
  }
  
  .display-equation {
    font-size: 16px;
  }
  
  .btn {
    padding: 15px;
    font-size: 20px;
  }
  
  .btn-decimal {
    font-size: 28px;
  }
  
  .btn-backspace {
    font-size: 24px;
  }
  
  .btn-function {
    font-size: 18px;
  }
  
  .history-panel {
    max-height: 250px;
  }
}