:root {
  /* Modern Color Palette */
  --primary: #004d2e;
  --primary-light: #e6f0eb;
  --accent: #d4af37;
  --text-main: #2c3e50;
  --text-light: #5e6d7e;
  --bg-body: #f8f9fa;
  --white: #ffffff;

  /* Spacing & Layout */
  --container-width: 1100px;
  --header-height: 80px;

  /* Safe Area Insets for iOS */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.12);

  /* Transitions */
  --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Noto Sans JP", sans-serif;
  color: var(--text-main);
  background-color: var(--bg-body);
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Prevent font scaling in landscape on iOS */
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
  width: 100%;
}

/* Prevent scrolling when mobile menu is open */
body.menu-open {
  overflow: hidden;
}

a {
  text-decoration: none;
  color: inherit;
  transition: var(--transition);
  /* Ensure ample touch area */
  touch-action: manipulation;
}

ul {
  list-style: none;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* --- Typography --- */
h1,
h2,
h3,
h4 {
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.05em;
}

.section-title {
  text-align: center;
  margin-bottom: clamp(3rem, 5vw, 4rem);
  position: relative;
  padding: 0 1rem;
}

.section-title h2 {
  /* Fluid typography: scales between 1.8rem and 2.2rem */
  font-size: clamp(1.8rem, 4vw, 2.2rem);
  color: var(--primary);
  margin-bottom: 0.5rem;
  display: inline-block;
}

.section-title p {
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

/* --- Layout --- */
.container {
  max-width: var(--container-width);
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 2rem);
  width: 100%;
}

section {
  padding: clamp(3rem, 8vw, 5rem) 0;
}

/* --- Header --- */
header {
  height: var(--header-height);
  background-color: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  /* Safari support */
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  padding-top: var(--safe-top);
  /* iOS Status bar handling */
}

.header-container {
  width: 100%;
  max-width: var(--container-width);
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 2rem);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo a {
  font-size: clamp(1.1rem, 4vw, 1.4rem);
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.nav-menu {
  display: flex;
  gap: 2.5rem;
}

.nav-link {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-main);
  position: relative;
  padding: 0.5rem 0;
}

.nav-link::after {
  content: '';
  position: absolute;
  width: 0;
  height: 2px;
  bottom: 0;
  left: 50%;
  background-color: var(--accent);
  transition: var(--transition);
  transform: translateX(-50%);
}

.nav-link:hover::after,
.nav-link.active::after {
  width: 100%;
}

.mobile-menu-btn {
  display: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--primary);
  padding: 0.5rem;
  /* Touch target */
  z-index: 1002;
}

/* --- Hero --- */
.hero {
  height: 85vh;
  min-height: 500px;
  /* Reduced for smaller screens */
  background-image: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.4)), url('../images/hero-bg.jpg');
  background-size: cover;
  background-position: center 80%;
  background-attachment: fixed;
  /* Note: Can be jittery on mobile, handled in media query */
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--white);
  padding: 0 1rem;
  margin-top: calc(var(--header-height) * -1);
  /* Underlay header */
  padding-top: var(--header-height);
}

.hero-content {
  max-width: 800px;
  animation: fadeUp 1s ease-out;
  width: 100%;
}

.hero h1 {
  font-size: clamp(2rem, 8vw, 3.5rem);
  margin-bottom: 1.5rem;
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  letter-spacing: 0.1em;
  line-height: 1.2;
}

.hero p {
  font-size: clamp(1rem, 3vw, 1.2rem);
  margin-bottom: 2.5rem;
  opacity: 0.9;
}

/* --- Buttons --- */
.btn {
  display: inline-block;
  padding: 1rem 2.5rem;
  border-radius: 4px;
  font-weight: 600;
  letter-spacing: 0.05em;
  transition: var(--transition);
  border: 2px solid transparent;
  cursor: pointer;
  /* Prevent iOS button styling */
  -webkit-appearance: none;
  appearance: none;
}

.btn-primary {
  background-color: var(--primary);
  color: var(--white);
  box-shadow: 0 4px 15px rgba(0, 77, 46, 0.3);
}

.btn-primary:hover {
  background-color: var(--white);
  color: var(--primary);
  border: 2px solid var(--primary);
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(0, 77, 46, 0.4);
}

/* --- Services Grid --- */
.services-section {
  background-color: var(--white);
}

.services-grid {
  display: grid;
  /* Lowered min-width to 280px for better support on narrow phones like Galaxy Fold or iPhone SE */
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 2.5rem;
}

.service-card {
  background: var(--white);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  position: relative;
  height: 100%;
}

.service-card:hover {
  transform: translateY(-10px);
  box-shadow: var(--shadow-lg);
}

/* Disable hover effects on touch devices to prevent stuck states */
@media (hover: none) {
  .service-card:hover {
    transform: none;
    box-shadow: var(--shadow-sm);
  }
}

.service-img-wrapper {
  height: 240px;
  overflow: hidden;
}

.service-img-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.service-card:hover .service-img-wrapper img {
  transform: scale(1.05);
}

.service-content {
  padding: 2rem;
}

.service-content h3 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  color: var(--primary);
}

.service-link {
  display: inline-block;
  margin-top: 1.5rem;
  color: var(--primary);
  font-weight: 600;
  border-bottom: 1px solid var(--primary);
  padding-bottom: 2px;
}

.service-link:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* --- News List --- */
.news-list {
  background: var(--white);
  padding: clamp(1.5rem, 4vw, 3rem);
  /* Responsive padding */
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  max-width: 900px;
  margin: 0 auto;
}

.news-item {
  display: grid;
  grid-template-columns: 100px 100px 1fr;
  align-items: center;
  padding: 1.2rem 0;
  border-bottom: 1px solid #eee;
  gap: 1.5rem;
  transition: var(--transition);
}

.news-item:last-child {
  border-bottom: none;
}

.news-item:hover {
  background-color: var(--bg-body);
  border-radius: 8px;
  /* Adjusted hover margin/padding logic for cleaner implementation */
  padding-left: 1rem;
  padding-right: 1rem;
  margin: 0 -1rem;
}

.news-date {
  color: var(--text-light);
  font-size: 0.9rem;
  font-family: 'Roboto', sans-serif;
}

.news-cat {
  font-size: 0.75rem;
  padding: 4px 0;
  text-align: center;
  border-radius: 20px;
  color: var(--white);
  font-weight: 600;
  white-space: nowrap;
}

.cat-news {
  background-color: var(--accent);
}

.cat-const {
  background-color: var(--primary);
}

.cat-it {
  background-color: #333;
}

.news-title {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-main);
  display: block;
  /* Ensure text-overflow works */
}

/* --- Forms (Contact / Inputs) --- */
.form-control,
input[type="text"],
input[type="email"],
textarea,
select {
  /* iOS Reset */
  -webkit-appearance: none;
  appearance: none;
  border-radius: 8px;
  /* Force iOS to respect this */
  font-size: 16px;
  /* Prevent iOS zoom */
}

/* --- Footer --- */
footer {
  background-color: #1a1a1a;
  color: #fff;
  padding: 5rem 0 calc(2rem + var(--safe-bottom));
  /* Safe area for home indicator */
}

.footer-content {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 4rem;
  margin-bottom: 3rem;
}

.footer-info h3 {
  font-size: 1.4rem;
  margin-bottom: 1.5rem;
  color: var(--white);
}

.footer-links h4 {
  font-size: 1.1rem;
  margin-bottom: 1.5rem;
  color: var(--accent);
}

.footer-links ul li {
  margin-bottom: 0.8rem;
}

.copyright {
  text-align: center;
  font-size: 0.85rem;
  color: #888;
  padding-top: 2rem;
  border-top: 1px solid #333;
}

/* --- Animations --- */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.8s ease-out, transform 0.8s ease-out;
}

.fade-in.visible {
  opacity: 1;
  transform: translateY(0);
}

/* --- Subpages --- */
.page-hero {
  height: 40vh;
  min-height: 250px;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  /* Fix header underlay gap */
  margin-top: calc(var(--header-height) * -1);
  padding-top: var(--header-height);
}

.page-hero::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.page-hero-content {
  position: relative;
  z-index: 1;
  text-align: center;
  color: var(--white);
  width: 100%;
}

.page-hero h1 {
  font-size: clamp(2rem, 5vw, 2.8rem);
  margin-bottom: 0.5rem;
}

/* --- Mobile / Tablet Specifics --- */
@media (max-width: 900px) {
  .hero {
    /* Disable fixed background on mobile for performance/jitter fixes */
    background-attachment: scroll;
  }
}

@media (max-width: 768px) {
  .nav-menu {
    position: fixed;
    top: 0;
    right: -100%;
    width: 100%;
    height: 100vh;
    background-color: var(--white);
    /* Reduced gap to fix excessive spacing */
    gap: 0.8rem;
    align-items: center;
    /* Center items instead of stretch */
    /* ... */
    padding: 3rem;
    padding-bottom: calc(3rem + var(--safe-bottom));
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
    z-index: 1001;
  }

  .nav-menu.active {
    right: 0;
  }

  .nav-link {
    font-size: 1.2rem;
    /* Reduced padding */
    padding: 0.5rem 0;
    width: auto;
    /* Fit content to make underline match text length */
    text-align: center;
    display: inline-block;
    /* Essential for width: auto behaviors */
    /* Full width click target dropped in favor of visual design request */
  }

  .mobile-menu-btn {
    display: block;
    margin-left: auto;
    /* Force to right side */
    padding: 0.5rem;
  }

  /* Hamburger to Close Icon Transformation */
  .mobile-menu-btn.active span {
    display: none;
  }

  .mobile-menu-btn.active::before {
    content: '✕';
    /* Close icon */
    font-size: 2rem;
    line-height: 1;
    color: var(--primary);
  }

  .news-item {
    grid-template-columns: 1fr;
    /* Stack vertically */
    gap: 0.5rem;
    text-align: left;
  }

  .news-date,
  .news-cat {
    display: inline-block;
    margin-right: 0.5rem;
  }

  .news-cat {
    width: auto;
    padding: 2px 10px;
  }

  .news-title {
    white-space: normal;
    /* Allow wrap on mobile */
  }

  .footer-content {
    grid-template-columns: 1fr;
    /* Single column footer */
    gap: 2rem;
    text-align: center;
    /* Center footer on mobile */
  }

  .footer-links ul li {
    display: block;
    /* Ease of tapping */
    margin-bottom: 1rem;
  }

  /* Recruit Banner Mobile */
  .recruit-banner {
    padding: 2rem !important;
    /* Reduce padding on mobile */
  }
}