/* StarMC responsive layout — shared by every page */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 16px;
}

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

body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  padding-left: clamp(10px, 2.5vw, 20px);
  padding-right: clamp(10px, 2.5vw, 20px);
}

.container {
  width: 100%;
  min-width: 0;
}

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

button, input, select, textarea { max-width: 100%; }

/* Avoid long player names, URLs and translated labels stretching the layout. */
.container, header, .member, .rule, .rule-text, .note-box,
.calc-form, .results, .panel, .section, .crafting-view {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Comfortable targets for touchscreens, without changing desktop sizing much. */
button, input, select, textarea, nav a, .topbar button {
  touch-action: manipulation;
}

@media (max-width: 760px) {
  body {
    padding-top: 16px;
    padding-bottom: 30px;
    background-attachment: scroll;
  }

  body > nav:not(.topbar), .site-nav {
    width: 100%;
    max-width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin: 0 auto 18px;
    padding: 0;
  }

  body > nav:not(.topbar) a, .site-nav a {
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 0;
    min-height: 44px;
    padding: 10px 9px;
    font-size: .88rem;
    line-height: 1.25;
    text-align: center;
    letter-spacing: .15px;
    overflow-wrap: anywhere;
  }

  header {
    padding: clamp(18px, 5vw, 28px) 14px !important;
    margin-bottom: 20px !important;
  }

  header h1 {
    font-size: clamp(1.42rem, 5.4vw, 2rem) !important;
    line-height: 1.2;
    letter-spacing: .2px !important;
    overflow-wrap: anywhere;
  }

  header p {
    font-size: .94rem;
    line-height: 1.5;
  }

  .action-buttons {
    gap: 10px;
    margin-bottom: 22px;
  }

  .action-btn {
    width: 100%;
    max-width: none;
    min-height: 46px;
    justify-content: center;
    padding: 12px 14px;
    text-align: center;
    overflow-wrap: anywhere;
  }

  .members {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 255px), 1fr));
  }

  .member { padding: 12px 13px; }

  .department-title {
    gap: 10px;
    flex-wrap: wrap;
    letter-spacing: 1.5px;
  }

  .section-header {
    gap: 9px;
    flex-wrap: wrap;
  }

  .rule {
    padding: 13px 15px !important;
    gap: 10px !important;
  }

  .rule-text {
    min-width: 0;
    line-height: 1.5;
  }

  .note-box {
    margin-left: 12px !important;
    margin-right: 12px !important;
  }

  .calc-form, .results, .panel {
    padding: 15px !important;
  }

  .form-row {
    flex-direction: column;
    align-items: stretch;
  }

  .form-group {
    width: 100%;
    min-width: 0 !important;
  }

  .form-group input, .form-group select,
  .field input, .field select {
    min-height: 44px;
    font-size: 16px;
  }

  .ingredients {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
  }

  .crafting-view {
    gap: 12px !important;
    padding: 13px 9px !important;
    max-width: 100%;
    justify-content: center;
  }

  .crafting-grid {
    max-width: 100%;
  }

  /* Category tabs remain in one swipeable row on small screens. */
  .topbar {
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 3px 2px 10px;
    margin-bottom: 16px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .topbar button {
    flex: 0 0 auto;
    min-height: 42px;
    white-space: nowrap;
  }

  #lang-switcher button, #theme-toggle {
    min-width: 42px;
    min-height: 42px;
  }
}

@media (max-width: 420px) {
  body { padding-left: 9px; padding-right: 9px; }
  body > nav:not(.topbar) a, .site-nav a {
    font-size: .82rem;
    padding: 9px 6px;
  }
  .rule { align-items: flex-start; }
  .rule-num { min-width: 38px !important; }
  .crafting-view { gap: 8px !important; }
}

@media (min-width: 761px) and (max-width: 1050px) {
  body { padding-left: 18px; padding-right: 18px; }
  .container { max-width: 100%; }
}

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


/* StarMC 2.0: OS/browser, accessibility and PWA refinements */
:root { color-scheme: dark light; }
html { min-height: 100%; scroll-behavior: smooth; }
body { min-height: 100vh; min-height: 100dvh; overscroll-behavior-y: contain; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; }
:focus-visible { outline: 3px solid #ffd700 !important; outline-offset: 3px; }
img { height: auto; }

/* Notch/home-indicator safe areas on iPhone and iPad. */
@supports (padding: max(0px)) {
  body { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .starmc-install-banner { bottom: max(14px, env(safe-area-inset-bottom)); left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); }
}

/* Larger hit areas on touch-first devices; mouse users keep the original density. */
@media (pointer: coarse) {
  button, [role="button"], input[type="button"], input[type="submit"], nav a { min-height: 44px; }
  input, select, textarea { font-size: 16px !important; }
}
@media (hover: none) {
  .member:hover, .rule:hover, .action-btn:hover { transform: none !important; }
}
@media (hover: hover) and (pointer: fine) {
  button, a { transition: filter .16s ease, transform .16s ease; }
}

/* Safari/iOS fallback for translucent panels. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .topbar, .starmc-install-banner { background: var(--bg2, #1a1a2e); }
}
html.os-ios input, html.os-ios select, html.os-ios textarea { border-radius: 10px; }
html.browser-safari { -webkit-text-size-adjust: 100%; }
html.os-windows, html.os-macos, html.os-linux { font-synthesis: none; }

/* Windows High Contrast / forced-colors mode. */
@media (forced-colors: active) {
  button, a, input, select, textarea, .member, .rule, .panel, .card {
    border: 1px solid ButtonText !important;
  }
  :focus-visible { outline: 2px solid Highlight !important; }
}

/* OS-level reduced motion preference. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto !important; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.starmc-install-banner {
  position: fixed; z-index: 99999; left: 14px; right: 14px; bottom: 14px;
  width: min(560px, calc(100% - 28px)); margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 16px; border: 1px solid rgba(255,255,255,.18); border-radius: 16px;
  color: var(--txt, #f4f4f4); background: rgba(20,24,36,.96);
  box-shadow: 0 12px 42px rgba(0,0,0,.35); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  font-size: 14px; line-height: 1.4;
}
.starmc-install-banner p { margin: 0; flex: 1; min-width: 0; }
.starmc-install-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 7px; }
.starmc-install-banner button { min-height: 40px; border: 0; border-radius: 10px; padding: 9px 12px; cursor: pointer; font-weight: 700; }
.starmc-install-primary { color: #171717; background: #ffd700; }
.starmc-install-close { color: #fff; background: rgba(255,255,255,.12); }
html.light-theme .starmc-install-banner { color: #1a1a2e; background: rgba(250,250,252,.97); border-color: rgba(0,0,0,.12); }
html.light-theme .starmc-install-close { color: #20202a; background: rgba(0,0,0,.08); }
@media (max-width: 560px) {
  .starmc-install-banner { align-items: stretch; flex-direction: column; gap: 10px; }
  .starmc-install-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .starmc-install-banner button { min-height: 44px; }
}
@media print {
  .starmc-install-banner, .topbar, #theme-toggle, #toTop, #lang-switcher { display: none !important; }
  body { color: #000 !important; background: #fff !important; }
}
