/* =====================
   Reset & Base
   ===================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 17px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f9f9f8;
  color: #1a1a18;
  min-height: 100vh;
  padding: 2.5rem 1.25rem 3rem;
}

/* =====================
   Layout Wrapper
   ===================== */
.wrap {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 0 0.5rem;
}

/* =====================
   App Title
   ===================== */
.app-title {
  font-size: 1.85rem;
  font-weight: 600;
  color: #1a1a18;
  letter-spacing: -0.01em;
}

/* =====================
   Display Box
   ===================== */
.display {
  background: #ffffff;
  border: 0.5px solid #c8c7c0;
  border-radius: 14px;
  padding: 1.5rem 1.75rem;
  min-height: 150px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.display-label {
  font-size: 0.85rem;
  color: #9e9d97;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.display-formula {
  font-size: 0.95rem;
  color: #6b6b65;
  font-family: 'Courier New', Courier, monospace;
  min-height: 20px;
}

.display-result {
  font-size: 2.3rem;
  font-weight: 500;
  color: #1a1a18;
  min-height: 48px;
  word-break: break-all;
  line-height: 1.15;
}

.display-unit {
  font-size: 0.95rem;
  color: #9e9d97;
}

/* =====================
   Breadcrumb
   ===================== */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  color: #9e9d97;
  min-height: 22px;
  flex-wrap: wrap;
}

.breadcrumb span {
  color: #5a5a56;
}

.breadcrumb .sep {
  color: #c8c7c0;
}

/* =====================
   Section Label
   ===================== */
.section-label {
  font-size: 0.85rem;
  color: #9e9d97;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

/* =====================
   Grids
   ===================== */
.grid {
  display: grid;
  gap: 14px;
}

.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-auto {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

/* =====================
   Topic Buttons (main grid)
   ===================== */
.btn-topic {
  background: #ffffff;
  border: 0.5px solid #c8c7c0;
  border-radius: 14px;
  padding: 20px 18px;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 500;
  color: #1a1a18;
  text-align: center;
  transition: background 0.14s, border-color 0.14s, transform 0.14s;
  line-height: 1.4;
  min-height: 120px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.btn-topic:hover {
  background: #f7f7f5;
  border-color: #a8a8a2;
  transform: translateY(-1px);
}

.btn-topic .topic-name {
  display: block;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* =====================
   Sub-formula Buttons
   ===================== */
.btn-sub {
  background: #ffffff;
  border: 0.5px solid #e2e1db;
  border-radius: 12px;
  padding: 16px 18px;
  cursor: pointer;
  font-size: 1.05rem;
  color: #4a4a48;
  text-align: left;
  transition: background 0.14s, color 0.14s, border-color 0.14s, transform 0.14s;
}

.btn-sub:hover {
  background: #f7f7f5;
  color: #1a1a18;
  border-color: #c8c7c0;
  transform: translateY(-1px);
}

.btn-sub.active {
  border-color: #4a90d9;
  background: #eaf3fb;
  color: #1a5fa5;
}

/* =====================
   Back Button
   ===================== */
.btn-back {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  color: #185fa5;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
}

.btn-back:hover {
  text-decoration: underline;
}

/* =====================
   Calculator View
   ===================== */
#calc-view {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#sub-view {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.formula-box {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.95rem;
  color: #6b6b65;
  background: #f2f1ec;
  border: 0.5px solid #e2e1db;
  border-radius: 10px;
  padding: 10px 14px;
}

.inputs-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.input-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-row label {
  font-size: 0.95rem;
  color: #6b6b65;
}

.input-row input {
  height: 44px;
  border: 0.5px solid #c8c7c0;
  border-radius: 10px;
  padding: 0 14px;
  font-size: 1rem;
  color: #1a1a18;
  background: #ffffff;
  width: 100%;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.input-row input:focus {
  border-color: #4a90d9;
  box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.15);
}

/* =====================
   Calculate Button & Error
   ===================== */
.calc-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.btn-calc {
  background: #1a1a18;
  color: #ffffff;
  border: none;
  border-radius: 10px;
  height: 44px;
  padding: 0 1.6rem;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s;
}

.btn-calc:hover {
  background: #3a3a36;
}

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

.err {
  color: #a32d2d;
  font-size: 0.95rem;
}

/* =====================
   Responsive
   ===================== */
@media (max-width: 767px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }

  .grid-auto {
    grid-template-columns: 1fr;
  }

  .display-result {
    font-size: 2.2rem;
  }

  .btn-topic,
  .btn-sub {
    padding: 18px 16px;
    font-size: 1.05rem;
  }

  .btn-topic {
    min-height: 110px;
  }

  .btn-calc {
    width: 100%;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-auto {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .wrap {
    padding: 0 1rem;
  }
}

@media (min-width: 1024px) {
  .wrap {
    max-width: 960px;
    padding: 0;
  }

  .grid-2 {
    grid-template-columns: repeat(3, 1fr);
  }

  .grid-auto {
    grid-template-columns: repeat(3, minmax(200px, 1fr));
  }

  .display {
    min-height: 170px;
  }

  .display-result {
    font-size: 2.7rem;
  }
}
