/* Real Hourly Wage Calculator: light + dark via CSS variables */

:root {
  --bg: #f6f6f7;
  --surface: #ffffff;
  --surface-2: #f1f1f3;
  --text: #1a1b1e;
  --muted: #5f636a;          /* 5.9:1 on white */
  --border: #e2e3e6;
  --input-bg: #ffffff;
  --input-border: #c9cbd0;
  --accent: #E5484D;         /* the "real" number */
  --accent-text: #CE2C31;    /* darker red for small text, 4.9:1 on white */
  --accent-soft: #fdecec;
  --good: #1e7b45;
  --good-soft: #e6f6ec;
  --focus: #3b82f6;
  --shadow: 0 1px 2px rgba(16, 17, 20, .04), 0 6px 24px rgba(16, 17, 20, .06);
  --radius: 12px;
  --gutter: 16px;
  --sticky-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #1b1b1f;
    --surface-2: #232328;
    --text: #ededef;
    --muted: #a1a4ab;        /* 7:1 on surface */
    --border: #2e2e34;
    --input-bg: #151518;
    --input-border: #45454d;
    --accent: #ff6369;       /* brighter red keeps contrast on dark */
    --accent-text: #ff7b80;
    --accent-soft: #3b1618;
    --good: #4cc38a;
    --good-soft: #13291e;
    --focus: #6ea8ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 28px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Hiragino Sans", "Noto Sans JP", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-weight: 400;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}

h1, h2, h3 { line-height: 1.2; margin: 0; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 8px; top: -60px;
  background: var(--text); color: var(--bg);
  padding: 0 14px; min-height: 44px; display: inline-flex; align-items: center;
  border-radius: 8px; z-index: 100;
  text-decoration: none; font-weight: 600;
}
.skip-link:focus { top: 8px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.muted { color: var(--muted); }
.accent { color: var(--accent); }

/* ---------- Header ---------- */
.site-header {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px var(--gutter) 8px;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 24px;
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: -.01em; }
.site-header h1 {
  font-size: clamp(1.9rem, 6vw, 3rem);
  font-weight: 800;
  letter-spacing: -.03em;
  max-width: 18ch;
}
:lang(ja) .site-header h1 { letter-spacing: -.01em; max-width: none; }
.subtitle { margin: 12px 0 0; color: var(--muted); font-size: 1.1rem; }

/* segmented toggles (language, period) */
.lang-toggle, .period-toggle {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.seg {
  border: 0; background: transparent; cursor: pointer;
  min-height: 44px; min-width: 44px;
  padding: 0 14px; border-radius: 999px;
  font-weight: 600; font-size: .9rem; color: var(--muted);
}
.seg[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---------- Layout ---------- */
.layout {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px var(--gutter);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}
.layout > * { min-width: 0; }

/* Mobile order: form, result, compare. Desktop: form + compare left, sticky result right. */
@media (min-width: 768px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 400px);
    grid-template-areas: "form result" "compare result";
    align-items: start;
    gap: 24px;
  }
  .form-card { grid-area: form; }
  .compare-card { grid-area: compare; }
  .col-result { grid-area: result; position: sticky; top: 16px; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
@media (min-width: 768px) { .card { padding: 24px; } }

/* ---------- Form ---------- */
.form-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-bottom: 16px; margin-bottom: 8px; border-bottom: 1px solid var(--border);
}
.currency-label { font-weight: 600; }
select {
  min-height: 44px;
  padding: 0 36px 0 12px;
  border: 1px solid var(--input-border);
  border-radius: 10px;
  background: var(--input-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%23888' stroke-width='2' d='M1 1l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 12px center;
  appearance: none; -webkit-appearance: none;
  font-weight: 600; cursor: pointer;
}

.section { border: 0; padding: 0; margin: 0; min-width: 0; }
.section + .section { margin-top: 8px; padding-top: 16px; border-top: 1px solid var(--border); }
.section legend {
  padding: 16px 0 4px; font-weight: 800; font-size: 1.15rem; letter-spacing: -.01em;
  float: left; width: 100%;
}
.section legend + * { clear: both; }
.section-note { margin: 0 0 4px; color: var(--muted); font-size: .9rem; }

.fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px 16px;
  padding-top: 8px;
}
@media (min-width: 560px) { .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; padding-bottom: 6px; }
.field label { font-weight: 600; font-size: .95rem; }
.help { margin: 0; color: var(--muted); font-size: .85rem; line-height: 1.4; }
.error { margin: 0; color: var(--accent-text); font-size: .85rem; font-weight: 600; min-height: 0; }
.error:empty { display: none; }

.input-wrap {
  display: flex; align-items: center;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 10px;
  min-height: 48px;
  transition: border-color .15s, box-shadow .15s;
  order: 1;
}
.field label { order: 0; }
.field .input-wrap { order: 1; }
.field .error { order: 2; }
.field .help { order: 3; }

.input-wrap:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.input-wrap:has(input[aria-invalid="true"]) { border-color: var(--accent-text); }
.input-wrap input {
  flex: 1; min-width: 0; width: 100%;
  border: 0; background: transparent; outline: none;
  padding: 10px 12px;
  font-size: 1.05rem; font-weight: 600;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.input-wrap input::-webkit-outer-spin-button,
.input-wrap input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.prefix, .suffix { color: var(--muted); font-weight: 600; user-select: none; white-space: nowrap; }
.prefix { padding-left: 12px; margin-right: -6px; }
.suffix { padding-right: 12px; font-size: .9rem; }

.form-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; text-decoration: none;
  transition: background-color .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--text); color: var(--surface); }
.btn-primary:hover:not(:disabled) { opacity: .9; }
.btn-secondary { background: var(--surface-2); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--input-border); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--input-border); }
.btn-sm { min-height: 44px; padding: 0 14px; font-size: .9rem; }
.btn.is-done { background: var(--good-soft); color: var(--good); border-color: transparent; }

/* ---------- Result card ---------- */
.result-card { display: flex; flex-direction: column; gap: 16px; }
.result-card .label { display: block; color: var(--muted); font-weight: 600; font-size: .95rem; }
.value-think { font-size: 1.6rem; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.row-real { margin-top: 12px; }
.label-real { color: var(--text) !important; }
.value-real {
  display: block;
  font-size: clamp(3rem, 14vw, 4.25rem);
  font-weight: 800; letter-spacing: -.04em; line-height: 1.05;
  color: var(--accent); font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.per { font-size: .45em; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.value-think .per { font-size: .6em; }
.diff {
  display: inline-block; margin: 8px 0 0;
  padding: 6px 12px; border-radius: 999px;
  font-weight: 800; font-size: 1rem;
}
.diff.is-less { background: var(--accent-soft); color: var(--accent-text); }
.diff.is-more { background: var(--good-soft); color: var(--good); }
.diff.is-same { background: var(--surface-2); color: var(--muted); }

.facts { list-style: none; margin: 20px 0 0; padding: 16px 0 0; border-top: 1px solid var(--border); display: grid; gap: 10px; }
.facts li { padding-left: 22px; position: relative; }
.facts li::before { content: ""; position: absolute; left: 4px; top: .6em; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.facts b { font-weight: 800; }

.period-toggle { margin-top: 20px; }
.stats { margin: 12px 0 0; display: grid; gap: 0; }
.stat { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.stat:last-child { border-bottom: 0; }
.stat dt { color: var(--muted); font-size: .9rem; }
.stat dt .per { font-size: .85em; }
.stat dd { margin: 0; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat dd.is-bad { color: var(--accent-text); }

.notice {
  margin: 0; padding: 14px 16px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-weight: 600;
}
.warning { margin: 12px 0 0; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }

.share-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.share-row #share-x { grid-column: 1 / -1; }

/* ---------- Compare ---------- */
.compare-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.compare-head h2 { font-size: 1.15rem; font-weight: 800; }
.compare-card > .muted { margin: 8px 0 0; font-size: .95rem; }
#compare-body { margin-top: 12px; }
.compare-copy { display: flex; justify-content: flex-end; }
.compare-result { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.compare-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; table-layout: fixed; }
.compare-table th, .compare-table td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.compare-table th[scope="row"] { text-align: left; color: var(--muted); font-weight: 600; font-size: .9rem; width: 40%; }
.compare-table thead th { font-size: .9rem; }
.compare-table thead th.win { color: var(--good); }
.compare-table thead th.win::after { content: " ✓"; }
.compare-table tr.is-real td { color: var(--accent); font-weight: 800; font-size: 1.1rem; }
.verdict { margin: 12px 0 0; padding: 12px 14px; border-radius: 10px; font-weight: 600; }
.verdict.is-better { background: var(--good-soft); color: var(--good); }
.verdict.is-worse { background: var(--accent-soft); color: var(--accent-text); }
.verdict.is-same { background: var(--surface-2); }

/* ---------- How it's calculated ---------- */
.how { margin: 8px max(var(--gutter), calc((100% - 1120px) / 2 + var(--gutter))) 0; }
.how summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.how summary::-webkit-details-marker { display: none; }
.how summary::after { content: "+"; font-size: 1.5rem; font-weight: 400; color: var(--muted); }
.how details[open] summary::after { content: "-"; }
.how summary h2 { font-size: 1.15rem; font-weight: 800; display: inline; }
.how-body { padding-top: 8px; }
.how-body ol { padding-left: 1.25rem; margin: 8px 0; display: grid; gap: 8px; }
.how-body h3 { font-size: 1rem; font-weight: 800; margin: 20px 0 8px; }
.breakdown { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: .92rem; }
.breakdown th, .breakdown td { padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.breakdown th { text-align: left; font-weight: 600; }
.breakdown td.calc { color: var(--muted); overflow-wrap: anywhere; }
.breakdown td.num { text-align: right; font-weight: 600; white-space: nowrap; }
.breakdown tr.is-total th, .breakdown tr.is-total td.num { font-weight: 800; }
.breakdown tr.is-real td.num { color: var(--accent); }
@media (max-width: 559px) {
  .breakdown td.calc { display: none; }
}

/* ---------- Footer ---------- */
.site-footer {
  max-width: 1120px; margin: 0 auto;
  padding: 32px var(--gutter) 40px;
  text-align: center; color: var(--muted); font-size: .92rem;
}
.site-footer p { margin: 6px 0; }
.site-footer .privacy { color: var(--text); font-weight: 600; }
.site-footer .links a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 6px; font-weight: 600; color: var(--text); }

/* ---------- Mobile sticky bar ---------- */
.sticky-bar { display: none; }
@media (max-width: 767px) {
  .sticky-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    min-height: var(--sticky-h);
    padding: 8px var(--gutter) calc(8px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, .08);
    text-decoration: none; color: var(--text);
    transition: transform .2s ease;
  }
  .sticky-bar.is-hidden { transform: translateY(110%); }
  .sticky-label { font-size: .85rem; font-weight: 600; color: var(--muted); }
  .sticky-value { font-weight: 800; font-size: 1.35rem; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
  .sticky-value .per { font-size: .7em; }
  .sticky-diff { font-size: .8rem; font-weight: 800; color: var(--accent-text); background: var(--accent-soft); padding: 2px 8px; border-radius: 999px; vertical-align: middle; }
  /* room so the bar never covers the footer */
  body { padding-bottom: calc(var(--sticky-h) + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) { .sticky-bar { transition: none; } }
