/* ---------- Reset ---------- */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ---------- Theme Variables ---------- */

:root {
  --bg: #EFEAE4;
  --card-bg: #F8F5F1;
  --modal-bg: #F4EFE9;

  --text-main: #3A3633;
  --text-soft: #5F5852;
  --display-text: #4A443E;

  --border-soft: #E0E4E7;
  --divider-soft: rgba(122, 111, 102, 0.2);

  --button-bg: #E6DED6;
  --button-hover: #D7CCC2;
  --button-active: #9F9489;

  --slider-fill: #7A6F66;
  --slider-track: #E4DED8;
  --slider-thumb: #8C8176;

  --focus-ring: rgba(159, 148, 137, 0.25);

  --shadow-soft: 0 10px 25px rgba(0, 0, 0, 0.05);
  --shadow-medium: 0 6px 18px rgba(0, 0, 0, 0.1);
  --shadow-strong: 0 20px 60px rgba(0, 0, 0, 0.15);
}

body.theme-blue {
  --bg: #E6EEF5;
  --card-bg: #F4F8FC;
  --modal-bg: #F4F8FC;

  --text-main: #25313B;
  --text-soft: #5B6770;
  --display-text: #44515B;

  --border-soft: #D7E2EC;
  --divider-soft: rgba(90, 120, 150, 0.18);

  --button-bg: #E3EBF2;
  --button-hover: #D2DFEA;
  --button-active: #97AFC2;

  --slider-fill: #70879A;
  --slider-track: #D5E1EA;
  --slider-thumb: #7E8D98;

  --focus-ring: rgba(120, 150, 180, 0.25);
}

body.theme-green {
  --bg: #E7F0E8;
  --card-bg: #F4F8F4;
  --modal-bg: #F4F8F4;

  --text-main: #263129;
  --text-soft: #59665C;
  --display-text: #465248;

  --border-soft: #D7E2D8;
  --divider-soft: rgba(90, 120, 100, 0.18);

  --button-bg: #E5EEE6;
  --button-hover: #D5E2D6;
  --button-active: #95AA98;

  --slider-fill: #738876;
  --slider-track: #D6E2D7;
  --slider-thumb: #7E8A80;

  --focus-ring: rgba(120, 150, 120, 0.25);
}

/* ---------- Base Page ---------- */

body {
  min-height: 100vh;
  padding: 20px;

  display: flex;
  flex-direction: column;
  align-items: center;

  font-family: "Be Vietnam Pro", sans-serif;
  font-size: 19px;
  line-height: 2;
  letter-spacing: 0.2px;

  background: var(--bg);
  color: var(--text-main);
}

body,
.card,
textarea,
.controls button,
.theme-button,
.info-button,
.info-modal,
.close-info {
  transition:
    background-color 0.3s ease,
    color 0.3s ease,
    border-color 0.3s ease;
}

body.modal-open {
  overflow: hidden;
}

/* ---------- Hero ---------- */

.hero {
  margin-top: 0;
  margin-bottom: 22px;

  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;

  text-align: center;
}

.site-logo {
  width: 170px;
  height: auto;

  display: block;
  margin: 0 auto -10px;
}

h1 {
  margin: 0;

  font-size: 40px;
  font-weight: 600;
  line-height: 1;
}

.subtitle {
  margin-top: 25px;

  font-size: 16px;
  opacity: 0.65;
}

/* ---------- Main Card ---------- */

.card {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 30px 40px 35px;

  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: var(--shadow-soft);
}

/* ---------- Text Editor ---------- */

textarea {
  width: 100%;
  max-width: 65ch;
  height: 200px;
  margin-bottom: 12px;
  padding: 18px;

  resize: none;

  font-family: inherit;
  font-size: 17px;
  line-height: 1.7;

  color: var(--text-main);
  background: #FFFFFF;

  border: 1px solid var(--border-soft);
  border-radius: 10px;
}

textarea:focus {
  outline: none;
  border-color: var(--border-soft);
  box-shadow: none;
}

/* ---------- Mode Buttons ---------- */

.controls {
  margin-bottom: 20px;
}

.controls button {
  margin-right: 8px;
  padding: 7px 16px;

  border: none;
  border-radius: 9px;

  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.1px;

  color: var(--text-main);
  background: var(--button-bg);

  cursor: pointer;

  transition:
    background 0.2s ease,
    transform 0.15s ease;
}

.controls button:hover:not(.active) {
  background: var(--button-hover);
}

.controls button.active {
  background: var(--button-active);
  color: var(--text-main);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.controls button:focus-visible,
.theme-button:focus-visible,
.info-button:focus-visible,
.close-info:focus-visible,
input[type="range"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

/* ---------- Rhythm Slider ---------- */

.slider-container {
  margin-bottom: 35px;

  display: flex;
  flex-direction: column;
  align-items: center;
}

.slider-container label {
  margin-bottom: 12px;

  font-size: 19px;
  font-weight: 600;

  color: var(--display-text);
}

input[type="range"] {
  width: 320px;
  height: 6px;

  appearance: none;
  border-radius: 10px;
  outline: none;

  background: linear-gradient(
    to right,
    var(--slider-fill) 0%,
    var(--slider-fill) 0%,
    var(--slider-track) 0%,
    var(--slider-track) 100%
  );

  transition: background 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb {
  width: 18px;
  height: 18px;

  appearance: none;
  border: none;
  border-radius: 50%;

  background: var(--slider-thumb);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;

  border: none;
  border-radius: 50%;

  background: var(--slider-thumb);
  cursor: pointer;
}

#speedValue {
  margin: 8px 0;

  font-size: 15px;
  font-weight: 500;
}

.thresholds {
  width: 320px;
  margin-top: 12px;

  display: flex;
  justify-content: space-between;

  font-size: 15px;
  color: var(--text-soft);
  opacity: 0.9;
}

.thresholds span {
  flex: 1;
  text-align: center;
}

.thresholds span:first-child {
  text-align: left;
}

.thresholds span:last-child {
  text-align: right;
}

/* ---------- Reading Display ---------- */

#display {
  max-width: 65ch;
  margin-top: 25px;
  padding-top: 20px;

  text-align: left;

  font-size: 16px;
  line-height: 1.8;
  letter-spacing: 0.5px;

  color: var(--display-text);
  border-top: 1px solid var(--divider-soft);

  transition:
    opacity 280ms cubic-bezier(0.22, 0.61, 0.36, 1),
    transform 320ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

#display p {
  margin-bottom: 20px;
}

#display > *:last-child {
  margin-bottom: 0 !important;
}

#display strong {
  font-weight: 600;
  color: var(--text-main);
  letter-spacing: 0.3px;
}

/* ---------- Mode: Steady Flow ---------- */

.mode-flow {
  --flow-line-height: 2;
  --flow-width: 65ch;
  --flow-opacity: 0.72;

  max-width: var(--flow-width);
  line-height: var(--flow-line-height);

  color: var(--text-soft);

  transition:
    line-height 260ms ease,
    max-width 320ms ease;
}

#display.mode-flow p {
  margin-bottom: 34px;

  opacity: var(--flow-opacity, 0.7);

  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  
  transition:
    opacity 220ms ease,
    color 220ms ease,
    transform 220ms ease;
}

#display.mode-flow p.active-focus {
  opacity: 1;
  color: var(--text-main);
  transform: translateX(1px);
}

/* ---------- Mode: Gentle Emphasis ---------- */

.mode-emphasis {
  max-width: 62ch;

  line-height: 1.8;
  word-spacing: 0;
  letter-spacing: 0;

  color: var(--text-main);
}

.mode-emphasis p {
  margin-bottom: 12px;
}

.mode-emphasis strong {
  font-weight: 700;
  color: var(--text-main);

  transition:
    font-weight 220ms ease,
    color 220ms ease;
}

/* ---------- Mode: Soft Breaks ---------- */

.chunk {
  display: inline-block;
  margin-right: var(--chunk-gap);
}

.mode-chunk-level3 .chunk:last-child {
  margin-bottom: 40px;
}

.mode-chunk-level3 {
  max-width: 55ch;
  line-height: 2.2;
  transition: none;
}

.mode-chunk-level3 .chunk {
  display: block;
  margin-bottom: 10px;
  padding-left: 6px;
  transition: none;
}

/* ---------- Floating Controls ---------- */

.floating-controls {
  position: fixed;
  right: 28px;
  bottom: 28px;
  z-index: 1000;

  display: flex;
  gap: 12px;
}

.theme-button,
.info-button {
  width: 46px;
  height: 46px;

  display: flex;
  align-items: center;
  justify-content: center;

  border: none;
  border-radius: 50%;

  color: var(--card-bg);
  background: var(--button-active);

  cursor: pointer;
  box-shadow: var(--shadow-medium);

  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;

  transition:
    transform 0.2s ease,
    background 0.2s ease;
}

@media (hover: hover) {
  .theme-button:hover,
  .info-button:hover {
    transform: scale(1.08);
    background: var(--button-hover);
  }
}

.theme-button {
  font-size: 22px;
}

.info-button {
  font-family: Georgia, serif;
  font-size: 21px;
  font-style: italic;
  font-weight: 700;
  line-height: 1;
}

/* ---------- Info Modal ---------- */

.info-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;

  display: flex;
  align-items: center;
  justify-content: center;

  background: rgba(0, 0, 0, 0.25);

  opacity: 0;
  visibility: hidden;

  transition:
    opacity 260ms ease,
    visibility 260ms ease;
}

.info-overlay.active {
  opacity: 1;
  visibility: visible;
}

.info-modal {
  position: relative;

  width: 480px;
  max-width: 90%;
  padding: 40px 36px;

  display: flex;
  flex-direction: column;
  align-items: center;

  overflow: hidden;

  background: var(--modal-bg);
  border-radius: 24px;
  box-shadow: var(--shadow-strong);

  opacity: 0;
  transform: translateY(10px) scale(0.98);

  transition:
    transform 320ms cubic-bezier(0.22, 0.61, 0.36, 1),
    opacity 280ms ease;
}

.info-overlay.active .info-modal {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.close-info {
  position: absolute;
  top: 20px;
  right: 20px;

  width: 34px;
  height: 34px;
  padding: 0;

  display: flex;
  align-items: center;
  justify-content: center;

  border: none;
  border-radius: 50%;

  font-size: 18px;
  font-weight: 600;
  line-height: 0;

  color: var(--text-main);
  background: var(--button-bg);

  cursor: pointer;
}

.close-info:hover {
  background: var(--button-hover);
}

.info-modal-content {
  width: 100%;
  max-width: 40ch;
  max-height: 70vh;
  margin: 0 auto;
  padding: 6px;

  overflow-y: auto;

  font-size: 16px;
  line-height: 1.95;

  text-wrap: pretty;
  scrollbar-width: none;
  scrollbar-color: rgba(58, 54, 50, 0.25) transparent;
}

.info-modal-content::-webkit-scrollbar {
  width: 8px;
}

.info-modal-content::-webkit-scrollbar-track {
  background: transparent;
}

.info-modal-content::-webkit-scrollbar-thumb {
  background: rgba(122, 111, 102, 0.35);
  border-radius: 10px;
  transition: background 0.3s ease;
}

.info-modal-content:hover::-webkit-scrollbar-thumb {
  background: rgba(58, 54, 50, 0.25);
}

.info-modal-content:hover {
  scrollbar-color: rgba(58, 54, 50, 0.25) transparent;
}

.info-modal-content h2,
.info-modal-content h3 {
  text-align: center;
}

.info-modal-content h2 {
  margin-bottom: 22px;

  font-size: 26px;
  font-weight: 600;
}

.info-modal-content h3 {
  margin-top: 32px;
  margin-bottom: 16px;

  font-size: 23px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.info-modal-content p {
  margin-bottom: 18px;
  text-wrap: balance;
}

/* ---------- Footer ---------- */

.footer {
  margin-top: 40px;

  text-align: center;
  font-size: 14px;
  opacity: 0.6;
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  body {
    padding: 18px;
  }

  .site-logo {
    width: 145px;
  }

  h1 {
    font-size: 32px;
  }

  .subtitle {
    margin-top: 18px;
    font-size: 15px;
  }

  .card {
    padding: 26px 22px 30px;
  }

  textarea {
    height: 180px;
    font-size: 16px;
  }

  .controls {
    display: flex;
    flex-direction: column;
    gap: 9px;
  }

  .controls button {
    width: 100%;
    margin-right: 0;
  }

  input[type="range"],
  .thresholds {
    width: 100%;
  }

  .floating-controls {
    right: 20px;
    bottom: 20px;
  }

  .info-modal {
    padding: 38px 24px 30px;
  }
}

/* ---------- Reduced Motion ---------- */

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
