/* ===== ROOT VARIABLES ===== */
:root {
  --accent: #6C63FF;
  --accent-light: #8B85FF;
  --accent-dark: #4A44CC;
  --green: #2EC4B6;
  --orange: #FF9F1C;
  --red: #FF6B6B;
  --purple: #C77DFF;

  /* Light mode */
  --bg: #F7F7FB;
  --surface: #FFFFFF;
  --surface2: #F0F0F8;
  --text: #1A1A2E;
  --text-secondary: #6B6B8A;
  --border: #E0E0F0;
  --card-shadow: 0 4px 20px rgba(108,99,255,0.08);
  --input-bg: #F0F0F8;
  --nav-bg: #FFFFFF;
  --result-bg: #F0F0F8;
}

[data-theme="dark"] {
  --bg: #0F0E17;
  --surface: #1A1928;
  --surface2: #252436;
  --text: #FFFFFE;
  --text-secondary: #A7A9BE;
  --border: #2E2D45;
  --card-shadow: 0 4px 20px rgba(0,0,0,0.3);
  --input-bg: #252436;
  --nav-bg: #1A1928;
  --result-bg: #252436;
}

/* ===== RESET & BASE ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s ease, color 0.3s ease;
  -webkit-font-smoothing: antialiased;
}

#app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 430px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ===== SCREEN SYSTEM ===== */
.screen-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 0 80px 0;
  opacity: 0;
  transform: translateX(100%);
  transition: opacity 0.35s cubic-bezier(0.4,0,0.2,1),
              transform 0.35s cubic-bezier(0.4,0,0.2,1);
  pointer-events: none;
  scrollbar-width: none;
}

.screen::-webkit-scrollbar { display: none; }

.screen.active {
  opacity: 1;
  transform: translateX(0);
  pointer-events: all;
}

.screen.exit-left {
  opacity: 0;
  transform: translateX(-40px);
}

/* ===== TOP HEADER ===== */
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  transition: background 0.3s;
}

.header-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

.header-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.theme-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface2);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: transform 0.2s, background 0.3s;
}

.theme-btn:active { transform: scale(0.9); }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  display: flex;
  background: var(--nav-bg);
  border-top: 1px solid var(--border);
  padding: 6px 0 max(6px, env(safe-area-inset-bottom));
  position: sticky;
  bottom: 0;
  z-index: 20;
  transition: background 0.3s, border-color 0.3s;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 4px;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 500;
  transition: color 0.2s;
  position: relative;
}

.nav-item.active { color: var(--accent); }

.nav-icon {
  font-size: 20px;
  transition: transform 0.2s;
}

.nav-item.active .nav-icon {
  transform: scale(1.1);
}

.nav-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 0.2s;
}

.nav-item.active .nav-dot { opacity: 1; }

/* ===== HOME SCREEN ===== */
.home-hero {
  padding: 8px 20px 24px;
  text-align: center;
}

.triangle-visual {
  width: 100%;
  max-width: 220px;
  margin: 0 auto 20px;
  display: block;
}

.hero-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.hero-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 0 20px;
}

.home-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
  transition: transform 0.2s, box-shadow 0.2s, background 0.3s, border-color 0.3s;
  position: relative;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

.home-card::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 60px; height: 60px;
  border-radius: 0 20px 0 60px;
  opacity: 0.12;
  transition: opacity 0.2s;
}

.home-card:active {
  transform: scale(0.96);
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.home-card.accent::before { background: var(--accent); }
.home-card.green::before  { background: var(--green); }
.home-card.orange::before { background: var(--orange); }
.home-card.purple::before { background: var(--purple); }
.home-card.red::before    { background: var(--red); }
.home-card.teal::before   { background: var(--green); }

.card-icon-wrap {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.accent .card-icon-wrap { background: rgba(108,99,255,0.12); }
.green  .card-icon-wrap { background: rgba(46,196,182,0.12); }
.orange .card-icon-wrap { background: rgba(255,159,28,0.12); }
.purple .card-icon-wrap { background: rgba(199,125,255,0.12); }
.red    .card-icon-wrap { background: rgba(255,107,107,0.12); }
.teal   .card-icon-wrap { background: rgba(46,196,182,0.12); }

.card-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.card-desc {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.home-card-full {
  grid-column: 1 / -1;
}

/* ===== CALC SCREEN ===== */
.calc-content {
  padding: 0 20px 20px;
}

.section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 10px;
  margin-top: 20px;
}

.input-group {
  position: relative;
  margin-bottom: 14px;
}

.input-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.input-label span {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: white;
}

.label-a { background: var(--accent); }
.label-b { background: var(--green); }
.label-c { background: var(--orange); }

.input-field {
  width: 100%;
  background: var(--input-bg);
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 16px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, background 0.3s;
  font-family: inherit;
  -webkit-appearance: none;
}

.input-field:focus {
  border-color: var(--accent);
  background: var(--surface);
}

.input-field.error {
  border-color: var(--red);
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.input-unit {
  position: absolute;
  right: 14px;
  bottom: 14px;
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
  pointer-events: none;
}

.error-msg {
  font-size: 12px;
  color: var(--red);
  margin-top: 4px;
  padding-left: 4px;
  display: none;
}

.error-msg.show { display: block; }

.calc-btn {
  width: 100%;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 16px;
  padding: 16px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 20px;
  transition: transform 0.15s, box-shadow 0.15s, background 0.2s;
  box-shadow: 0 4px 15px rgba(108,99,255,0.35);
  letter-spacing: 0.2px;
  position: relative;
  overflow: hidden;
}

.calc-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: white;
  opacity: 0;
  transition: opacity 0.15s;
}

.calc-btn:active {
  transform: scale(0.97);
  box-shadow: 0 2px 8px rgba(108,99,255,0.25);
}

.calc-btn:active::after { opacity: 0.1; }

.calc-btn.green-btn {
  background: var(--green);
  box-shadow: 0 4px 15px rgba(46,196,182,0.35);
}

.calc-btn.orange-btn {
  background: var(--orange);
  box-shadow: 0 4px 15px rgba(255,159,28,0.35);
}

.calc-btn.purple-btn {
  background: var(--purple);
  box-shadow: 0 4px 15px rgba(199,125,255,0.35);
}

.clear-btn {
  width: 100%;
  background: transparent;
  color: var(--text-secondary);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 10px;
  transition: all 0.2s;
  font-family: inherit;
}

.clear-btn:active { transform: scale(0.97); }

/* ===== RESULT CARDS ===== */
.results-section {
  margin-top: 24px;
  display: none;
}

.results-section.show {
  display: block;
  animation: fadeUp 0.4s cubic-bezier(0.4,0,0.2,1);
}

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

.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.result-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  transition: background 0.3s, border-color 0.3s;
}

.result-card.full { grid-column: 1 / -1; }

.result-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
}

.result-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.result-value.green  { color: var(--green); }
.result-value.orange { color: var(--orange); }
.result-value.purple { color: var(--purple); }

.result-unit {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-left: 2px;
}

/* ===== TRIANGLE DIAGRAM ===== */
.triangle-diagram {
  width: 100%;
  padding: 0 20px;
  margin-top: 8px;
}

.triangle-diagram svg {
  width: 100%;
  height: auto;
  display: block;
}

/* ===== MISSING SIDE SCREEN ===== */
.side-selector {
  display: flex;
  gap: 10px;
  padding: 0 20px;
  margin-bottom: 4px;
}

.side-option {
  flex: 1;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 14px 8px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.side-option.selected {
  border-color: var(--accent);
  background: rgba(108,99,255,0.08);
}

.side-option-icon {
  font-size: 20px;
  margin-bottom: 4px;
}

.side-option-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.side-option-sub {
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.side-option.selected .side-option-label {
  color: var(--accent);
}

/* ===== ANGLE SCREEN ===== */
.angle-visual {
  width: 100%;
  padding: 10px 20px 0;
}

.angle-display {
  display: flex;
  gap: 12px;
  padding: 0 20px;
  margin-top: 4px;
}

.angle-card {
  flex: 1;
  background: var(--surface);
  border-radius: 16px;
  padding: 18px 14px;
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  transition: background 0.3s, border-color 0.3s;
}

.angle-letter {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 4px;
}

.angle-letter.alpha { color: var(--accent); }
.angle-letter.beta  { color: var(--green); }

.angle-val {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
}

.angle-unit {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

.trig-table {
  background: var(--surface);
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin: 0 20px;
  box-shadow: var(--card-shadow);
  transition: background 0.3s, border-color 0.3s;
}

.trig-row {
  display: flex;
  border-bottom: 1px solid var(--border);
  transition: border-color 0.3s;
}

.trig-row:last-child { border-bottom: none; }

.trig-cell {
  flex: 1;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  border-right: 1px solid var(--border);
  transition: border-color 0.3s;
}

.trig-cell:last-child { border-right: none; }

.trig-cell.header {
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-secondary);
  background: var(--result-bg);
}

.trig-value {
  font-weight: 700;
  color: var(--accent);
}

/* ===== FORMULA SCREEN ===== */
.formula-card {
  background: var(--surface);
  border-radius: 20px;
  margin: 12px 20px 0;
  padding: 18px;
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  transition: background 0.3s, border-color 0.3s;
}

.formula-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.formula-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.formula-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.formula-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.formula-eq {
  background: var(--result-bg);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  font-family: 'Courier New', monospace;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  transition: background 0.3s;
}

.formula-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.formula-vars {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.var-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text);
}

.var-badge {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.badge-a  { background: var(--accent); }
.badge-b  { background: var(--green); }
.badge-c  { background: var(--orange); }
.badge-th { background: var(--purple); }

.formula-diagram-wrap {
  padding: 10px 20px 0;
}

/* ===== HISTORY SCREEN ===== */
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  margin-bottom: 4px;
}

.history-count {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.clear-history-btn {
  font-size: 13px;
  color: var(--red);
  font-weight: 600;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.2s;
  font-family: inherit;
}

.clear-history-btn:active { background: rgba(255,107,107,0.1); }

.history-list {
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  background: var(--surface);
  border-radius: 16px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  transition: background 0.3s, border-color 0.3s;
  animation: fadeUp 0.3s ease;
}

.history-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.history-type {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  color: white;
}

.hist-hypo   { background: var(--accent); }
.hist-base   { background: var(--green); }
.hist-height { background: var(--orange); }
.hist-angle  { background: var(--purple); }

.history-time {
  font-size: 11px;
  color: var(--text-secondary);
}

.history-vals {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hist-val {
  font-size: 13px;
  color: var(--text);
  background: var(--result-bg);
  border-radius: 8px;
  padding: 4px 10px;
  font-weight: 500;
  transition: background 0.3s;
}

.hist-val strong {
  color: var(--accent);
  font-weight: 700;
}

.history-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.history-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.history-empty-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.history-empty-desc {
  font-size: 14px;
  line-height: 1.5;
}

/* ===== STEP BOX ===== */
.steps-box {
  background: var(--result-bg);
  border-radius: 14px;
  padding: 14px 16px;
  margin-top: 16px;
  transition: background 0.3s;
  display: none;
}

.steps-box.show { display: block; animation: fadeUp 0.3s ease; }

.steps-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 10px;
}

.step-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}

.step-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ===== PILL TABS ===== */
.pill-tabs {
  display: flex;
  gap: 8px;
  padding: 0 20px;
  margin-bottom: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.pill-tabs::-webkit-scrollbar { display: none; }

.pill-tab {
  flex-shrink: 0;
  background: var(--surface2);
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.pill-tab.active {
  background: var(--accent);
  color: white;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: all 0.3s;
  z-index: 100;
  white-space: nowrap;
  pointer-events: none;
}

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

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ===== ANGLE DISPLAY FIX ===== */
.angle-display {
  display: flex;
  gap: 12px;
  padding: 0 20px;
  margin-top: 4px;
}

.angle-card {
  flex: 1;
  background: var(--surface);
  border-radius: 16px;
  padding: 18px 14px;
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  transition: background 0.3s, border-color 0.3s;
}

.angle-letter {
  font-size: 26px;
  font-weight: 900;
  margin-bottom: 4px;
  font-family: Georgia, serif;
}
.angle-letter.alpha { color: var(--purple); }
.angle-letter.beta  { color: var(--green); }

.angle-val {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
}
.angle-unit {
  font-size: 16px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ===== UTIL ===== */
.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
  transition: background 0.3s;
}

.badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
}

.badge-new {
  background: rgba(46,196,182,0.15);
  color: var(--green);
}

/* ===== RESPONSIVE ===== */
@media (min-width: 430px) {
  #app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    box-shadow: 0 0 40px rgba(0,0,0,0.1);
  }
}

/* ===== ANIMATIONS ===== */
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.result-value { animation: none; }
.result-value.pop {
  animation: pulse 0.4s cubic-bezier(0.4,0,0.2,1);
}

/* Loading spinner */
.loading {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== FORMULA SCREEN SPECIFIC ===== */
.formula-section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  padding: 20px 20px 0;
}

.pythagorean-diagram {
  width: 100%;
  padding: 16px 20px 0;
}
