/* ===== Tokens ===== */
/*
  Breakpoints (media queries cannot read custom properties, so the values are written in each @media):
  - 48rem (768px, md): header nav text size, #top / #localize side padding, #localize two columns, form rows, #contact illustration
  - 64rem (1024px, lg): #app two columns
  - 72rem (1152px): #localize main column switches to a 60% basis (matches the old flex-shrink result)
*/
:root {
  color-scheme: light;

  /* Colors */
  --color-text: #000000;
  --color-text-muted: #666666;
  --color-text-inverse: #fefefe;
  --color-text-inverse-soft: rgba(254, 254, 254, 0.85);
  --color-text-inverse-muted: rgba(254, 254, 254, 0.6);
  --color-text-inverse-placeholder: rgba(254, 254, 254, 0.54);
  --color-surface-page: #ffffff;
  --color-surface-warm: #ecebe4;
  --color-surface-light: #fefefe;
  --color-surface-brand: #193654;
  --color-surface-dark: #3a3a3c;
  --color-accent: #c9ef52;
  --color-accent-alt: #a270e1;
  --color-on-accent: #000000;
  --color-on-accent-alt: #000000;
  --color-biji: #800202;
  --color-on-biji: #ffffff;
  --color-button-bg: #111111;
  --color-button-text: #ffffff;
  --color-error: #ff8080;
  --color-divider-inverse: rgba(255, 255, 255, 0.15);
  --color-input-border: rgba(255, 255, 255, 0.4);
  --color-slider-track: #e0e0e0;
  --color-slider-inactive: #636363;
  --color-logo-backdrop: rgba(255, 255, 255, 0.7);
  --color-hover-overlay: rgba(0, 0, 0, 0.05);
  --color-focus: #193654;
  --color-focus-inverse: #c9ef52;

  --shadow-slider-track: inset 0 2px 6px rgba(0, 0, 0, 0.2);
  --shadow-slider-thumb: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-app-logo: 0 2px 8px rgba(0, 0, 0, 0.15);
  --color-carousel-arrow-bg: rgba(0, 0, 0, 0.15);

  /* Fonts */
  --font-sans: "Zen Kaku Gothic New", sans-serif;
  --font-mono: "Geist Mono", ui-monospace, monospace;
  --font-mono-system: monospace;

  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-lg: 1.125rem;
  --font-size-4xl: 2.25rem;

  /* Spacing */
  --header-height: 3.5rem;
  --space-page-x: 1.5rem;
  --space-section-x: 8vw;
  --space-section-y: 3.75rem;

  /* Opacity of secondary text in app cards */
  --opacity-card-url: 0.56;
  --opacity-card-url-on-accent-alt: 0.75;

  /* App carousel (one card per view, as in the old Splide setup) */
  --carousel-gap: 1rem;
  --card-height: 30rem;
  /* One-column cap: about the 2-column card at 1290px, so the phone mockup is mostly visible instead of only its top. */
  --carousel-max-width-single: 22rem;

  /* Motion */
  --duration-slider: 0.2s;
}

/* ===== Reset & base ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: 0 solid;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: var(--header-height);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  background: var(--color-surface-page);
  color: var(--color-text);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3 {
  font-size: inherit;
  font-weight: inherit;
}

ul {
  list-style: none;
}

a {
  color: inherit;
  text-decoration: inherit;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
  background: transparent;
}

button {
  cursor: pointer;
}

textarea {
  resize: vertical;
}

::placeholder {
  color: var(--color-text-inverse-placeholder);
  opacity: 1;
}

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

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* ===== Components ===== */
.button {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  font-weight: 500;
  line-height: calc(1.25 / 0.875);
}

.button--dark {
  background: var(--color-button-bg);
  color: var(--color-button-text);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ===== Header ===== */
.site-header {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 50;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: var(--header-height);
  padding-inline: var(--space-page-x);
  background: var(--color-surface-warm);
}

.site-header__logo img {
  width: 47px;
  height: 50px;
  object-fit: contain;
}

.site-nav__list {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.875rem;
  border-radius: 9999px;
  background: var(--color-surface-light);
}

/* Padding enlarges the tap target to 44px; the negative margin keeps the pill the same size. */
.site-nav__link {
  display: block;
  margin-block: -0.875rem;
  padding: 0.875rem 0.625rem;
  color: var(--color-text);
  font-size: var(--font-size-xs);
  font-weight: 600;
  line-height: 1rem;
}

@media (min-width: 48rem) {
  .site-nav__link {
    font-size: var(--font-size-sm);
    line-height: 1.25rem;
    margin-block: -0.75rem;
    padding-block: 0.75rem;
  }
}

/* ===== Layout ===== */
main {
  padding-top: var(--header-height);
}

.top,
.app,
.localize,
.contact {
  min-height: 100vh;
  min-height: 100svh;
}

/* ===== #top ===== */
.top {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 6rem var(--space-page-x);
  background: var(--color-surface-warm);
  color: var(--color-text);
}

/* The second term only bites below ~400px: it keeps "こんにちは！" (about 6em wide) on one line down to 320px. */
.top__title {
  font-size: min(clamp(3.625rem, 8vw, 4.8125rem), calc((100vw - 3rem) / 6));
  font-weight: 900;
  line-height: 1.1;
}

.top__hello {
  display: block;
  font-size: clamp(5.875rem, 17vw, 9.75rem);
}

.top__konnichiwa,
.top__link {
  display: inline-block;
  position: relative;
  max-width: 100%;
}

.top__konnichiwa {
  white-space: nowrap;
}

/* Own stacking context so the highlight SVG (positioned, inserted by rough-notation) can sit under the punctuation. */
.top__intro {
  position: relative;
  z-index: 0;
  margin-top: 1.5rem;
  font-size: clamp(1.0625rem, 3vw, 1.75rem);
  font-weight: 600;
  line-height: 1.6;
}

.top__note {
  margin-top: 5rem;
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  line-height: 1rem;
}

@media (min-width: 48rem) {
  .top {
    padding-inline: var(--space-section-x);
  }
}

/* Link preview card (built by js/link-preview.js, positioned in page coordinates) */
.link-preview {
  position: absolute;
  z-index: 50;
  width: 13.75rem;
  pointer-events: none;
}

.link-preview__image {
  width: 100%;
  height: 5.625rem;
  border-radius: 0.25rem;
  object-fit: cover;
}

.top__intro > .rough-annotation {
  z-index: -1;
}

/* rough-notation's own keyframes, shipped here because the CSP blocks the inline <style> it would inject. */
@keyframes rough-notation-dash {
  to {
    stroke-dashoffset: 0;
  }
}

/* ===== #app ===== */
[data-app-lang="en"] .app [data-i18n="ja"],
[data-app-lang="ja"] .app [data-i18n="en"] {
  display: none;
}

.app {
  display: flex;
  flex-direction: column;
  padding: var(--space-section-y) var(--space-section-x);
  background: var(--color-surface-light);
  color: var(--color-text);
}

/* Language slider */
.lang-slider {
  --slider-position: 15%;
  margin-bottom: 2rem;
}

[data-app-lang="ja"] .lang-slider {
  --slider-position: 85%;
}

html:not(.js) .lang-slider {
  display: none;
}

.lang-slider__track {
  position: relative;
  height: 3rem;
  border-radius: 9999px;
  background: var(--color-slider-track);
  box-shadow: var(--shadow-slider-track);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.lang-slider__thumb,
.lang-slider__option {
  position: absolute;
  top: 4px;
  width: 50%;
  height: calc(100% - 8px);
  border-radius: 9999px;
}

.lang-slider__thumb {
  left: calc(var(--slider-position) / 2);
  background: var(--color-accent);
  box-shadow: var(--shadow-slider-thumb);
}

[data-app-lang="ja"] .lang-slider__thumb {
  background: var(--color-biji);
}

.lang-slider__option {
  display: flex;
  align-items: center;
  padding-inline: 1.25rem;
  color: var(--color-slider-inactive);
  font-size: var(--font-size-sm);
  font-weight: 700;
  line-height: 1.25rem;
  cursor: inherit;
}

.lang-slider__option[data-lang-option="en"] {
  left: 0;
  justify-content: flex-start;
}

.lang-slider__option[data-lang-option="ja"] {
  right: 0;
  justify-content: flex-end;
}

/* The active label rides on the thumb. */
[data-app-lang="en"] .lang-slider__option[data-lang-option="en"],
[data-app-lang="ja"] .lang-slider__option[data-lang-option="ja"] {
  z-index: 1;
  right: auto;
  left: calc(var(--slider-position) / 2);
  justify-content: center;
}

[data-app-lang="en"] .lang-slider__option[data-lang-option="en"] {
  color: var(--color-on-accent);
}

[data-app-lang="ja"] .lang-slider__option[data-lang-option="ja"] {
  color: var(--color-on-biji);
}

.lang-slider--dragging {
  cursor: grabbing;
}

@media (prefers-reduced-motion: no-preference) {
  .lang-slider__thumb,
  .lang-slider__option {
    transition: left var(--duration-slider) ease, background var(--duration-slider) ease;
  }

  .lang-slider--dragging .lang-slider__thumb,
  .lang-slider--dragging .lang-slider__option {
    transition: none;
  }
}

/* Intro column */
.app__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2rem;
}

.app__intro {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.app__title {
  margin-bottom: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  text-transform: lowercase;
}

.app__title [data-i18n="en"] {
  display: block;
  font-size: clamp(3rem, 9vw, 6.875rem);
  line-height: 1;
}

.app__title [data-i18n="ja"] {
  display: block;
  font-size: clamp(2rem, 6vw, 4.6875rem);
  line-height: 1.4;
  letter-spacing: -0.04em;
}

.app__sub {
  max-width: 32rem;
  margin-bottom: 3rem;
  font-size: var(--font-size-lg);
  font-weight: 600;
  line-height: calc(1.75 / 1.125);
}

.app__cta {
  margin-bottom: 1rem;
}

.app__intro .button {
  align-self: flex-start;
}

@media (min-width: 64rem) {
  .app__body {
    flex-direction: row;
    align-items: stretch;
  }

  .app__intro {
    width: calc(100% * 2 / 3);
  }

  /* Centred like .app__intro, so both columns share the same vertical middle however tall the row gets. */
  .app-carousel {
    justify-content: center;
    width: calc(100% / 3);
    max-width: none;
  }
}

/* App carousel: native horizontal scroll with snapping; js/carousel.js only adds arrows and mouse dragging. */
.app-carousel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
  max-width: var(--carousel-max-width-single);
}

.app-carousel__viewport {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  border-radius: 1rem;
}

/* Scrollbar hidden only when the arrows exist; without JS it stays as a visible way to scroll. */
.js .app-carousel__viewport {
  scrollbar-width: none;
}

.js .app-carousel__viewport::-webkit-scrollbar {
  display: none;
}

/* While dragging, scrollLeft is set on every pointer move: smooth scrolling would make it lag behind the pointer. */
.app-carousel--dragging .app-carousel__viewport {
  scroll-snap-type: none;
  scroll-behavior: auto;
  cursor: grabbing;
  user-select: none;
  -webkit-user-select: none;
}

.app-list {
  display: flex;
  gap: var(--carousel-gap);
}

.app-card {
  flex: 0 0 100%;
  scroll-snap-align: start;
}

.app-carousel__controls {
  display: flex;
  justify-content: flex-end;
}

html:not(.js) .app-carousel__controls {
  display: none;
}

/* 44px tap target; the visible 32px circle and chevron are drawn by the pseudo-elements. */
.app-carousel__arrow {
  position: relative;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  color: var(--color-text);
}

.app-carousel__arrow::before,
.app-carousel__arrow::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
}

.app-carousel__arrow::before {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--color-carousel-arrow-bg);
}

.app-carousel__arrow::after {
  width: 0.5rem;
  height: 0.5rem;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
}

.app-carousel__arrow--prev::after {
  transform: translateX(1px) rotate(-135deg);
}

.app-carousel__arrow--next::after {
  transform: translateX(-1px) rotate(45deg);
}

.app-carousel__arrow[aria-disabled="true"] {
  opacity: 0.35;
  cursor: default;
}

@media (prefers-reduced-motion: no-preference) {
  .app-carousel__viewport {
    scroll-behavior: smooth;
  }
}

.app-card__link {
  display: block;
  position: relative;
  height: var(--card-height);
  overflow: hidden;
  padding: 1.25rem;
  border-radius: 1rem;
  background: var(--color-accent);
  color: var(--color-on-accent);
}

.app-card:nth-child(3n + 2) .app-card__link {
  background: var(--color-accent-alt);
  color: var(--color-on-accent-alt);
}

.app-card:nth-child(3n) .app-card__link {
  background: var(--color-surface-warm);
}

.app-card__link::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  background: transparent;
  pointer-events: none;
}

.app-card__link:hover::after {
  background: var(--color-hover-overlay);
}

/* The scroll container would clip an outer ring. */
.app-card__link:focus-visible {
  outline-offset: -3px;
}

.app-card__logo {
  position: absolute;
  top: 1.25rem;
  left: 1.25rem;
  z-index: 2;
  width: 5rem;
  height: 5rem;
  padding: 0.25rem;
  border-radius: 0.75rem;
  background: var(--color-logo-backdrop);
  box-shadow: var(--shadow-app-logo);
  object-fit: contain;
}

/* Fixed height + cover/top crops the phone like the old clipping wrapper did. */
.app-card__mockup {
  position: absolute;
  top: 3.4375rem;
  left: -40%;
  z-index: 1;
  width: 180%;
  max-width: none;
  height: calc(100% - 3.4375rem - 5rem);
  object-fit: cover;
  object-position: top;
}

.app-card[data-mockup="laptop"] .app-card__mockup {
  left: 10%;
  width: 80%;
  object-fit: contain;
  object-position: center;
  transform: scale(0.9);
}

.app-card__description {
  position: absolute;
  right: 1.25rem;
  bottom: 3rem;
  left: 1.25rem;
  z-index: 3;
  padding-top: 0.5rem;
  background: inherit;
  color: color-mix(in srgb, currentColor 85%, transparent);
  font-size: var(--font-size-sm);
  line-height: calc(1.25 / 0.875);
}

.app-card__url {
  position: absolute;
  bottom: 1rem;
  left: 1.25rem;
  z-index: 3;
  font-family: var(--font-mono-system);
  font-size: var(--font-size-xs);
  opacity: var(--opacity-card-url);
}

/* 0.55 falls below 4.5:1 on the purple card. */
.app-card:nth-child(3n + 2) .app-card__url {
  opacity: var(--opacity-card-url-on-accent-alt);
}

/* ===== #localize ===== */
.localize {
  --color-focus: var(--color-focus-inverse);

  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4rem;
  padding: var(--space-section-y) var(--space-page-x);
  background: var(--color-surface-brand);
  color: var(--color-text-inverse);
}

.localize__title {
  font-family: var(--font-mono);
  font-size: clamp(2rem, 6vw, 4.5rem);
  font-weight: 700;
  line-height: 1.25;
}

.localize__title span {
  display: block;
}

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

.localize__sub {
  max-width: 36rem;
  margin-top: 1.5rem;
  color: var(--color-text-inverse-soft);
  font-size: var(--font-size-lg);
  line-height: calc(1.75 / 1.125);
}

/* Wrapping keeps the three stats from overflowing narrow screens (the old site clipped "Direct" at 360px). */
.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem 3rem;
  margin-top: 4rem;
}

.stats__item {
  display: flex;
  flex-direction: column;
}

.stats__value {
  color: var(--color-accent);
  font-size: var(--font-size-4xl);
  font-weight: 700;
  line-height: 2.5rem;
}

.stats__label {
  margin-top: 0.25rem;
  color: var(--color-text-inverse-muted);
  font-size: var(--font-size-sm);
  line-height: 1.25rem;
}

.services {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.services__title {
  margin-bottom: 1.5rem;
  color: var(--color-accent);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  line-height: 1rem;
  letter-spacing: 0.1em;
}

.services__item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding-block: 1rem;
  border-bottom: 1px solid var(--color-divider-inverse);
}

.services__name {
  font-size: var(--font-size-sm);
  line-height: 1.25rem;
}

.services__lang {
  flex-shrink: 0;
  color: var(--color-text-inverse-muted);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  line-height: 1rem;
}

/* Wrap + align-content centers the row vertically while both columns stretch to the same height. */
@media (min-width: 48rem) {
  .localize {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-content: center;
    padding-inline: var(--space-section-x);
  }

  .localize__main {
    flex: 0 1 calc((100% - 4rem) * 0.6);
  }

  /* The unwrapped stats row sets the column's minimum width, as in the old layout. */
  .stats {
    flex-wrap: nowrap;
  }

  /* Growing from 0 takes the space left by the main column, so the row never wraps. */
  .services {
    flex: 1 1 0;
    max-width: 20rem;
  }
}

@media (min-width: 72rem) {
  .localize__main {
    flex-basis: 60%;
  }
}

/* ===== #contact ===== */
.contact {
  --color-focus: var(--color-focus-inverse);

  position: relative;
  overflow: hidden;
  padding: 3rem 2rem 5rem;
  background: var(--color-surface-dark);
  color: var(--color-text-inverse);
}

.contact__main {
  max-width: 37.5rem;
}

.contact__title {
  margin-bottom: 3rem;
  font-size: clamp(2.25rem, 5vw, 4rem);
  font-weight: 800;
}

html:not(.js) .form {
  display: none;
}

.form__row {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 2.5rem;
}

.form__label {
  flex-shrink: 0;
  min-width: 17.5rem;
  font-size: clamp(1.125rem, 2.5vw, 1.75rem);
  font-weight: 700;
}

.form__input {
  flex: 1;
  width: 100%;
  padding: 0.5rem 0;
  border-bottom: 2px solid var(--color-input-border);
  color: var(--color-text-inverse);
  font-size: clamp(1rem, 2vw, 1.375rem);
  outline: none;
}

.form__input:focus-visible {
  border-bottom-color: var(--color-focus);
}

@media (min-width: 48rem) {
  .form__row {
    flex-direction: row;
    align-items: baseline;
  }

  .form__label {
    text-align: right;
  }
}

/* Off-screen rather than display:none so naive bots still see and fill it. */
.form__trap {
  position: absolute;
  top: 0;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.form__actions {
  display: flex;
  justify-content: flex-end;
}

.form__submit {
  padding: 0.75rem 2rem;
  background: var(--color-accent);
  color: var(--color-on-accent);
  font-weight: 700;
}

.form__submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.form__message {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  line-height: 1.25rem;
}

.form__message:not(:empty) {
  margin-top: 1.5rem;
}

.form__message--success {
  color: var(--color-accent);
}

.form__message--error {
  color: var(--color-error);
}

.form__noscript {
  font-size: var(--font-size-lg);
}

.contact__note {
  margin-top: 1rem;
  margin-bottom: 2rem;
  color: var(--color-text-inverse-muted);
  font-size: var(--font-size-xs);
  line-height: 1rem;
  text-align: right;
}

.contact__illustration {
  position: absolute;
  right: 2rem;
  bottom: 0;
  width: 5rem;
}

@media (min-width: 48rem) {
  .contact__illustration {
    width: 13.75rem;
  }
}
