/* Tutorial dimensions follow the game overlay, including the phone preview. */
.overlay:has(.tw) {
  padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}
html .modal:has(.tw) {
  width: min(1040px, 100%);
  max-width: 100%;
  height: min(540px, 100%);
  max-height: 100%;
  min-height: 0;
  padding: 14px 18px;
  border-radius: 20px;
  overflow: hidden;
}
html.phone-preview .modal:has(.tw) {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  padding: 10px 14px;
}
html .tutorial.tw {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 42px minmax(0, 1fr) 54px;
  gap: 8px;
  text-align: left;
}
.tw-header, .tw-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; }
.tw-header { border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.tw-progress { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; font-size: 14px; }
.tw-progress > span { color: var(--blue); font-weight: 800; }
.tw-progress-track { display: flex; gap: 4px; width: 84px; }
.tw-progress-track i { height: 4px; flex: 1; background: var(--line); border-radius: 4px; }
.tw-progress-track .done { background: var(--blue); }
.tw-skip, .tw-voice { background: transparent; min-height: 44px; padding: 8px 10px; font-size: 14px; font-weight: 700; white-space: nowrap; }
.tw-skip { color: var(--muted); }
.tw-voice { color: var(--blue); border: 1px solid var(--line); border-radius: 12px; background: #fffdf5; }
.tw-body { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 16px; min-height: 0; overflow: auto; overscroll-behavior: contain; align-items: stretch; }
.tw-coach { display: grid; grid-template-columns: 80px minmax(0, 1fr); gap: 12px; align-items: center; min-width: 0; }
.tw-cat { padding: 8px 0; align-self: center; }
.tw-cat img { display: block; width: 80px; height: 124px; object-fit: contain; transform-origin: 50% 95%; animation: tw-cat-talk 1.8s ease-in-out infinite; }
.tw-speech { min-width: 0; }
.tw .tw-speech h2 { font-size: 23px; line-height: 1.25; margin: 0 0 12px; letter-spacing: -.5px; overflow-wrap: anywhere; }
.tw .tw-speech p { font-size: 17px; line-height: 1.65; color: var(--ink); margin: 0; word-break: keep-all; overflow-wrap: anywhere; }
.tw .tw-speech b { color: var(--blue); }
.tw-demo { min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: #fffdf5; border: 1px solid var(--line); border-radius: 16px; padding: 12px; text-align: center; }
.tw-demo-title { font-size: 15px; font-weight: 800; line-height: 1.4; }
.tw-letters, .tw-choices { display: flex; justify-content: center; gap: 10px; }
.tw-letters > span { display: grid; place-items: center; width: 48px; height: 52px; background: white; border: 2px solid var(--blue); border-radius: 10px; color: var(--blue); font-size: 30px; font-weight: 900; }
.tw-letters > .tw-missing { background: #edf3ff; border-style: dashed; }
.tw-choices button { width: 60px; height: 52px; font-size: 30px; font-weight: 900; color: var(--red); background: var(--paper); border: 2px solid var(--red); border-radius: 10px; box-shadow: 0 3px 0 #20324718; }
.tw-choices button:active { transform: translateY(2px); box-shadow: none; }
.tw-owned > span { background: var(--red); border-color: var(--red); color: white; }
.tw-owned > span:last-child { background: var(--blue); border-color: var(--blue); }
.tw p.tw-example-note { font-size: 14px; line-height: 1.5; color: var(--ink); margin: 0; overflow-wrap: anywhere; }
.tw p.tw-success { font-size: 17px; line-height: 1.4; color: var(--green); font-weight: 800; margin: 0; }
.tw-hand { display: flex; gap: 5px; width: 100%; }
.tw-hand span { flex: 1; min-width: 0; height: 54px; display: grid; place-items: center; border: 2px solid var(--blue); border-radius: 7px; color: var(--blue); font-size: 22px; font-weight: 800; }
.tw-attempts { display: flex; gap: 12px; }
.tw-attempts i { width: 22px; height: 22px; background: var(--red); border-radius: 50%; }
.tw-hint { font-size: 17px; font-weight: 800; color: var(--blue); background: #edf3ff; padding: 12px 18px; border-radius: 12px; }
.tw-specials { display: flex; justify-content: center; gap: 16px; }
.tw-specials figure { margin: 0; }
.tw-specials img { display: block; width: 58px; height: 80px; object-fit: contain; margin: auto; }
.tw-specials figcaption { font-size: 13px; font-weight: 800; margin-top: 4px; }
.tw-footer { border-top: 1px solid var(--line); padding-top: 8px; }
.tw-nav { display: flex; gap: 10px; min-width: 0; }
.tw .tw-nav button { width: auto; min-width: 82px; min-height: 44px; margin: 0; padding: 9px 18px; font-size: 16px; border-radius: 12px; }
.tw .tw-nav .primary { min-width: 132px; box-shadow: 0 3px 0 var(--ink); }
@keyframes tw-cat-talk { 0%, 100% { transform: rotate(-2deg); } 50% { transform: translateY(-4px) rotate(2deg); } }
@media (max-width: 700px) {
  .tw-coach { grid-template-columns: 52px minmax(0, 1fr); gap: 8px; align-content: center; }
  .tw-cat img { width: 52px; height: 82px; }
  .tw .tw-speech h2 { font-size: 20px; margin-bottom: 8px; }
  .tw .tw-speech p { font-size: 16px; line-height: 1.5; }
  .tw-body { gap: 12px; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
}
@media (max-width: 480px) and (orientation: portrait) {
  .tw-body { grid-template-columns: minmax(0, 1fr); align-content: start; }
  .tw-coach { grid-template-columns: 60px minmax(0, 1fr); }
  .tw-cat { display: block; }
  .tw-cat img { width: 60px; height: 90px; }
  .tw-demo { padding: 16px; }
  .tw-progress-track { display: none; }
  .tw .tw-nav button { min-width: 60px; padding: 8px; font-size: 14px; }
  .tw .tw-nav .primary { min-width: 88px; }
  .tw-voice { font-size: 12px; padding: 6px; }
}
@media (prefers-reduced-motion: reduce) { .tw-cat img { animation: none; } }

@media (orientation:portrait) and (max-width:900px){
 html .modal:has(.tw){width:min(600px,100%);height:min(1000px,100%);padding:clamp(14px,3vw,24px);border-radius:24px}
 html .tutorial.tw{grid-template-rows:48px minmax(0,1fr) 60px;gap:12px}
 .tw-header{gap:8px}
 .tw-progress{gap:4px;font-size:12px}
 .tw-progress>strong{flex-basis:100%;font-size:14px}
 .tw-progress-track{display:flex;width:72px}
 .tw-body{grid-template-columns:minmax(0,1fr);grid-template-rows:auto minmax(0,1fr);gap:16px;align-content:stretch}
 .tw-coach{grid-template-columns:60px minmax(0,1fr);gap:12px;align-items:center;padding:8px 0}
 .tw-cat img{width:60px;height:90px}
 .tw .tw-speech h2{font-size:clamp(21px,5.5vw,29px);line-height:1.25;margin-bottom:8px}
 .tw .tw-speech p{font-size:clamp(15px,3.8vw,19px);line-height:1.5}
 .tw-demo{min-height:0;padding:clamp(12px,3vw,22px);gap:clamp(10px,2dvh,20px);border:2px solid var(--ink);outline:1px solid var(--line);outline-offset:-6px;border-radius:20px;box-shadow:0 4px 0 #20324712}
 .tw-demo-title{font-size:16px}
 .tw-letters,.tw-choices{gap:8px;max-width:100%}
 .tw-letters>span{width:clamp(42px,12vw,68px);height:clamp(46px,7dvh,72px);font-size:clamp(26px,6vw,38px)}
 .tw-choices button{width:54px;height:60px;outline:1px solid var(--red);outline-offset:-5px}
 .tw-hand span{height:clamp(48px,7dvh,72px)}
 .tw-specials{gap:12px;max-width:100%}
 .tw-specials img{width:clamp(48px,13vw,80px);height:clamp(65px,18vw,110px)}
 .tw p.tw-example-note{font-size:14px;line-height:1.45}
 .tw-footer{display:grid;grid-template-columns:44px minmax(0,1fr);gap:10px}
 .tw-voice{width:44px;height:48px;padding:0;font-size:0}
 .tw-voice::before{content:'♫';font-size:23px}
 .tw-nav{width:100%;gap:8px}
 .tw .tw-nav button,.tw .tw-nav .primary{flex:1;min-width:0;min-height:48px;font-size:15px;padding:9px 10px}
 @media(max-height:700px){
  html .tutorial.tw{gap:8px;grid-template-rows:46px minmax(0,1fr) 58px}
  .tw-body{gap:10px}
  .tw-coach{grid-template-columns:44px minmax(0,1fr);gap:8px;padding:4px 0}
  .tw-cat img{width:44px;height:66px}
  .tw .tw-speech h2{font-size:20px}
  .tw .tw-speech p{font-size:15px}
  .tw-demo{gap:10px;padding:12px}
 }
}
