/**
 * base.css — Modern CSS Reset + Base Typography + Global Defaults
 * "Maison Rare" Design System
 *
 * Depends on: tokens.css (must be loaded first)
 */

/* ─────────────────────────────────────────────
   1. Modern CSS Reset
   ───────────────────────────────────────────── */

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

html {
  font-size: 100%;           /* 1rem = 16px base */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  tab-size: 4;
}

body {
  font-family: var(--font-body);
  font-size: var(--fs-body-md);
  line-height: var(--lh-body);
  color: var(--on-surface);
  background-color: var(--surface);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

/* ─────────────────────────────────────────────
   2. Lists
   ───────────────────────────────────────────── */

ol,
ul {
  list-style: none;
}

/* ─────────────────────────────────────────────
   3. Media Elements
   ───────────────────────────────────────────── */

img,
video,
canvas,
svg {
  max-width: 100%;
  display: block;
}

img {
  height: auto;
  font-style: italic;           /* Alt text fallback styling */
  background-color: var(--surface-container-low);
}

/* ─────────────────────────────────────────────
   4. Typography — Display & Headlines (Playfair Display)
   ───────────────────────────────────────────── */

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: var(--lh-headline);
  letter-spacing: var(--ls-display);
  color: var(--on-surface);
  overflow-wrap: break-word;
}

h1 {
  font-size: var(--fs-display-md);
  line-height: var(--lh-display);
}

h2 {
  font-size: var(--fs-headline-sm);
}

h3 {
  font-size: var(--fs-title-lg);
  font-weight: 600;
  letter-spacing: var(--ls-title);
}

h4 {
  font-size: var(--fs-title-md);
  font-weight: 600;
  letter-spacing: var(--ls-title);
}

h5 {
  font-size: var(--fs-title-sm);
  font-weight: 500;
}

h6 {
  font-size: var(--fs-body-md);
  font-weight: 500;
}

/* ─────────────────────────────────────────────
   5. Links — No standard browser blue
   ───────────────────────────────────────────── */

a {
  /* 링크 기본은 텍스트 색 상속 (푸터/카드/GNB 등 컨텍스트별 색상 존중).
     원래 링크 강조가 필요한 맥락은 개별 컴포넌트 CSS 에서 color 선언. */
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: text-decoration-color var(--transition-fast),
              color var(--transition-fast);
}

/* :visited 는 컴포넌트별 color 선언(.mr-btn-cream 등)을 덮어쓰지 않도록
   스타일을 지정하지 않는다. 브라우저 기본 :visited 보라색은 `a { color: inherit }`
   에 의해 이미 부모 색상으로 상속되므로 별도 선언 불필요. */

a:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

/* ─────────────────────────────────────────────
   6. Buttons — Reset + Touch Target
   ───────────────────────────────────────────── */

button {
  font-family: var(--font-body);
  font-size: inherit;
  line-height: 1;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  min-height: var(--touch-min);   /* 44px touch target */
  min-width: var(--touch-min);    /* 44px touch target */
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}

/* ─────────────────────────────────────────────
   7. Form Elements — Ghost Border Base Style
   ───────────────────────────────────────────── */

input[type="text"],
input[type="search"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="url"] {
  font-family: var(--font-body);
  font-size: var(--fs-body-md);
  color: var(--on-surface);
  width: 100%;

  /* Ghost Border: bottom-only */
  border: none;
  border-bottom: 1.5px solid var(--outline-variant);
  background: transparent;
  padding: 12px 4px;
  line-height: var(--lh-body);

  -webkit-appearance: none;
  appearance: none;
  outline: none;
  transition: border-bottom-color var(--transition-base);
}

input[type="text"]:focus,
input[type="search"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="tel"]:focus,
input[type="number"]:focus,
input[type="url"]:focus {
  border-bottom-color: var(--primary);
  border-bottom-width: 1.5px;
  outline: none;
}

input[type="text"]::placeholder,
input[type="search"]::placeholder,
input[type="email"]::placeholder,
input[type="password"]::placeholder,
input[type="tel"]::placeholder,
input[type="number"]::placeholder,
input[type="url"]::placeholder {
  color: var(--on-surface-variant);
  opacity: 0.7;
}

/* Chrome autofill override */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--on-surface);
  -webkit-box-shadow: 0 0 0px 1000px var(--surface) inset;
  transition: background-color 9999s ease-in-out 0s;
}

textarea {
  font-family: var(--font-body);
  font-size: var(--fs-body-md);
  color: var(--on-surface);
  width: 100%;
  border: none;
  border-bottom: 1.5px solid var(--outline-variant);
  background: transparent;
  padding: 12px 4px;
  line-height: var(--lh-body);
  resize: vertical;
  outline: none;
  transition: border-bottom-color var(--transition-base);
}

textarea:focus {
  border-bottom-color: var(--primary);
  outline: none;
}

select {
  font-family: var(--font-body);
  font-size: var(--fs-body-md);
  color: var(--on-surface);
  background: var(--surface-container-low);
  border: none;
  border-bottom: 1.5px solid var(--outline-variant);
  padding: 10px 32px 10px 12px;
  min-height: var(--touch-min);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  transition: border-bottom-color var(--transition-base);
}

select:focus {
  border-bottom-color: var(--primary);
  outline: none;
}

label {
  display: block;
  font-size: var(--fs-body-sm);
  color: var(--on-surface-variant);
  margin-bottom: var(--space-1);
  cursor: pointer;
}

fieldset {
  border: none;
  padding: 0;
}

legend {
  font-size: var(--fs-body-md);
  font-weight: 600;
  color: var(--on-surface);
  padding: 0;
  margin-bottom: var(--space-3);
}

/* ─────────────────────────────────────────────
   8. Tables
   ───────────────────────────────────────────── */

table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: var(--fs-body-md);
}

th {
  font-weight: 600;
  color: var(--on-surface);
  background: var(--surface-container-low);
}

/* ─────────────────────────────────────────────
   9. Inline Text Elements
   ───────────────────────────────────────────── */

p {
  font-size: var(--fs-body-md);
  line-height: var(--lh-body);
  color: var(--on-surface);
  overflow-wrap: break-word;
  word-break: keep-all;  /* Korean word break */
}

strong, b {
  font-weight: 700;
}

em, i {
  font-style: italic;
}

small {
  font-size: var(--fs-body-sm);
  color: var(--on-surface-variant);
}

abbr[title] {
  cursor: help;
  text-decoration: underline dotted;
}

/* ─────────────────────────────────────────────
   10. Focus Visible — Accessibility
   ───────────────────────────────────────────── */

:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Touch devices: suppress focus ring on tap */
@media (hover: none) and (pointer: coarse) {
  :focus-visible {
    outline: none;
  }
}

/* ─────────────────────────────────────────────
   11. Scrollbar (Webkit)
   ───────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--surface);
}

::-webkit-scrollbar-thumb {
  background: var(--surface-container-highest);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--on-surface-variant);
}

/* ─────────────────────────────────────────────
   12. Accessibility Utilities
   ───────────────────────────────────────────── */

/* Visually hidden but accessible to screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Reveal on focus (skip navigation links) */
.sr-only-focusable:focus,
.sr-only-focusable:focus-within {
  position: static;
  width: auto;
  height: auto;
  padding: var(--space-2) var(--space-4);
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ─────────────────────────────────────────────
   13. Selection
   ───────────────────────────────────────────── */

::selection {
  background-color: var(--primary);
  color: #fff;
}

/* ─────────────────────────────────────────────
   14. Reduced Motion
   ───────────────────────────────────────────── */

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