:root {
  color-scheme: light;
  --bg: #f4f7f1;
  --panel: #ffffff;
  --ink: #24313f;
  --muted: #61707c;
  --line: #dce5df;
  --green: #2f7d68;
  --green-dark: #215f50;
  --blue: #2f6f9f;
  --yellow: #f2c14e;
  --coral: #dc735b;
  --purple: #7262a5;
  --shadow: 0 14px 32px rgb(36 49 63 / 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgb(47 125 104 / 0.12), transparent 32%),
    linear-gradient(315deg, rgb(242 193 78 / 0.2), transparent 36%),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px clamp(12px, 2.8vw, 28px) 24px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green-dark);
  font-size: clamp(0.9rem, 1.3vw, 1.02rem);
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.35rem);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: clamp(1.12rem, 2vw, 1.42rem);
  letter-spacing: 0;
}

.mode-switch,
.control-row,
.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mode-button,
.action-button,
.small-button,
.icon-button,
.preset-button {
  min-height: 48px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

.mode-button {
  min-width: 118px;
  padding: 0 18px;
}

.mode-button.is-active,
.action-button.primary {
  border-color: var(--green-dark);
  background: var(--green);
  color: #fff;
}

.action-button {
  min-width: 132px;
  padding: 0 20px;
  font-size: 1.04rem;
}

.action-button.success {
  border-color: #b98a12;
  background: var(--yellow);
  color: #35270b;
}

.small-button,
.icon-button {
  min-width: 48px;
  padding: 0 12px;
}

.screen {
  display: none;
}

.screen.is-active {
  display: grid;
}

#childScreen {
  grid-template-columns: minmax(320px, 0.82fr) minmax(360px, 1.18fr);
  gap: 14px;
  align-items: stretch;
}

.flow-list,
.current-panel,
.editor-panel {
  min-width: 0;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgb(255 255 255 / 0.96);
  box-shadow: var(--shadow);
}

.flow-list,
.editor-panel {
  padding: 16px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.progress-text {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
  white-space: nowrap;
}

.step-list {
  display: grid;
  gap: 9px;
}

.step-card {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 78px;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.step-card.is-current {
  border-color: var(--blue);
  background: #edf7ff;
}

.step-card.is-done {
  border-color: #88b59d;
  background: #edf8f1;
}

.step-card.is-empty {
  color: var(--muted);
  cursor: default;
}

.mini-icon {
  width: 48px;
  height: 48px;
}

.step-main {
  min-width: 0;
}

.step-title {
  display: block;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: clamp(1rem, 1.7vw, 1.22rem);
  font-weight: 900;
  line-height: 1.2;
}

.step-time {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
}

.step-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e7ece9;
  color: var(--muted);
  font-weight: 900;
}

.step-card.is-done .step-mark {
  background: var(--green);
  color: #fff;
}

.current-panel {
  display: grid;
  grid-template-rows: auto auto auto auto auto 1fr;
  justify-items: center;
  gap: 12px;
  padding: clamp(18px, 3vw, 30px);
  text-align: center;
}

.current-badge {
  min-width: 108px;
  padding: 8px 16px;
  border-radius: 999px;
  background: #eaf2ef;
  color: var(--green-dark);
  font-weight: 900;
}

.current-icon {
  width: min(31vw, 230px);
  max-width: 230px;
  aspect-ratio: 1;
}

.current-icon svg,
.mini-icon svg,
.preset-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

#currentTitle {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: clamp(2.15rem, 5.3vw, 4.4rem);
  line-height: 1.05;
}

.timer-text {
  font-variant-numeric: tabular-nums;
  color: var(--green-dark);
  font-size: clamp(3rem, 8.2vw, 6.7rem);
  font-weight: 950;
  line-height: 0.95;
}

.timer-bar {
  width: min(480px, 100%);
  height: 18px;
  overflow: hidden;
  border-radius: 999px;
  background: #e6ece9;
}

.timer-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--coral));
  transition: width 180ms linear;
}

.status-text {
  min-height: 2.8em;
  color: var(--muted);
  font-size: clamp(1rem, 1.6vw, 1.16rem);
  font-weight: 800;
  line-height: 1.4;
}

.control-row {
  align-self: end;
  justify-content: center;
}

#editScreen {
  grid-template-columns: minmax(300px, 0.82fr) minmax(420px, 1.18fr);
  gap: 14px;
}

.preset-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(132px, 1fr));
  gap: 9px;
}

.preset-button {
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: center;
  gap: 8px;
  min-height: 64px;
  padding: 8px 10px;
  text-align: left;
}

.preset-button:disabled {
  opacity: 0.42;
  cursor: default;
}

.preset-icon {
  width: 44px;
  height: 44px;
}

.preset-name {
  overflow-wrap: anywhere;
  font-weight: 900;
  line-height: 1.2;
}

.edit-list {
  display: grid;
  gap: 9px;
}

.edit-row {
  display: grid;
  grid-template-columns: 38px minmax(120px, 1fr) 112px 104px 96px;
  gap: 8px;
  align-items: center;
  min-height: 66px;
  padding: 9px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.row-number {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #eef3f0;
  color: var(--green-dark);
  font-weight: 900;
}

.edit-input {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  font-weight: 850;
}

.time-control,
.move-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.time-label {
  min-width: 34px;
  text-align: center;
  font-weight: 900;
}

.delete-button {
  color: #a33c2e;
}

.editor-actions {
  justify-content: flex-end;
  margin-top: 12px;
}

.icon-activity {
  --icon-bg: #dff0ec;
  --icon-main: #2f7d68;
  --icon-sub: #f2c14e;
}

.icon-rest {
  --icon-bg: #eaf1fb;
  --icon-main: #2f6f9f;
  --icon-sub: #9bd3e8;
}

.icon-talk {
  --icon-bg: #f1ebfa;
  --icon-main: #7262a5;
  --icon-sub: #f2c14e;
}

.icon-start,
.icon-end {
  --icon-bg: #fff2e5;
  --icon-main: #dc735b;
  --icon-sub: #f2c14e;
}

@media (max-width: 860px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .mode-button,
  .action-button {
    flex: 1 1 128px;
  }

  #childScreen,
  #editScreen {
    grid-template-columns: 1fr;
  }

  .current-panel {
    min-height: 560px;
  }

  .edit-row {
    grid-template-columns: 34px 1fr 104px;
  }

  .move-control,
  .delete-button {
    grid-column: 2 / span 2;
    justify-self: end;
  }

  .preset-list {
    grid-template-columns: repeat(2, minmax(128px, 1fr));
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding-inline: 10px;
  }

  .preset-list {
    grid-template-columns: 1fr;
  }

  .step-card {
    grid-template-columns: 44px 1fr 36px;
  }

  .mini-icon {
    width: 44px;
    height: 44px;
  }

  .edit-row {
    grid-template-columns: 32px 1fr;
  }

  .time-control,
  .move-control,
  .delete-button {
    grid-column: 2;
    justify-self: stretch;
  }
}

/* LiNest v3: 活動種別・現在・完了の教材色を保ち、外枠を統一する。 */
body.linest-themed {
  --bg: var(--linest-bg);
  --panel: var(--linest-surface);
  --ink: var(--linest-text);
  --muted: var(--linest-muted);
  --line: var(--linest-border);
  --green: var(--linest-green);
  --green-dark: var(--linest-green-dark);
  --shadow: var(--linest-shadow);
}

body.linest-themed .app-header {
  padding: 16px 18px;
  border: 1px solid var(--linest-border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--linest-shadow);
}

body.linest-themed :where(.flow-list, .current-panel, .editor-panel) {
  border-color: var(--linest-border);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--linest-shadow);
}

body.linest-themed :where(.mode-button, .action-button, .small-button, .icon-button, .preset-button, .step-card, .edit-row, .edit-input) {
  border-color: var(--linest-border);
  background-color: #ffffff;
  color: var(--linest-text);
}

body.linest-themed .mode-button.is-active {
  border-color: var(--linest-green);
  background: var(--linest-green);
  color: #ffffff;
}

@media (max-width: 560px) {
  body.linest-themed :where(.mode-button, .action-button, .small-button, .icon-button, .preset-button) {
    min-width: 0;
    padding-inline: 8px;
    white-space: normal;
    word-break: keep-all;
  }

  body.linest-themed .mode-switch,
  body.linest-themed .control-row,
  body.linest-themed .editor-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }
}
