:root {
  color-scheme: light;
  --bg: #f8f7f3;
  --panel: #ffffff;
  --text: #1f2528;
  --muted: #697176;
  --line: #d8d3c8;
  --accent: #1f6f78;
  --accent-pressed: #185c63;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  -webkit-text-size-adjust: 100%;
}

button,
input,
textarea,
.input-editor {
  font: inherit;
}

.app {
  position: fixed;
  top: var(--app-top, 0px);
  right: 0;
  bottom: auto;
  left: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  width: 100%;
  max-width: 620px;
  height: var(--app-height, 100svh);
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 12px var(--app-bottom-padding, calc(8px + env(safe-area-inset-bottom)));
  overflow: hidden;
}

@supports (height: 100dvh) {
  .app {
    height: var(--app-height, 100dvh);
  }
}

.toolbar {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.toolbar-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

h1 {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
}

button,
.settings-panel summary {
  flex: 0 0 auto;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  background: var(--accent);
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
}

button:active {
  background: var(--accent-pressed);
}

button:disabled {
  opacity: 0.45;
}

.secondary-button,
.settings-panel summary {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
}

.secondary-button:active,
.settings-panel summary:active {
  background: #eeeeea;
}

.settings-panel {
  position: relative;
}

.settings-panel summary {
  display: flex;
  align-items: center;
  list-style: none;
}

.settings-panel summary::-webkit-details-marker {
  display: none;
}

.settings-body {
  position: fixed;
  top: calc(var(--app-top, 0px) + 62px + env(safe-area-inset-top));
  right: 12px;
  left: 12px;
  z-index: 4;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px 10px;
  max-width: 596px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #ffffff;
  box-shadow: 0 12px 28px rgba(31, 37, 40, 0.16);
}

.settings-body label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.settings-body input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
  color: var(--text);
  background: #ffffff;
  font-size: 15px;
}

.settings-body input:focus {
  border-color: var(--accent);
}

.api-key-row {
  display: flex;
  gap: 8px;
}

.api-key-row input {
  min-width: 0;
}

.api-key-row button {
  min-height: 40px;
  padding: 0 12px;
  font-size: 13px;
}

.settings-status {
  grid-column: 2;
  min-height: 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.output-panel,
.input-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.output-panel {
  min-height: calc(5 * 1.75em + 42px);
}

.output-panel.is-editing {
  border-color: var(--accent);
  background: #fbfffd;
  box-shadow: inset 0 0 0 1px rgba(31, 111, 120, 0.28);
}

.input-panel {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(31, 37, 40, 0.08);
}

.input-panel.is-disabled {
  opacity: 0.58;
}

.panel-label {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
  padding: 8px 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.output-text {
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15.25px;
  line-height: 1.75;
  -webkit-overflow-scrolling: touch;
}

.output-text[contenteditable="true"] {
  outline: none;
  caret-color: var(--accent);
  -webkit-user-select: text;
  user-select: text;
}

.insert-marker {
  color: #d02626;
  font-weight: 700;
}

.output-text:empty::before {
  content: "句読点まで入力した文章がここに表示されます。";
  color: #9a9a9a;
}

.input-row {
  display: flex;
  min-height: 44px;
  align-items: center;
}

.input-editor {
  flex: 1 1 auto;
  width: 100%;
  min-height: 44px;
  max-height: 78px;
  border: 0;
  padding: 9px 12px;
  resize: none;
  outline: none;
  color: var(--text);
  background: transparent;
  font-size: 17px;
  line-height: 1.55;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  cursor: text;
  -webkit-user-select: text;
  user-select: text;
}

.input-editor[contenteditable="false"] {
  cursor: default;
}

.input-editor:focus {
  outline: none;
}

.status-text {
  flex: 0 0 auto;
  max-width: 84px;
  padding-right: 12px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-text:empty {
  display: none;
}

.notice-text {
  flex: 0 0 auto;
  max-width: 112px;
  padding-right: 12px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notice-text:empty {
  display: none;
}

.input-editor:empty::before {
  content: attr(data-placeholder);
  color: #9a9a9a;
}

@media (min-width: 640px) {
  .app {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }
}

@media (max-width: 380px) {
  .toolbar {
    gap: 6px;
  }

  .toolbar-actions {
    gap: 5px;
  }

  h1 {
    font-size: 15px;
  }

  button,
  .settings-panel summary {
    padding: 0 9px;
    font-size: 13px;
  }
}

@media (max-width: 430px) {
  h1 {
    font-size: 14px;
  }

  button,
  .settings-panel summary {
    padding: 0 7px;
    font-size: 12px;
  }
}
