// ============================================================
// Yuto Water H5 — Global Styles
// Mobile-first · No Tailwind · Dark mode aware
// ============================================================

@use './variables' as *;

// ── CSS Reset (minimal, mobile-focused) ────────────────────
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

// ── HTML & Body ─────────────────────────────────────────────
html {
  // Smooth scrolling
  scroll-behavior: smooth;
  // Prevent text size adjustment on orientation change
  -webkit-text-size-adjust: 100%;
  // Font smoothing
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  // Prevent pull-to-refresh / overscroll bounce on iOS
  overscroll-behavior: none;
}

body {
  font-family: $font-family-base;
  font-size: $font-size-base;
  font-weight: $font-weight-regular;
  line-height: $line-height-normal;
  color: var(--color-text-primary);
  background-color: var(--color-bg-page);
  // Mobile-first: full viewport width
  width: 100%;
  min-height: 100vh;
  // Safe area insets for notched devices
  padding-top: $safe-area-inset-top;
  padding-bottom: $safe-area-inset-bottom;
  // Prevent horizontal overflow
  overflow-x: hidden;
  // Mobile tap highlight removal
  -webkit-tap-highlight-color: transparent;
  // Improve touch responsiveness
  touch-action: manipulation;
  // Enable momentum scrolling on iOS
  -webkit-overflow-scrolling: touch;
}

// ── Typography Defaults ─────────────────────────────────────
h1, h2, h3, h4, h5, h6 {
  font-weight: $font-weight-semibold;
  line-height: $line-height-tight;
  color: var(--color-text-primary);
}

h1 { font-size: $font-size-xxxl; }
h2 { font-size: $font-size-xxl; }
h3 { font-size: $font-size-xl; }
h4 { font-size: $font-size-lg; }
h5 { font-size: $font-size-md; }
h6 { font-size: $font-size-base; }

p {
  margin-bottom: $spacing-sm;
  color: var(--color-text-regular);
}

a {
  color: var(--color-primary);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;

  &:active {
    opacity: 0.7;
  }
}

// ── Form Elements ───────────────────────────────────────────
input,
textarea,
select,
button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  // iOS default styling reset
  -webkit-appearance: none;
  appearance: none;
  // Remove inner shadow on iOS inputs
  background-clip: padding-box;
}

// Fix iOS input zoom on focus (prevents zoom for font-size >= 16px on iOS)
input,
textarea,
select {
  font-size: $font-size-md;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;

  &:disabled {
    cursor: not-allowed;
    opacity: 0.5;
  }
}

// ── Lists ───────────────────────────────────────────────────
ul, ol {
  list-style: none;
}

// ── Images & Media ──────────────────────────────────────────
img,
video,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

img {
  // Prevent image dragging
  -webkit-user-drag: none;
  user-select: none;
}

// ── Table defaults ──────────────────────────────────────────
table {
  border-collapse: collapse;
  width: 100%;
}

// ── Focus Styles (accessibility) ────────────────────────────
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

// Remove focus outline for mouse/touch users (browser handles :focus-visible)
:focus:not(:focus-visible) {
  outline: none;
}

// ── Scrollbar Styling (WebKit) ──────────────────────────────
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-border-dark);
  border-radius: $radius-round;

  &:hover {
    background: var(--color-text-placeholder);
  }
}

// ── Selection ───────────────────────────────────────────────
::selection {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}

// ── Utility: Safe Area Padding ──────────────────────────────
.safe-area-top {
  padding-top: $safe-area-inset-top;
}

.safe-area-bottom {
  padding-bottom: $safe-area-inset-bottom;
}

// ── Utility: Screen Reader Only ─────────────────────────────
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

// ── Utility: Custom Scroll Container ────────────────────────
.scroll-container {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

// ── Page Wrapper (centered, max-width constrained) ──────────
.page-wrapper {
  max-width: $max-width-mobile;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--color-bg-page);
}

// ── Card Component Base ─────────────────────────────────────
.card {
  background: var(--color-bg-card);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  padding: 20px 16px;
  margin: $spacing-sm $spacing-md;

  &--elevated {
    box-shadow: var(--shadow-md);
  }

  &--flat {
    box-shadow: none;
    border: 1px solid var(--color-border);
  }
}

// ── Flex Helpers ────────────────────────────────────────────
.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

// ── Text Helpers ────────────────────────────────────────────
.text-primary   { color: var(--color-primary); }
.text-success   { color: var(--color-success); }
.text-warning   { color: var(--color-warning); }
.text-danger    { color: var(--color-danger); }
.text-secondary { color: var(--color-text-secondary); }
.text-ellipsis  {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

// ── Spacing Utility Classes ──────────────────────────────────
@each $size in (xxs, xs, sm, md, lg, xl, xxl, xxxl) {
  .m-#{$size}  { margin: var(--spacing-#{$size}); }
  .mt-#{$size} { margin-top: var(--spacing-#{$size}); }
  .mb-#{$size} { margin-bottom: var(--spacing-#{$size}); }
  .ml-#{$size} { margin-left: var(--spacing-#{$size}); }
  .mr-#{$size} { margin-right: var(--spacing-#{$size}); }
  .mx-#{$size} { margin-left: var(--spacing-#{$size}); margin-right: var(--spacing-#{$size}); }
  .my-#{$size} { margin-top: var(--spacing-#{$size}); margin-bottom: var(--spacing-#{$size}); }

  .p-#{$size}  { padding: var(--spacing-#{$size}); }
  .pt-#{$size} { padding-top: var(--spacing-#{$size}); }
  .pb-#{$size} { padding-bottom: var(--spacing-#{$size}); }
  .pl-#{$size} { padding-left: var(--spacing-#{$size}); }
  .pr-#{$size} { padding-right: var(--spacing-#{$size}); }
  .px-#{$size} { padding-left: var(--spacing-#{$size}); padding-right: var(--spacing-#{$size}); }
  .py-#{$size} { padding-top: var(--spacing-#{$size}); padding-bottom: var(--spacing-#{$size}); }
}

// ── Dark Mode Transition (smooth theme switch) ──────────────
body,
body *,
body *::before,
body *::after {
  transition:
    background-color $transition-base,
    border-color $transition-base,
    color $transition-fast;
}

// Disable transitions on page load (prevents flash)
.preload * {
  transition: none !important;
}
