/* ===================================================================
   Mortgage Calculator — Premium Design
   =================================================================== */

/* ============ Design tokens ============ */
:root {
  --bg:           #faf6f1;
  --bg-2:         #f3eee5;
  --surface:      #ffffff;
  --surface-2:    #faf6ed;
  --surface-3:    #eee7d8;
  --border:       #e8dfcc;
  --border-soft:  #f0e9da;
  --text:         #1f1a14;
  --text-2:       #5c5547;
  --text-3:       #6e6557;
  --text-faint:   #b5ac9b;
  --accent:       #e85f4d;
  --accent-2:     #d44a39;
  --accent-soft:  rgba(232,95,77,0.10);
  --accent-glow:  rgba(232,95,77,0.30);
  --success:      #3a9d6f;
  --r-sm: 8px;
  --r-md: 12px;
  --r-xl: 20px;
  --r-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 24px 48px rgba(0,0,0,0.12);
  --transition: 200ms cubic-bezier(0.4,0,0.2,1);
  --font-ui: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "PingFang TC", "PingFang SC", "Hiragino Sans", "Noto Sans CJK", sans-serif;
}

/* ============ Reset ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
html, body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font-family: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-2); }
[hidden] { display: none !important; }

.skip-link {
  position: absolute;
  left: -9999px; top: 0;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  font-weight: 600;
  border-radius: 0 0 var(--r-sm) 0;
  z-index: 1000;
}
.skip-link:focus { left: 0; }

body {
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(255, 235, 220, 0.55) 0%, transparent 70%),
    var(--bg);
  background-attachment: fixed;
}

/* ============ App layout ============ */
.app {
  max-width: 580px;
  margin: 0 auto;
  padding: clamp(12px, 3vw, 24px) clamp(12px, 3vw, 24px) 80px;
}

/* ============ Top bar ============ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px 28px;
}
.brand {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--text-2);
}
.brand:hover { color: var(--accent); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-3);
  padding: 6px 10px;
  border-radius: var(--r-sm);
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
.nav-link:hover {
  color: var(--accent);
  background: var(--surface-2);
}

.lang-switcher {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 28px 6px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 12 12' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%237a7973' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 12px;
  transition: border-color var(--transition);
}
.lang-switcher:hover { border-color: var(--text-3); }
.lang-switcher:focus { outline: none; border-color: var(--accent); }

/* ============ Page title ============ */
.page-title {
  font-size: clamp(24px, 4vw, 32px);
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: center;
  margin-bottom: 6px;
}
.page-sub {
  text-align: center;
  font-size: 14px;
  color: var(--text-3);
  margin-bottom: 36px;
}

/* ============ Workspace ============ */
.workspace {
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin-bottom: 64px;
}

/* ============ Mode pills ============ */
.mode-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.mode-pill {
  padding: 10px 18px;
  min-height: 44px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform 80ms ease-out;
}
.mode-pill:hover {
  background: var(--accent-soft);
  border-color: var(--accent-glow);
  color: var(--accent);
}
.mode-pill:active { transform: scale(0.96); }
.mode-pill.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ============ Input card ============ */
.input-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: clamp(24px, 4vw, 32px) clamp(20px, 4vw, 28px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.input-field label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
}
.input-field input {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  -moz-appearance: textfield;
}
.input-field input::-webkit-inner-spin-button,
.input-field input::-webkit-outer-spin-button {
  opacity: 1;
  height: 30px;
}
.input-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input-hint {
  font-size: 11px;
  color: var(--text-faint);
  font-style: italic;
}

/* ============ Result card (bezel screen) ============ */
.result-card {
  --screen-bg-1: #fff4ec;
  --screen-bg-2: #f6e6d6;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 18px 18px 22px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  min-height: 140px;
  display: flex;
  flex-direction: column;
}

.result-bezel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 10px;
  position: relative;
}

.result-label {
  font-size: 10px;
  letter-spacing: 0.22em;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-3);
}

.result-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-2);
  box-shadow: var(--shadow-sm);
  transition: color var(--transition), transform 80ms ease-out, background var(--transition), border-color var(--transition);
  position: relative;
}
.result-copy:hover { color: var(--accent); border-color: var(--accent); }
.result-copy:active { transform: translateY(1px); }
.result-copy svg { width: 14px; height: 14px; }
.result-copy .icon-check { display: none; color: var(--success); }
.result-copy.is-copied .icon-copy { display: none; }
.result-copy.is-copied .icon-check { display: block; }

.result-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 90% 70% at 50% 35%, var(--screen-bg-1) 0%, var(--screen-bg-2) 100%);
  border-radius: 14px;
  padding: 22px 16px;
  min-height: 90px;
  gap: 6px;
  position: relative;
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 3px rgba(40, 28, 20, 0.08);
  overflow: hidden;
}
.result-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(0deg,
      rgba(40, 28, 20, 0.025) 0px,
      rgba(40, 28, 20, 0.025) 1px,
      transparent 1px,
      transparent 3px);
  pointer-events: none;
  border-radius: 14px;
}
.result-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35) 0%, transparent 22%);
  pointer-events: none;
  border-radius: 14px;
}

.result-number {
  position: relative;
  font-size: clamp(36px, 10vw, 72px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
  text-shadow:
    0 0 12px rgba(232, 95, 77, 0.28),
    0 1px 0 rgba(255, 255, 255, 0.45);
  z-index: 1;
  text-align: center;
}

.result-sub {
  position: relative;
  font-size: 13px;
  font-weight: 500;
  color: rgba(40, 28, 20, 0.55);
  z-index: 1;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.result-sub-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.result-sub-label {
  font-size: 9px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: rgba(40, 28, 20, 0.4);
}

.result-sub-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}

.result-empty {
  position: relative;
  font-size: 14px;
  color: rgba(40, 28, 20, 0.42);
  font-weight: 500;
  letter-spacing: 0.02em;
  z-index: 1;
}

/* ============ Amortization table ============ */
.amortization-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: clamp(20px, 4vw, 28px) clamp(16px, 4vw, 24px);
}

.amortization-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 16px;
  color: var(--text);
}

.amortization-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
}

.amortization-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.amortization-table th {
  background: var(--surface-2);
  padding: 10px 12px;
  text-align: right;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
}
.amortization-table th:first-child { text-align: left; }

.amortization-table td {
  padding: 8px 12px;
  text-align: right;
  color: var(--text-2);
  border-bottom: 1px solid var(--border-soft);
}
.amortization-table td:first-child { text-align: left; font-weight: 500; color: var(--text); }

.amortization-table tr:nth-child(even) td {
  background: var(--surface-2);
}
.amortization-table tr:last-child td {
  border-bottom: none;
}
.amortization-table tr:last-child td {
  font-weight: 600;
  color: var(--accent-2);
}

/* ============ Info section ============ */
.info {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 0;
  color: var(--text-2);
  line-height: 1.7;
}
.info h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  margin: 0 0 12px;
}
.info p { margin-bottom: 14px; font-size: 15px; }
.info .footnote {
  font-size: 12px;
  color: var(--text-3);
  font-style: italic;
  margin-top: 8px;
}

/* ============ Footer ============ */
.site-footer {
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--border-soft);
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
}
.site-footer-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 6px;
}
.site-footer a { color: var(--text-2); }
.site-footer a:hover { color: var(--accent); }
.site-footer .sub {
  font-size: 11px;
  color: var(--text-faint);
}

/* ============ Responsive ============ */
@media (max-width: 600px) {
  .app { padding: 8px 12px 60px; }
  .topbar { padding: 4px 0 20px; }
  .lang-switcher { padding: 4px 22px 4px 8px; font-size: 12px; max-width: 140px; text-overflow: ellipsis; }
  .page-sub { margin-bottom: 24px; }
  .result-card { padding: 14px 14px 18px; min-height: 120px; }
  .result-screen { min-height: 80px; padding: 18px 12px; }
  .result-number { font-size: clamp(28px, 8vw, 48px); }
  .mode-pill { padding: 8px 14px; font-size: 12px; }
  .amortization-section { padding: 16px 12px; }
  .amortization-table { font-size: 12px; }
  .amortization-table th,
  .amortization-table td { padding: 6px 8px; }
  .info { padding: 16px 4px; }
  .info h2 { font-size: 20px; margin-top: 0; }
}

@media (max-width: 420px) {
  .nav-link { display: none; }
  .lang-switcher { max-width: 130px; }
}

/* ============ Reduced motion ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============ Focus visible ============ */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus:not(:focus-visible),
select:focus:not(:focus-visible),
input:focus:not(:focus-visible) { outline: none; }
