:root {
  --bg: #f6f8fb;
  --bg-2: #eef3f9;
  --panel: #ffffff;
  --panel-border: #d8e2ee;
  --text: #1f2a37;
  --muted: #5f6f82;
  --accent: #4f8cff;
  --accent-2: #76a9ff;
  --shadow: 0 10px 30px rgba(88, 118, 160, 0.14);

  --viewer-font-size: 42px;
  --viewer-line-height: 1.6;
  --safe-width: 980px;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
    "Yu Gothic", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  min-height: 100vh;
  width: 100%;
}

.app-header {
  width: min(var(--safe-width), calc(100% - 24px));
  margin: 0 auto;
  padding: 20px 0 12px;
}

.app-header h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.tagline {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.tabs {
  width: min(var(--safe-width), calc(100% - 24px));
  margin: 0 auto 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.tab-button {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  border-radius: 14px;
  padding: 16px 12px;
  font-weight: 700;
  box-shadow: var(--shadow);
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.tab-button:hover {
  transform: translateY(-1px);
}

.tab-button.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #ffffff;
}

.tab-panels {
  width: min(var(--safe-width), calc(100% - 24px));
  margin: 0 auto;
  padding-bottom: 24px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.time-input label,
.script-input label {
  display: block;
  font-weight: 700;
  margin-bottom: 10px;
}

.time-adjust {
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.adjust-btn {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  border-radius: 14px;
  height: 56px;
  font-size: 28px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.time-display {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 56px;
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  background: #f9fbfe;
  box-shadow: var(--shadow);
}

#durationPreview {
  display: inline-block;
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
}

#durationRange {
  width: 100%;
  margin: 6px 0 4px;
}

.range-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 20px;
}

#script {
  width: 100%;
  min-height: 52vh;
  border-radius: 16px;
  border: 1px solid var(--panel-border);
  background: #f9fbfe;
  color: var(--text);
  padding: 16px;
  line-height: 1.8;
  resize: vertical;
  outline: none;
}

#script:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(79, 140, 255, 0.14);
}

.viewer-meta {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.viewer-time-label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

.viewer-time-value {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.4;
  word-break: break-word;
}

.viewer-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.viewer-controls button {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

#play {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #ffffff;
}

#stage {
  position: relative;
  height: calc(100vh - 280px);
  min-height: 460px;
  overflow: hidden;
  border-radius: 22px;
  border: 1px solid var(--panel-border);
  background: linear-gradient(180deg, #ffffff 0%, #f7faff 100%);
  box-shadow: var(--shadow);
}

.center-highlight {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: calc(var(--viewer-font-size) * var(--viewer-line-height));
  background: linear-gradient(
    180deg,
    rgba(79, 140, 255, 0.06),
    rgba(79, 140, 255, 0.18),
    rgba(79, 140, 255, 0.06)
  );
  border-top: 1px solid rgba(79, 140, 255, 0.28);
  border-bottom: 1px solid rgba(79, 140, 255, 0.28);
  pointer-events: none;
  z-index: 1;
}

#track {
  position: absolute;
  left: 0;
  right: 0;
  padding-left: 6vw;
  padding-right: 6vw;
  will-change: transform;
  z-index: 2;
}

.roll-line {
  margin: 0;
  padding: 0;
  font-size: var(--viewer-font-size);
  line-height: var(--viewer-line-height);
  color: #2a3645;
  white-space: pre-wrap;
  word-break: break-word;
}

.roll-line.empty::before {
  content: " ";
  white-space: pre;
}

#stage:fullscreen {
  width: 100vw;
  height: 100vh;
  border-radius: 0;
  border: none;
}

#stage:fullscreen #track {
  padding-left: 8vw;
  padding-right: 8vw;
}

@media (orientation: landscape) and (max-width: 950px) {
  .app-header {
    padding: 10px 0 8px;
  }

  .app-header h1 {
    font-size: 24px;
  }

  .tagline {
    font-size: 12px;
    margin-top: 4px;
  }

  .tabs {
    margin-bottom: 10px;
    gap: 8px;
  }

  .tab-button {
    padding: 12px 10px;
  }

  .viewer-meta {
    padding: 10px 14px;
    margin-bottom: 8px;
  }

  .viewer-time-value {
    font-size: 18px;
  }

  .viewer-controls {
    margin-bottom: 8px;
    gap: 8px;
  }

  .viewer-controls button {
    padding: 10px 14px;
  }

  #stage {
    height: calc(100vh - 160px);
    min-height: 0;
  }

  :root {
    --viewer-font-size: 28px;
    --viewer-line-height: 1.55;
  }
}

@media (max-width: 768px) {
  :root {
    --viewer-font-size: 32px;
  }

  .app-header h1 {
    font-size: 28px;
  }

  .viewer-time-value {
    font-size: 22px;
  }

  #stage {
    height: calc(100vh - 300px);
    min-height: 420px;
  }
}

@media (max-width: 520px) {
  :root {
    --viewer-font-size: 28px;
  }

  .tab-button {
    padding: 14px 10px;
  }

  .time-adjust {
    grid-template-columns: 52px 1fr 52px;
  }

  .adjust-btn {
    height: 52px;
    font-size: 26px;
  }

  .viewer-controls button {
    width: 100%;
  }

  .viewer-time-value {
    font-size: 20px;
  }
}