﻿:root {
  --bg: #eef3f8;
  --panel: #ffffff;
  --line: #ccd9e7;
  --text: #1e2832;
  --accent: #2f4f73;
  --muted: #5b6a7a;
  --danger: #b24949;
  --bottom-safe: 0px;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Noto Sans JP", sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #e6edf5 0%, var(--bg) 35%);
  height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

.app {
  height: 100dvh;
  min-height: 100vh;
  max-width: 1800px;
  margin: 0 auto;
  padding: 12px 12px calc(2px + var(--bottom-safe));
  display: grid;
  gap: 10px;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.header {
  position: sticky;
  top: 0;
  z-index: 300;
  background: #f3f8fd;
  display: grid;
  gap: 6px;
}

h1,
h2 {
  margin: 0 0 8px;
}

h1 {
  font-size: 1.4rem;
}

h2 {
  font-size: 1rem;
}

.timer-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.header-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(148px, 220px);
  align-items: center;
  gap: 8px;
}

.header-brand {
  display: grid;
  gap: 2px;
  align-content: start;
}

.timer-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  background: #f8fcff;
}

.timer-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.timer-display {
  margin-top: 0;
  font-family: Consolas, "Courier New", monospace;
  font-size: 1.18rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  line-height: 1;
}

.timer-display.done {
  color: #b24949;
}

.timer-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
}

.timer-actions button {
  padding: 5px 4px;
  font-size: 0.74rem;
}

.scramble-box {
  display: grid;
  gap: 4px;
}

.scramble-box label {
  font-size: 0.82rem;
  color: var(--muted);
}

.scramble-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: end;
}

.scramble-row textarea {
  width: 100%;
  min-height: 48px;
  resize: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow-y: hidden;
  font-size: 1.08rem;
  line-height: 1.35;
  font-weight: 700;
  padding: 8px 10px;
}

.scramble-row textarea.display-mode {
  font-size: 1.16rem;
  line-height: 1.4;
  background: #f3f8ff;
}

.header-bottom {
  display: block;
}

.phase {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.help-link-btn {
  margin-top: 2px;
  justify-self: start;
  padding: 0;
  border: 0;
  background: transparent;
  color: #1f5f98;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.help-modal {
  position: fixed;
  inset: 0;
  z-index: 2200;
}

.help-modal[hidden] {
  display: none;
}

.help-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 20, 34, 0.45);
}

.help-modal-panel {
  position: absolute;
  inset: 5vh 5vw;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.help-modal-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #f4f8fc;
}

.help-modal-header h2 {
  margin: 0;
}

.help-close-btn {
  padding: 6px 10px;
}

.help-modal-body {
  padding: 12px;
  overflow: auto;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.help-modal-body article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfdff;
}

.help-modal-body h3 {
  margin: 0 0 8px;
}

.help-modal-body p {
  margin: 8px 0 4px;
  font-size: 0.9rem;
  color: var(--muted);
}

.help-modal-body ul {
  margin: 0;
  padding-left: 18px;
  line-height: 1.5;
  font-size: 0.9rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 10px;
  min-height: 0;
}

.left-side,
.right-side {
  display: grid;
  gap: 10px;
}

.left-side {
  overflow-y: auto;
  min-height: 0;
  padding-right: 4px;
  padding-bottom: calc(1px + var(--bottom-safe));
}

.right-side {
  max-height: 100%;
  overflow-y: auto;
  min-height: 0;
  padding-bottom: calc(1px + var(--bottom-safe));
}

.memo-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

textarea,
input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.92rem;
  background: #fafdff;
  touch-action: manipulation;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 76px;
  line-height: 1.35;
  caret-color: #1d4f85;
}

textarea.active-target {
  outline: 2px solid #6aa3da;
  outline-offset: 0;
  background: transparent;
}

.memo-input-wrap {
  position: relative;
}

.memo-input-wrap .indent-bg {
  position: absolute;
  inset: 1px;
  border-radius: 7px;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
  background: #fafdff;
}

.memo-input-wrap .indent-bg-content {
  position: absolute;
  inset: 0;
}

.memo-input-wrap .indent-row {
  height: var(--memo-line-height, 1.3em);
  width: 100%;
}

.memo-input-wrap .indent-row.no-color {
  background: transparent;
}

.memo-input-wrap .indent-row.step-0 {
  background: rgba(36, 123, 255, 0.08);
}

.memo-input-wrap .indent-row.step-1 {
  background: rgba(19, 173, 122, 0.09);
}

.memo-input-wrap .indent-row.step-2 {
  background: rgba(255, 170, 20, 0.09);
}

.memo-input-wrap .indent-row.step-3 {
  background: rgba(255, 92, 57, 0.1);
}

.memo-input-wrap .indent-row.step-4 {
  background: rgba(214, 67, 107, 0.1);
}

.memo-input-wrap .indent-row.step-5 {
  background: rgba(123, 92, 255, 0.1);
}

.memo-input-wrap textarea {
  position: relative;
  z-index: 1;
  background: transparent;
}

.memo-input-wrap .syntax-overlay {
  position: absolute;
  inset: 1px;
  border-radius: 7px;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}

.memo-input-wrap .syntax-overlay-content {
  position: absolute;
  inset: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
}

.memo-input-wrap .syntax-line {
  min-height: var(--memo-line-height, 1.3em);
}

.memo-input-wrap .slice-move-token {
  color: #0d8e68;
  font-weight: 700;
}

.memo-input-wrap .slice-comment-text {
  color: #67788a;
}

.memo-input-wrap textarea.syntax-overlay-source {
  z-index: 2;
  color: transparent;
  -webkit-text-fill-color: transparent;
}

.fake-caret {
  position: absolute;
  width: 2px;
  background: #1d4f85;
  pointer-events: none;
  z-index: 3;
  animation: caret-blink 1s step-end infinite;
}

@keyframes caret-blink {
  0%,
  45% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

.check-row {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.comment-bar {
  position: fixed;
  left: 0;
  top: 0;
  width: 160px;
  z-index: 1600;
}

.comment-bar[hidden] {
  display: none;
}

.comment-bar-inner {
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  backdrop-filter: none;
}

.comment-bar-inner label {
  display: none;
}

.comment-bar-row {
  display: block;
}

#commentInput {
  width: 100%;
  font-size: 16px;
  line-height: 1.35;
  background: transparent;
  border: 0;
  padding: 0;
  color: transparent;
  caret-color: transparent;
  outline: none;
  box-shadow: none;
}

#commentInput::selection {
  background: transparent;
}

#commentDoneBtn {
  display: none;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 8px 10px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

button.help-link-btn {
  margin-top: 2px;
  justify-self: start;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #1f5f98;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: underline;
  cursor: pointer;
}

button.danger {
  background: var(--danger);
}

.notation-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.note-btn {
  min-height: 38px;
}

.control-list {
  display: grid;
  gap: 6px;
}

.controls-layout {
  display: grid;
  grid-template-columns: minmax(96px, 104px) minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.data-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.recon-actions {
  margin-top: 8px;
  display: grid;
  gap: 6px;
}

.scramble-diagram-panel {
  padding-top: 7px;
}

.scramble-diagram-panel h2 {
  margin-bottom: 4px;
  line-height: 1.15;
}

.arrow-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 0;
}

.arrow-pad button:nth-child(1) {
  grid-column: 2;
}

.arrow-pad button:nth-child(2) {
  grid-column: 1;
}

.arrow-pad button:nth-child(3) {
  grid-column: 2;
}

.arrow-pad button:nth-child(4) {
  grid-column: 3;
}

#cubeCanvas {
  width: 100%;
  max-width: 350px;
  height: auto;
  display: block;
  background: #f5f8fc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.face-u {
  background: #ffffff;
  color: #222;
  border: 1px solid #d9d9d9;
}

.face-l {
  background: #ffa500;
  color: #222;
}

.face-f {
  background: #00c853;
  color: #222;
}

.face-r {
  background: #e53935;
}

.face-b {
  background: #1e40af;
}

.face-d {
  background: #ffeb3b;
  color: #222;
}

@media (min-width: 1024px) {
  .memo-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .app {
    padding: 6px 6px calc(1px + var(--bottom-safe));
    gap: 6px;
  }

  .panel {
    padding: 6px;
    border-radius: 8px;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr) minmax(240px, 44vw);
    gap: 6px;
  }

  .header {
    gap: 4px;
  }

  .header-top {
    grid-template-columns: minmax(0, 1fr) minmax(114px, 150px);
    gap: 6px;
  }

  .header-brand {
    gap: 1px;
  }

  .timer-box {
    padding: 4px 5px;
  }

  .timer-label {
    font-size: 0.68rem;
  }

  .timer-display {
    font-size: 0.92rem;
    letter-spacing: 0.5px;
  }

  .timer-row {
    gap: 4px;
  }

  .timer-actions button {
    padding: 4px 3px;
    font-size: 0.66rem;
  }

  .scramble-row {
    gap: 4px;
  }

  .scramble-row input,
  .scramble-row textarea,
  .scramble-row button {
    padding: 5px 6px;
    font-size: 0.8rem;
  }

  .scramble-row textarea {
    min-height: 40px;
    font-size: 0.9rem;
    line-height: 1.3;
  }

  .scramble-row textarea.display-mode {
    font-size: 0.98rem;
  }

  .phase {
    font-size: 0.82rem;
  }

  .right-side {
    gap: 6px;
  }

  .right-side h2 {
    margin-bottom: 4px;
    font-size: 0.88rem;
  }

  .controls-layout {
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 6px;
  }

  .data-actions {
    gap: 4px;
    margin-top: 6px;
  }

  .note-btn {
    min-height: 30px;
    padding: 4px 5px;
    font-size: 0.8rem;
  }

  .arrow-pad {
    margin-bottom: 4px;
    gap: 4px;
  }

  .arrow-pad button {
    padding: 5px 4px;
    font-size: 0.82rem;
  }

  .control-list {
    gap: 4px;
  }

  .control-list button {
    padding: 5px 6px;
    font-size: 0.8rem;
  }

  #cubeCanvas {
    max-width: 220px;
    margin: 0 auto;
  }

  .comment-bar {
    width: 140px;
  }

  .help-modal-panel {
    inset: 3vh 3vw;
  }

  .help-modal-body {
    grid-template-columns: 1fr;
    padding: 10px;
  }
}

@media (max-width: 600px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) minmax(190px, 42vw);
  }

  .header-top {
    grid-template-columns: minmax(0, 1fr) minmax(102px, 128px);
    gap: 5px;
  }

  .timer-box {
    padding: 3px 4px;
  }

  .timer-display {
    font-size: 0.82rem;
  }

  .timer-actions button {
    padding: 3px 2px;
    font-size: 0.62rem;
  }

  .header-bottom {
    gap: 6px;
  }

  #cubeCanvas {
    max-width: 180px;
  }
}

@media (orientation: portrait) and (max-width: 900px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) clamp(172px, 36vw, 280px);
  }

  .right-side {
    gap: 5px;
  }

  .panel.controls-panel {
    padding-bottom: 5px;
  }

  .notation-grid {
    gap: 4px;
  }

  .note-btn {
    min-height: 28px;
    padding: 4px 4px;
  }

  .controls-layout {
    grid-template-columns: 80px minmax(0, 1fr);
    gap: 5px;
  }

  .arrow-pad {
    gap: 3px;
  }

  .arrow-pad button {
    padding: 4px 2px;
  }

  .control-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
  }

  .data-actions button {
    padding: 4px 4px;
    font-size: 0.74rem;
  }

  #cubeCanvas {
    max-width: 100%;
    margin: 0;
  }
}

@media (orientation: portrait) and (max-width: 600px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) clamp(156px, 40vw, 220px);
  }

  .controls-layout {
    grid-template-columns: 74px minmax(0, 1fr);
  }

  .control-list button {
    padding: 4px 5px;
    font-size: 0.74rem;
  }

  .data-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .data-actions button:last-child {
    grid-column: 1 / -1;
  }

  #cubeCanvas {
    max-width: 100%;
  }
}

@media (display-mode: standalone) {
  :root {
    --bottom-safe: env(safe-area-inset-bottom, 0px);
  }
}

